> Source: https://wexa.ai/docs/tools/run-agent

# run-agent

Resume an agent that ALREADY EXISTS in this project, with a natural-language goal, and return its execution_id. This does NOT run a one-off prompt: 'agentflow_id' is required and there is no project default. If you have no flow yet, provision one first with create-process-flow (POST /v1/docs \{"topic":"orchestrate"\} has a manifest example that is accepted as written), then pass the id it returns here. Provide 'agentflow_id' (the agent to run — its `agentflowId`) and 'goal' (what you want it to do). The run is asynchronous: poll the execution by its execution_id for status and the conclusion. For a MULTI-TURN conversation, pass a stable 'session_id' across calls — the agent then recalls prior turns and the runs are grouped as one conversation.

## What it is called on each surface

The wire name is `run-agent` everywhere: it is what the Wexa MCP server advertises, the REST path is
`POST /v1/run-agent`, and each SDK exposes it under its own language's naming convention.

| Surface | Name |
| --- | --- |
| Wexa MCP server | `run-agent` |
| REST API | `POST /v1/run-agent` |
| TypeScript SDK | `fabric.runAgent()` |
| Python SDK | `fabric.run_agent()` |

## Arguments

2 of the 6 arguments are required. Omitting a required one is refused before the tool runs, at the validation stage, so it costs nothing and changes nothing.

| Argument | Type | Required | Notes |
| --- | --- | --- | --- |
| `agentflow_id` | string | Required | Id of the agent to run. |
| `files` | array | Optional | Optional file ids to add to the execution context. |
| `goal` | string | Required | Natural-language goal / message for this run (this turn). |
| `input_variables` | object | Optional | Optional input variables consumed by the agent. |
| `session_id` | string | Optional | Optional conversation id. Reuse the same value across turns for multi-turn memory + grouping. Omit for a one-shot run. |
| `start_from_agent_id` | string | Optional | Optional agent id to start the flow from. |

`project_id`, `projectID`, `organization_id` and `executed_by` are not arguments you pass: the
platform binds all four from the credential you authenticated with, and both SDKs refuse them
before the request leaves your process — see
[server-bound arguments](/docs/get-started/scope-and-server-bound-arguments).

## What it returns

