列出 Session

更新时间:
复制 MD 格式

分页列出会话,按 created_at 倒序返回。支持按智能体、状态、创建时间范围过滤。

前提

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

接口

GET/sessions

查询参数

agent_idstring默认 —

按智能体过滤

statuses[]string默认 —

多状态过滤,可重复传入。如 ?statuses[]=idle&statuses[]=running

created_at[gte] / created_at[lte]string默认 —

创建时间范围,ISO 8601

limitint默认 20

每页数量,最大 100

pagestring默认 —

首次不传,后续传上一次响应的 next_page

请求示例

curl "$AGENTSTUDIO_URL/sessions?agent_id=agent_xxx&statuses[]=idle&limit=20" \
  -H "Authorization: Bearer $DASHSCOPE_API_KEY"
for session in client.sessions.list(
    limit=20,
    agent_id="agent_xxx",
    statuses=["idle"],
):
    print(session.id, session.status, session.title)
CursorPage<Session> page = client.sessions().list(SessionListParam.builder()
    .limit(20)
    .agentId("agent_xxx")
    .statuses(Arrays.asList("idle"))
    .build());
for (Session s : page.getData()) {
    System.out.println(s.getId() + " " + s.getStatus() + " " + s.getTitle());
}

响应字段

dataarray<Session>

Session 对象数组

data[] Session 对象字段

idstring

会话 ID,格式 sesn_<ULID>

typestring

固定为 session

statusstring

会话状态:idle / running / terminated

stop_reasonobject / null

会话回到 idle 的原因,判别联合。null / {"type":"end_turn"} / {"type":"retries_exhausted"} / {"type":"requires_action","pending_batch_id":"...","pending_call_ids":[...]}。仅在 status=idle 时用于判断交互状态

typestring

end_turn / requires_action / retries_exhausted

pending_batch_idstring

待处理的工具审批批次 ID

pending_call_idsarray<string>

待裁决的工具调用 ID 列表

agentobject

智能体配置快照,含 id / version / name / model / system / tools 等

idstring

Agent ID,格式 agent_xxx

versioninteger

要锁定的版本号;不传使用最新版本

environment_idstring

绑定的运行环境 ID

titlestring

会话标题

metadataobject

业务自定义键值

resourcesarray of object

挂载的资源列表。按 type 区分文件、记忆库和 Git 仓库;Git 仓库不返回 authorization_token。字段与获取 Session的 resources 一致,包括 id、type、url、mount_path、checkout、created_at、updated_at。

archived_atstring / null

归档时间,未归档时为 null

created_atstring

创建时间,ISO 8601

updated_atstring

最近更新时间,ISO 8601

environment_variablesobject

会话运行时注入的环境变量,字符串键值对,沙箱代码中可直接按名读取

next_pagestring / null

下一页游标;无更多数据时不返回或为 null

request_idstring

本次请求的唯一标识

响应示例

{
  "data": [
    {
      "id": "sesn_xxx",
      "type": "session",
      "status": "idle",
      "stop_reason": null,
      "agent": {
        "id": "agent_xxx",
        "type": "agent",
        "version": 1,
        "name": "data-analyst",
        "model": {"id": "qwen3.7-max"},
        "system": "你是数据分析专家,使用 pandas 处理 CSV 文件。",
        "tools": []
      },
      "environment_id": "env_xxx",
      "title": "Q3 销售数据分析",
      "resources": [
        {
          "id": "sesrsc_zzz",
          "type": "git_repository",
          "url": "https://gitlab.com/group/project",
          "mount_path": "/workspace/project",
          "checkout": {"type": "branch", "name": "main"},
          "created_at": "2026-11-28T02:00:55Z",
          "updated_at": "2026-11-28T02:00:55Z"
        }
      ],
      "metadata": {"biz_ticket_id": "1234"},
      "archived_at": null,
      "created_at": "2026-05-28T08:23:11.456000Z",
      "updated_at": "2026-05-28T08:23:25.789000Z",
      "environment_variables": {"API_BASE_URL": "https://api.example.com", "LOG_LEVEL": "info"}
    }
  ],
  "next_page": "xxx",
  "request_id": "xxx"
}