发送事件
先调用「创建会话」,用返回的会话 ID 替换示例 ID。
/agent/v1/sessions/{session_id}/events◐ 部分支持请求参数
session_idstring必填path: 会话 ID(sesn_...),由 sessions.create 或 sessions.list 返回。资源和线程调用的 session_id 查询参数也接受同一 ID,且必须与路径值一致。
eventsarray必填要发送给会话的事件列表。
返回
200
将 sesn_123 换成创建会话返回的 id。每条 user.message 只接受一个非空文本块。支持文本 user.message、user.interrupt、工具确认、user.custom_tool_result 和 system.message。system.message 的 content 为非空文本块数组;每个请求最多一条,必须是最后一条且紧跟 user.message、user.tool_result 或 user.custom_tool_result。user.custom_tool_result 的 custom_tool_use_id 来自 agent.custom_tool_use.id 或 requires_action 的 stop_reason.event_ids;content 可省略或为空,仅接受 text 块,其它块返回 400;is_error 可省略或为 null,均视为 false。无需传 session_thread_id,服务按调用 id 路由子会话;传入该字段返回 400。未知调用 id 返回 400;重复结果或调用已不再等待返回 409。/agent/v1 的 end_user 仅可提交自己会话的结果,他人会话返回 404。user.tool_result 仍不支持。initial_events 不接受 system.message;可发送 user.withdraw 并用 event_id 指向仍在排队的消息来撤回它,消息已开始处理时返回 409。运行中需要提前补充要求时,发送 user.steer 事件,并用 event_id 指向仍在排队的消息:当前工具继续执行,消息在下一次模型请求前进入当前回合。返回带 processed_at 的 user.steer 回执,重复标记返回同一回执;已开始或已撤回返回 409,事件不存在返回 404。有待授权时继续等待;若当前回合先结束,消息仍按普通队列处理。默认发送消息仍然排队,/anthropic 不接受 user.steer。其它事件变体尚不支持。返回的是已接纳事件;模型回复从事件历史或订阅读取。会话等待工具授权时发送的 user.message 会排队:返回的事件 processed_at 为 null,授权处理完成后按发送顺序执行。允许工具调用时可在 updated_permissions 中原样提交该调用的 permission_suggestions,让个人智能体的所有会话记住同类操作(destination: agent);服务型智能体只接受 session。guarded 下需逐次确认的危险操作不提供建议。使用网页搜索或读取网页时,/agent/v1 与 /anthropic 的工具结果均为官方 search_result 块;回答文本块的 citations 是 /agent/v1 的扩展字段,/anthropic 将回答引用显示为正文中的 [n]。 仅在 /agent/v1:可选 Idempotency-Key 请求头(1–255 个可见 ASCII 字符)。请求只含一条 user.message 时,同一会话里相同的键只生效一次,重复请求返回首次接受的事件,不会再开始一轮回复;其他事件忽略该请求头。格式不符返回 400 invalid_request_error。
错误按 Anthropic 错误格式返回(type / message / request_id),参见 错误码
请求示例
curl
# 先调用「创建会话」,用返回的会话 ID 替换示例 ID。
curl https://api.deepraxis.com/agent/v1/sessions/sesn_123/events \
-H "Authorization: Bearer $PRAXIS_API_KEY" \
-H "Content-Type: application/json" \
-d '{"events":[{"type":"user.message","content":[{"type":"text","text":"你好"}]}]}'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/events",
headers={"Authorization": f"Bearer {opts['api_key']}"},
json={"events":[{"type":"user.message","content":[{"type":"text","text":"你好"}]}]},
)
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/events`, {
method: "POST",
headers: { Authorization: `Bearer ${opts.apiKey}`, "Content-Type": "application/json" },
body: JSON.stringify({"events":[{"type":"user.message","content":[{"type":"text","text":"你好"}]}]}),
});
console.log(resp.status, await resp.json());响应示例 200
{
"data": [
{
"id": "7498fb36-ffbf-46fd-8303-aafe16ae2f32",
"type": "user.message",
"processed_at": null,
"content": [
{
"type": "text",
"text": "你好"
}
]
}
]
}响应
HTTP 200
Successful response
application/json
| 名称 | 类型 | 说明 |
|---|---|---|
| data | array<object> | Sent events |
| data[].id | string | Unique identifier for this event. / Event id, unique within the session. Use it to refer to this event, for example in user.tool_confirmation or user.steer. |
| data[].content | array<object> | Array of content blocks comprising the user message. / The result content returned by the tool. / The result content returned by the tool. / System content blocks. Text-only. |
| data[].type | string | Always user.message. A message from the user to the agent, with content blocks. / Always user.interrupt. The user interrupted the running turn. / Always user.tool_confirmation. The user's decision to allow or deny a tool call that waits for approval. / Always user.custom_tool_result. The user's result for a custom tool call. / Always user.define_outcome. The user defined the outcome the agent should reach. / Always user.tool_result. The user's result for a client-side tool call. / Always system.message. A message produced by the platform rather than the user or the agent. / Always user.steer. Receipt that a queued user.message was injected into the running turn. |
| data[].processed_at | null | string | string | null | string | null | string | string | A timestamp in RFC 3339 format / RFC 3339 time at which the server processed the event; null while a queued input has not started running. |
| data[].praxis_context | object | Untrusted page context for this user message only. Resend on each turn when needed; never added to system instructions. The complete JSON value must be at most 4096 UTF-8 bytes; invalid values return 400 INVALID_PARAMS. Empty items are treated as absent. Available only on /agent/v1. |
| data[].session_thread_id | null | string | string | null | If absent, interrupts every non-archived thread in a multiagent session (or the primary alone in a single-agent session). If present, interrupts only the named thread. / Set by the server to the subagent thread this confirmation was routed to. Omitted when it was routed to the primary thread. / Set by the server to the subagent thread this result was routed to. Omitted when it was routed to the primary thread. / Set by the server to the subagent thread this result was routed to. Omitted when it was routed to the primary thread. / Envelope field, not part of this event's own payload: the public sthr_ thread id of the row (null when the row has none), added by the shared projection in apps/api/src/routes/managed-session-events.ts whenever the row carries one (#4480). No writer of this event runs under a thread today, so it is declared for the frame shape rather than produced here. |
| data[].result | string | UserToolConfirmationResult enum |
| data[].tool_use_id | string | The id of the agent.tool_use or agent.mcp_tool_use event this result corresponds to, which can be found in the last session.status_idle event's stop_reason.event_ids field. / The id of the agent.tool_use event this result corresponds to, which can be found in the last session.status_idle event's stop_reason.event_ids field. |
| data[].deny_message | string | Feedback for a deny result, at most 4000 characters. Appended to the model-visible refusal and persisted on the confirmation. Omit when no feedback is needed. |
| data[].permission_mode | string | With result=allow and full_access_available=true, switch this session to full access before allowing this call. Other values or ineligible active requests return 400. Repeated or late replies are successful no-ops. |
| data[].custom_tool_use_id | string | The id of the agent.custom_tool_use event this result corresponds to, which can be found in the last session.status_idle event's stop_reason.event_ids field. |
| data[].is_error | null | boolean | Whether the tool execution resulted in an error. |
| data[].description | string | What the agent should produce. Copied from the input event. |
| data[].max_iterations | null | number | Evaluate-then-revise cycles before giving up. Default 3, max 20. |
| data[].outcome_id | string | Server-generated outc_ ID for this outcome. Referenced by span.outcome_evaluation_* events and the session's outcome_evaluations list. |
| data[].rubric | object | Rubric for grading the quality of an outcome. |
| data[].event_id | string | Id of the event this event refers to. |
| data[].message_id | string | Envelope field, not part of this event's own payload: the transcript message id of the row, added by the shared projection in apps/api/src/routes/managed-session-events.ts whenever the row carries one (#4480). No writer of this event stamps a message id today, so it is declared for the frame shape rather than produced here. |