The three surfaces wrap this differently, and code written against one will not read another
correctly — see [return shape](/docs/tools/overview#return-shape).

A real response, captured from a live call to `run-agent`:

`agentflow` came back populated and is shown as `…` here, because the real value runs to
thousands of characters. Read it from your own call rather than from this page.

**Result of run-agent**

**REST API**

```json
{
  "lifecycle_id": "qlc_000184",
  "result": {
    "_id": "6ab196817566f41b5c28e31a",
    "agent_type": "Task",
    "agent_version": null,
    "agentflow": "\u2026",
    "agentflow_id": "6ab1945e7566f41b5c28e303",
    "agentflow_name": "docs-fixture-agent",
    "agents_output": [],
    "anomaly_detected": null,
    "application_user_id": "6a79a770b6c128ccc24bfca7",
    "conclusion": null,
    "created_at": 1790023297.263668,
    "duration_ms": null,
    "end_time": null,
    "executed_by": {
      "_id": "6a79a770b6c128ccc24bfca7",
      "application_user_id": "6a79a770b6c128ccc24bfca7",
      "is_external_application": true,
      "metadata": null,
      "name": "6a79a770b6c128ccc24bfca7",
      "type": "api"
    },
    "execution_context": {},
    "execution_id": "8ba80297-9dfe-4ff6-9134-a1d9803355dd",
    "files": [],
    "goal": "Reply with READY.",
    "goal_template": null,
    "input_variables": {},
    "interop_ask": null,
    "interop_resume": null,
    "is_external_application": true,
    "kb_tags": [],
    "parent_execution_id": null,
    "previews": {},
    "projectID": "6aa9beb7ec8121a43b6c791b",
    "runtime_inputs": {},
    "schedule": null,
    "session_id": null,
    "simulation": false,
    "start_from_agent_id": null,
    "status": "running",
    "task_id": "6ab196817566f41b5c28e31b",
    "total_price": null,
    "total_tokens": null,
    "trigger_source": "api"
  }
}
```

**Wexa MCP server**

```json
{
  "content": [
    {
      "type": "text",
      "text": "{\"lifecycle_id\":\"qlc_000184\",\"result\":{\"_id\":\"6ab196817566f41b5c28e31a\",\"agent_type\":\"Task\",\"agent_version\":null,\"agentflow\":\"\\u2026\",\"agentflow_id\":\"6ab1945e7566f41b5c28e303\",\"agentflow_name\":\"docs-fixture-agent\",\"agents_output\":[],\"anomaly_detected\":null,\"application_user_id\":\"6a79a770b6c128ccc24bfca7\",\"conclusion\":null,\"created_at\":1790023297.263668,\"duration_ms\":null,\"end_time\":null,\"executed_by\":{\"_id\":\"6a79a770b6c128ccc24bfca7\",\"application_user_id\":\"6a79a770b6c128ccc24bfca7\",\"is_external_application\":true,\"metadata\":null,\"name\":\"6a79a770b6c128ccc24bfca7\",\"type\":\"api\"},\"execution_context\":{},\"execution_id\":\"8ba80297-9dfe-4ff6-9134-a1d9803355dd\",\"files\":[],\"goal\":\"Reply with READY.\",\"goal_template\":null,\"input_variables\":{},\"interop_ask\":null,\"interop_resume\":null,\"is_external_application\":true,\"kb_tags\":[],\"parent_execution_id\":null,\"previews\":{},\"projectID\":\"6aa9beb7ec8121a43b6c791b\",\"runtime_inputs\":{},\"schedule\":null,\"session_id\":null,\"simulation\":false,\"start_from_agent_id\":null,\"status\":\"running\",\"task_id\":\"6ab196817566f41b5c28e31b\",\"total_price\":null,\"total_tokens\":null,\"trigger_source\":\"api\"}}"
    }
  ],
  "isError": false
}
```

**TypeScript SDK**

```ts
// the object you get back IS the result — there is no `.result` to read
{
  _id: '6ab196817566f41b5c28e31a',
  agent_type: 'Task',
  agent_version: null,
  agentflow: '…',
  agentflow_id: '6ab1945e7566f41b5c28e303',
  agentflow_name: 'docs-fixture-agent',
  agents_output: [],
  anomaly_detected: null,
  application_user_id: '6a79a770b6c128ccc24bfca7',
  conclusion: null,
  created_at: 1790023297.263668,
  duration_ms: null,
  end_time: null,
  executed_by: {
    _id: '6a79a770b6c128ccc24bfca7',
    application_user_id: '6a79a770b6c128ccc24bfca7',
    is_external_application: true,
    metadata: null,
    name: '6a79a770b6c128ccc24bfca7',
    type: 'api'
  },
  execution_context: {},
  execution_id: '8ba80297-9dfe-4ff6-9134-a1d9803355dd',
  files: [],
  goal: 'Reply with READY.',
  goal_template: null,
  input_variables: {},
  interop_ask: null,
  interop_resume: null,
  is_external_application: true,
  kb_tags: [],
  parent_execution_id: null,
  previews: {},
  projectID: '6aa9beb7ec8121a43b6c791b',
  runtime_inputs: {},
  schedule: null,
  session_id: null,
  simulation: false,
  start_from_agent_id: null,
  status: 'running',
  task_id: '6ab196817566f41b5c28e31b',
  total_price: null,
  total_tokens: null,
  trigger_source: 'api'
}

// The TS SDK names these camelCase — lifecycleId, traceId — where Python uses
// lifecycle_id and trace_id. Both are non-enumerable: readable, but omitted by
// Object.keys() and JSON.stringify(). `result.lifecycleId` here is undefined.
result.lifecycleId // 'qlc_000184'
```

**Python SDK**

```python
# a dict subclass; `result` is already unwrapped
{
 "_id": "6ab196817566f41b5c28e31a",
 "agent_type": "Task",
 "agent_version": None,
 "agentflow": "\u2026",
 "agentflow_id": "6ab1945e7566f41b5c28e303",
 "agentflow_name": "docs-fixture-agent",
 "agents_output": [],
 "anomaly_detected": None,
 "application_user_id": "6a79a770b6c128ccc24bfca7",
 "conclusion": None,
 "created_at": 1790023297.263668,
 "duration_ms": None,
 "end_time": None,
 "executed_by": {
  "_id": "6a79a770b6c128ccc24bfca7",
  "application_user_id": "6a79a770b6c128ccc24bfca7",
  "is_external_application": True,
  "metadata": None,
  "name": "6a79a770b6c128ccc24bfca7",
  "type": "api"
 },
 "execution_context": {},
 "execution_id": "8ba80297-9dfe-4ff6-9134-a1d9803355dd",
 "files": [],
 "goal": "Reply with READY.",
 "goal_template": None,
 "input_variables": {},
 "interop_ask": None,
 "interop_resume": None,
 "is_external_application": True,
 "kb_tags": [],
 "parent_execution_id": None,
 "previews": {},
 "projectID": "6aa9beb7ec8121a43b6c791b",
 "runtime_inputs": {},
 "schedule": None,
 "session_id": None,
 "simulation": False,
 "start_from_agent_id": None,
 "status": "running",
 "task_id": "6ab196817566f41b5c28e31b",
 "total_price": None,
 "total_tokens": None,
 "trigger_source": "api"
}

out.lifecycle_id  # 'qlc_000184' — an attribute, not a key
```

Keeping the `lifecycle_id` is what lets you ask later why a call was allowed, refused or held.

## Calling it

The same call on all four surfaces. Pick a tab once and every code block in the documentation follows it.

The ids in this example are real, and resolve against the project the documentation is written
against. Swap them for your own. A value in angle brackets is one only you can supply, and the
platform refuses a literal `<...>`.

**Call run-agent**

**Wexa MCP server**

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "run-agent",
    "arguments": {
      "agentflow_id": "6ab1945e7566f41b5c28e303",
      "goal": "<goal>"
    }
  }
}
```

**REST API**

```bash
curl -sS https://fabric.wexa.ai/v1/run-agent \
  -H "authorization: Bearer $FABRIC_API_KEY" \
  -H "content-type: application/json" \
  -d '{"agentflow_id":"6ab1945e7566f41b5c28e303","goal":"<goal>"}'
