Skip to main content

获取 Session

返回会话元数据、嵌入的智能体快照与资源列表。事件历史与消息内容通过事件 API 获取。

前提

已完成 Endpoint 与鉴权配置,详见API 总览与认证。

接口

GET /sessions/{session_id}

请求示例

curl "$AGENTSTUDIO_URL/sessions/sesn_xxx" \
  -H "Authorization: Bearer $DASHSCOPE_API_KEY"

响应字段

响应为 Session 对象。字段如下:id string会话 ID,格式 sesn_<ULID>type string固定为 sessionstatus string会话状态:idle / running / terminatedstop_reason object / null会话回到 idle 的原因,判别联合。null(running,或 idle 刚创建尚未产生结束原因)/ {"type":"end_turn"}(模型主动结束)/ {"type":"retries_exhausted"}(重试耗尽)/ {"type":"requires_action","pending_batch_id":"...","pending_call_ids":[...]}(等待工具审批,pending_call_ids 为待裁决调用列表)。仅在 status=idle 时用于判断交互状态;running 时为 null;terminated 是终态,客户端不应依赖其 stop_reasonagent object智能体配置完整快照,含 id / version / name / model / system / tools 等;会话级覆盖(若已设置)已并入快照environment_id string绑定的运行环境 IDsandbox object沙箱快照持久化配置与当前快照状态;未配置时省略
enable_snapshot boolean当前 Session 是否开启快照持久化snapshot_persistent_seconds integer单份快照配置的保留时间,单位秒;未配置时不返回is_persisting boolean当前 Session 是否正在保留可用快照;尚未取得统计时可能不返回predict_release_time string / null当前快照预计释放时间,ISO 8601 UTC;没有当前快照时为 null
usage.sandbox object沙箱快照时长统计。创建响应中可能省略;已开启快照但尚未生成快照时,内部时长字段为 null。
session_total_persisted_hours integer / null历史快照累计保留小时数;尚无统计时为 nulllatest_snapshot_persisted_hours integer / null当前最新快照已保留小时数;没有当前快照时为 null
title / metadata string / object会话标题与业务自定义元数据archived_at string / null归档时间,未归档时为 nullcreated_at / updated_at string创建 / 最近更新时间,ISO 8601request_id string本次请求的唯一标识environment_variables object会话运行时注入的环境变量,字符串键值对,沙箱代码中可直接按名读取vault_ids array of string绑定的 Vault ID 列表mcp_configs array of object会话级 MCP 请求头,每项含 mcp_server_name 与 headers;未配置时为空数组

响应示例

{
  "id": "sesn_xxx",
  "type": "session",
  "status": "idle",
  "stop_reason": {
    "type": "requires_action",
    "pending_batch_id": "response_xxx:9f2c...",
    "pending_call_ids": [
      "call_xxx"
    ]
  },
  "agent": {
    "id": "agent_xxx",
    "type": "agent",
    "version": 1,
    "name": "data-analyst",
    "description": null,
    "model": {"id": "qwen3.7-max"},
    "system": "你是数据分析专家,使用 pandas 处理 CSV 文件。",
    "tools": []
  },
  "environment_id": "env_xxx",
  "title": "Q3 销售数据分析",
  "metadata": {"biz_ticket_id": "1234"},
  "archived_at": null,
  "created_at": "2026-05-28T08:23:11Z",
  "updated_at": "2026-05-28T08:23:25Z",
  "request_id": "xxx",
  "environment_variables": {"API_BASE_URL": "https://api.example.com", "LOG_LEVEL": "info"},
  "vault_ids": ["vlt_xxx"],
  "mcp_configs": [{"mcp_server_name": "crm", "headers": {"X-Tenant-Id": "tenant-demo"}}]
}

沙箱快照响应示例

当前存在可用快照时:
{
  "sandbox": {
    "enable_snapshot": true,
    "snapshot_persistent_seconds": 172800,
    "is_persisting": true,
    "predict_release_time": "2026-11-17T06:09:50Z"
  },
  "usage": {
    "sandbox": {
      "session_total_persisted_hours": 3,
      "latest_snapshot_persisted_hours": 1
    }
  }
}
已开启快照但尚未生成快照时:
{
  "sandbox": {
    "enable_snapshot": true,
    "snapshot_persistent_seconds": 172800,
    "is_persisting": false,
    "predict_release_time": null
  },
  "usage": {
    "sandbox": {
      "session_total_persisted_hours": null,
      "latest_snapshot_persisted_hours": null
    }
  }
}