Skip to content

Update Agent

POST/v1/agents/{agent_id}

Update an agent. Each successful update that changes at least one field increments the agent's version. Existing sessions keep the version they were created with; new sessions use the latest.

Optimistic locking

You must pass the agent's current version. If it doesn't match the server's current version, the request fails with 409 conflict — re-fetch the agent and retry. This prevents concurrent overwrites.

Path Parameters

ParameterTypeRequiredDescription
agent_idstringThe agent ID (agent_...)

Request Parameters

ParameterTypeRequiredDescription
versionintegerThe agent's current version (optimistic lock).
modelstring | objectModel identifier. Omit to preserve. Cannot be cleared.
namestringName. 1–256 chars. Omit to preserve. Cannot be cleared.
descriptionstring | nullOmit to preserve; send empty string or null to clear.
systemstring | nullSystem prompt. Omit to preserve; send empty string or null to clear.
toolsarray | nullFull replacement. Omit to preserve; send [] or null to clear. Max 128.
mcp_serversarray | nullFull replacement. Omit to preserve; send [] or null to clear. Max 20.
metadataobjectMetadata patch. Set a key to a string to upsert, or null to delete. Omit to preserve.

Field Update Semantics

Field kindSemantics
Scalars (model, name)Replace. Cannot be cleared.
Nullable scalars (description, system)Replace, or clear with "" / null.
Arrays (tools, mcp_servers)Full replacement — the provided array becomes the new value.
metadataPer-key patch — upsert by string value, delete by null.

Full replacement for arrays

To add a tool without losing existing ones, GET the agent, append to the tools array, and POST the complete array back.

Request Examples

python
from anthropic import Anthropic

client = Anthropic(
    api_key="sk-sb-YOUR_KEY",
    base_url="https://api.sandbase.ai"
)

agent = client.beta.agents.update(
    agent_id="agent_01HqR2k7...",
    version=1,
    system="You are a senior research assistant. Always cite sources."
)
print(f"New version: {agent.version}")  # 2
bash
curl -X POST https://api.sandbase.ai/v1/agents/agent_01HqR2k7... \
  -H "Authorization: Bearer sk-sb-YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "version": 1,
    "system": "You are a senior research assistant. Always cite sources."
  }'

Response

Returns the updated Agent object with an incremented version.

json
{
  "id": "agent_01HqR2k7...",
  "type": "agent",
  "version": 2,
  "name": "Research Assistant",
  "description": "A general-purpose research agent.",
  "model": { "id": "claude-sonnet-4", "speed": "standard" },
  "system": "You are a senior research assistant. Always cite sources.",
  "tools": [
    {
      "type": "agent_toolset_20260401",
      "default_config": { "enabled": true, "permission_policy": { "type": "always_ask" } },
      "configs": [{ "name": "bash", "enabled": true, "permission_policy": { "type": "always_allow" } }]
    }
  ],
  "mcp_servers": [],
  "metadata": {},
  "archived_at": null,
  "created_at": "2026-05-29T10:00:00Z",
  "updated_at": "2026-05-29T11:00:00Z"
}

If no field actually changed, the version is not incremented and the existing agent is returned unchanged.

Errors

StatusTypeDescription
400invalid_requestInvalid field values
401authentication_errorInvalid or missing API key
404not_foundAgent not found
409conflictversion does not match the current version. Re-fetch and retry.