```

**TypeScript SDK**

```ts
import { Fabric } from '@wexa-fabric/sdk'

const fabric = new Fabric()
const { result } = await fabric.runAgent({
  agentflow_id: "6ab1945e7566f41b5c28e303",
  goal: "<goal>"
})
```

**Python SDK**

```python
from wexa import Fabric

fabric = Fabric()
out = fabric.run_agent(agentflow_id="6ab1945e7566f41b5c28e303", goal="<goal>")
```

## Errors

Both SDKs raise the same typed errors, chosen from the gateway's own error string first and its
HTTP status second. `run-agent` checks the `fabric:agent.run` grant, and reaches the seven classes every
tool reaches — listed under [the common set](/docs/tools/errors#the-common-set). These are the ones specific to it:

| Error | Status | Raised when |
| --- | --- | --- |
| `NotFound` | 404 | `agentflow_id` matches no agent or process flow in this project. |
| `ApprovalRequired` | 202 | A policy held this call for a person to approve. The error carries the approval id; see below. |
| `ConfigurationError` | 5xx | `run-agent` is not available to you. Retrying will not help. |

## Governance

Every call to `run-agent` runs through the same ten-stage lifecycle as every other Wexa tool: the
credential is resolved to a scope, the `fabric:agent.run` grant is checked, quota is drawn down, the arguments are
validated, policy rules are evaluated, the call is executed, the result is shaped and redacted, and an audit
record is written. The `lifecycle_id` in the response is the handle to that record.

`run-agent` is marked consequential, which means it changes something rather than only reading. Two things
follow. It is audited in full rather than lightly, and a policy rule may hold it for human approval — in which
case the call returns `202` and an `ApprovalRequired` error carrying the approval id, and the SDKs can wait for
the decision and resume rather than making you call again.

## See also

[The tool index](/docs/tools/overview), [errors](/docs/tools/errors),
and [which identifier goes where](/docs/tools/identifiers).
