跳转到内容
EN

压缩会话(扩展)

先调用「创建会话」,用返回的会话 ID 替换示例 ID。

POST/agent/v1/sessions/{session_id}/compact● 支持

请求参数

  • session_idstring必填

    path: 会话 ID(sesn_...),由 sessions.create 或 sessions.list 返回。资源和线程调用的 session_id 查询参数也接受同一 ID,且必须与路径值一致。

  • instructionsstring可选

    Optional focus instructions for the summary, passed to the summarizing model unchanged.

返回

200

仅在 /agent/v1 提供。请求体可省略或为 {},可选 instructions 必须为字符串且原样传递。Idempotency-Key 请求头原样传递;缺失时生成 UUID。响应为 { type: session_compaction, id, status, reason? },id 是操作 ID。queued/running 返回 202;skipped/succeeded/failed/cancelled 返回 200。非字符串 instructions 返回 400 invalid_request_error。不存在或不可见的托管会话返回 404 not_found_error。

错误按 Anthropic 错误格式返回(type / message / request_id),参见 错误码

请求示例

curl
# 先调用「创建会话」,用返回的会话 ID 替换示例 ID。
curl https://api.deepraxis.com/agent/v1/sessions/sesn_123/compact \
  -H "Authorization: Bearer $PRAXIS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{}'
Python
# 先调用「创建会话」,用返回的会话 ID 替换示例 ID。
import requests

opts = dict(
    base_url="https://api.deepraxis.com/agent",
    api_key="$PRAXIS_API_KEY",
)

# /agent 是我们自己的 Managed Agents 形状,直接发 HTTP 请求(Bearer 认证)
resp = requests.post(
    f"{opts['base_url']}/v1/sessions/sesn_123/compact",
    headers={"Authorization": f"Bearer {opts['api_key']}"},
    json={},
)
print(resp.status_code, resp.json())
TypeScript
// 先调用「创建会话」,用返回的会话 ID 替换示例 ID。
const opts = {
  baseURL: "https://api.deepraxis.com/agent",
  apiKey: "$PRAXIS_API_KEY",
};

// /agent 是我们自己的 Managed Agents 形状,直接发 HTTP 请求(Bearer 认证)
const resp = await fetch(`${opts.baseURL}/v1/sessions/sesn_123/compact`, {
  method: "POST",
  headers: { Authorization: `Bearer ${opts.apiKey}`, "Content-Type": "application/json" },
  body: JSON.stringify({}),
});
console.log(resp.status, await resp.json());

响应示例 200

{
  "type": "session_compaction",
  "id": "compact_584a8f3a-f204-4997-9261-ac9b725cf141",
  "status": "skipped",
  "reason": "No complete older turn can be compacted safely"
}

响应

HTTP 200

Skipped, succeeded or failed compaction

application/json

名称 类型 说明
type string Always session_compaction. Result of a compaction request.
id string Compaction operation id; pass it as operation_id to sessions.compact.retrieve.
status string State of the compaction operation: queued and running are in progress, skipped means nothing needed compaction, succeeded, failed and cancelled are final.
reason string Why the compaction was skipped, failed or cancelled; absent otherwise.

HTTP 202

Queued or running compaction

application/json

名称 类型 说明
type string Always session_compaction. Result of a compaction request.
id string Compaction operation id; pass it as operation_id to sessions.compact.retrieve.
status string State of the compaction operation: queued and running are in progress, skipped means nothing needed compaction, succeeded, failed and cancelled are final.
reason string Why the compaction was skipped, failed or cancelled; absent otherwise.