Skip to main content

Update Session

Modify a session's title, metadata, environment_variables, vault_ids, session-level agent configuration, and session-level MCP request headers. Updating a session is the only operation that triggers a session.updated event.

Prerequisites

Endpoint and authentication configuration must be completed. For details, see Overview and authentication.

Endpoint

POST /sessions/{session_id} You can modify title, metadata, environment_variables, vault_ids, session-level agent configuration (agent), and session-level MCP request headers (mcp_configs). Array and object fields are replaced as a whole; empty values clear them. Updating a session is the only operation that triggers a session.updated event.

Request body

FieldRequiredTypeDescription
titleNostringSession title. Omitted keeps the current value; null performs no update
metadataNoobjectCustom key-value pairs for business use. Replaced as a whole; omitted keeps the current value, null performs no update
environment_variablesNoobjectEnvironment variables injected into the session runtime as string key-value pairs; sandbox code can read them directly by name. Replaced as a whole; an empty object clears them, omitted keeps the current value
vault_idsNoarray of stringReplaces vault bindings as a whole; an empty array clears them, omitted keeps the current value
agentNoobjectSession-level agent configuration patch. Can only carry the system / tools / mcp_servers / skills override fields; carrying other fields (such as type / id / version / model) returns invalid_parameter. See Session-level configuration patch
mcp_configsNoarrayReplaces session-level MCP request headers as a whole; same structure as in Create Session. An empty array clears them, omitted keeps the current value, null is invalid

Session-level configuration patch

The agent patch only modifies the configuration snapshot of the current session and never creates a new agent version. Sub-field semantics (consistent with the override semantics in Create Session):
ValueEffect
OmittedKeep the existing override
nullDelete the override for that field and re-inherit the agent's source configuration
[] (array fields)Explicitly override to empty
"" (only for system)Explicitly use an empty prompt

Request example

curl -X POST "$AGENTSTUDIO_URL/sessions/sesn_xxx" \
  -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "title": "Q3 销售复盘",
    "metadata": {"biz_ticket_id": "1234", "status": "done"},
    "environment_variables": {"API_BASE_URL": "https://api.example.com", "LOG_LEVEL": "info"},
    "agent": {
      "system": "你是本会话专用的项目分析助手。",
      "skills": []
    },
    "mcp_configs": [
      {"mcp_server_name": "crm", "headers": {"X-Tenant-Id": "tenant-demo"}}
    ]
  }'

Response example

Returns the updated session details: new values of title / metadata / etc. after overwrite, agent (full snapshot with overrides merged), mcp_configs, vault_ids, updated_at, and request_id.
{
  "id": "sesn_xxx",
  "type": "session",
  "status": "idle",
  "title": "Q3 销售复盘",
  "metadata": {"biz_ticket_id": "1234", "status": "done"},
  "updated_at": "2026-05-28T09:30:00Z",
  "request_id": "xxx",
  "environment_variables": {"API_BASE_URL": "https://api.example.com", "LOG_LEVEL": "info"},
  "agent": {
    "id": "agent_xxx",
    "type": "agent",
    "version": 1,
    "name": "data-analyst",
    "system": "你是本会话专用的项目分析助手。",
    "tools": [],
    "mcp_servers": [],
    "skills": []
  },
  "vault_ids": ["vlt_xxx"],
  "mcp_configs": [{"mcp_server_name": "crm", "headers": {"X-Tenant-Id": "tenant-demo"}}]
}

Response fields

FieldTypeDescription
idstringSession ID
typestringFixed as session
statusstringCurrent session status (update does not change the status)
title / metadatastring / objectNew values after overwrite from the request body
updated_atstringLast update time, ISO 8601
request_idstringUnique identifier for this request
environment_variablesobjectEnvironment variables injected into the session runtime as string key-value pairs; sandbox code can read them directly by name
agentobjectUpdated agent configuration snapshot with session-level overrides merged. Fields are the same as in Get Session
vault_idsarray of stringUpdated vault bindings
mcp_configsarray of objectUpdated session-level MCP request headers; each item contains mcp_server_name and headers
Flow Agent API
Sandbox API
RAG API
Long-term Memory
ParseX API
Security API
Framework Integration