> ## 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.

# Save agent authoring code

> MCP reference for save_workflow.

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

Read [`get_workflow`](https://docs.agents.labs.bandwidth.com/mcp/tools/get-workflow) first and edit its returned `code`. Submit the complete updated source with the same numeric `workflow_id`; patches are not accepted. Success has `saved: true` and version status `draft`. The agent lifecycle is separate and may stay active while a draft is edited.

Inspect structured failure fields including `error_code`, `error`, and optional validation details. Parser errors can identify a source location. Preserve fields you did not intend to change. Saving does not publish or execute a call; URL checks can resolve hostnames.

## Example: update one prompt

1. Call `get_workflow` with `{ "workflow_id": 42 }`, using an agent ID from your workspace.
2. Read the returned `code` string. For an agent whose prompt is `Be helpful and concise.`, change only that prompt to `Ask one question.`. Keep every node, edge, identifier, and other setting.
3. Call `save_workflow` with `workflow_id: 42` and `code` set to the **entire edited string**, not just the new prompt.
4. Confirm `saved: true` and `version_status: "draft"` before continuing. Run [Validate an agent](https://docs.agents.labs.bandwidth.com/mcp/tools/validate-workflow.md) to inspect the saved definition.

## Arguments

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

## 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"
>     },
>     "workflow_id": {
>       "type": "integer"
>     }
>   },
>   "required": [
>     "workflow_id",
>     "code"
>   ],
>   "type": "object"
> }
> ```

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


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