> ## Documentation Index
> Fetch the complete documentation index at: https://docs.agents.labs.bandwidth.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Create an agent from authoring code

> MCP reference for create_workflow.

Tool: `create_workflow`. Requires **Editor, Admin, or Owner** in the applicable workspace and a connected [OAuth session](https://docs.agents.labs.bandwidth.com/mcp/authentication.md).

Accepts the complete supported TypeScript authoring source in `code`. Start from code returned by [`get_workflow`](https://docs.agents.labs.bandwidth.com/mcp/tools/get-workflow), change its workflow name and desired behavior, and submit the full source. The name in that source is required. This tool parses the source; it is not a general TypeScript execution service. For a fresh agent without code, use [`create_workflow_from_template`](https://docs.agents.labs.bandwidth.com/mcp/tools/create-workflow-from-template) or [`create_single_prompt_agent`](https://docs.agents.labs.bandwidth.com/mcp/tools/create-single-prompt-agent).

Success has `created: true`, lifecycle `draft`, and version 1 `published` for the stored snapshot. Failures include `parse_error`, `validation_error`, `graph_validation`, `missing_name`, and `trigger_path_conflict`. Correct the full source before retrying. The tool does not call a model/provider or publish the agent; URL checks may resolve hostnames.

The example below is complete authoring text for a two-node agent. Send it as the `code` string; Agent Builder parses `Workflow`, `startCall`, and `endCall` directly. You do not need to install an SDK or execute this text locally.

## Arguments

| Name | Type | Required | Defaults and limits |
| - | - | - | - |
| `code` | string | Yes | See full schema |

## Example arguments

Replace sample resource IDs with IDs returned in your selected workspace.

```json theme={null}
{
  "code": "const wf = new Workflow({ name: \"MCP workflow assistant\" });\nconst welcome = wf.addTyped(startCall({ name: \"Welcome\", prompt: \"Ask how you can help.\" }));\nconst done = wf.addTyped(endCall({ name: \"Done\", prompt: \"Thank the caller.\" }));\nwf.edge(welcome, done, { label: \"done\", condition: \"The caller is finished.\" });"
}
```

## Result and errors

The schema below describes MCP `structuredContent`, including the `result` wrapper where present. Your client may also display a text representation. Read success flags and structured errors before continuing; transport success alone does not prove the operation succeeded. Authentication, missing membership, and insufficient role can fail before a tool result is produced. See [troubleshooting](https://docs.agents.labs.bandwidth.com/mcp/troubleshooting.md).

**Effect:** Changes state. **Retry:** Do not blindly repeat successful calls. Discovery annotations describe behavior; they do not grant permission or replace confirmation for consequential actions.

> [accordion] Input schema
>
> ```json theme={null}
> {
>   "additionalProperties": false,
>   "properties": {
>     "code": {
>       "type": "string"
>     }
>   },
>   "required": [
>     "code"
>   ],
>   "type": "object"
> }
> ```

> [accordion] Result schema
>
> ```json theme={null}
> {
>   "properties": {
>     "result": {
>       "anyOf": [
>         {
>           "properties": {
>             "assistant_mode": {
>               "enum": [
>                 "single_prompt",
>                 "workflow"
>               ],
>               "type": "string"
>             },
>             "created": {
>               "const": true,
>               "type": "boolean"
>             },
>             "edge_count": {
>               "type": "integer"
>             },
>             "lifecycle_status": {
>               "enum": [
>                 "draft",
>                 "active",
>                 "paused",
>                 "archived"
>               ],
>               "type": "string"
>             },
>             "name": {
>               "type": "string"
>             },
>             "node_count": {
>               "type": "integer"
>             },
>             "version_number": {
>               "type": "integer"
>             },
>             "version_status": {
>               "enum": [
>                 "draft",
>                 "published"
>               ],
>               "type": "string"
>             },
>             "workflow_id": {
>               "type": "integer"
>             }
>           },
>           "required": [
>             "created",
>             "workflow_id",
>             "name",
>             "lifecycle_status",
>             "version_status",
>             "version_number",
>             "assistant_mode"
>           ],
>           "type": "object"
>         },
>         {
>           "properties": {
>             "created": {
>               "const": false,
>               "type": "boolean"
>             },
>             "error": {
>               "type": "string"
>             },
>             "error_code": {
>               "type": "string"
>             },
>             "errors": {
>               "items": {
>                 "additionalProperties": true,
>                 "type": "object"
>               },
>               "type": "array"
>             },
>             "trigger_paths": {
>               "items": {
>                 "type": "string"
>               },
>               "type": "array"
>             }
>           },
>           "required": [
>             "created",
>             "error_code",
>             "error"
>           ],
>           "type": "object"
>         }
>       ]
>     }
>   },
>   "required": [
>     "result"
>   ],
>   "type": "object"
> }
> ```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.