智能体

发送事件

发送事件。使用当前 API Key 所属工作区的资源。

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

POST /agent/v1/sessions/{session_id}/events◐ 部分支持

Claude 官方文档 ↗

请求参数

  • session_idstring必填

    path: Session id (sesn_...), as returned by sessions.create or sessions.list. The same id is also accepted as the session_id query parameter on resource and thread calls, where it must equal the path value.

  • eventsarray必填

    要发送给会话的事件列表。

返回

200

将 sesn_123 换成创建会话返回的 id。每条 user.message 只接受一个非空文本块。支持文本 user.message、user.interrupt 和工具确认;可发送 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,让本次对话记住同类操作;危险操作不提供可记住的建议。使用网页搜索或读取网页时,/agent/v1 与 /anthropic 的工具结果均为官方 search_result 块;回答文本块的 citations 是 /agent/v1 的扩展字段,/anthropic 将回答引用显示为正文中的 [n]。

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

响应

HTTP 200

Successful response

application/json

名称类型说明
dataarray<object>Sent events
data[].idstringUnique 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. / Event id, unique within the session.
data[].contentarray<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[].typestringAlways `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. / Always `user.tool_confirmation`.
data[].processed_atnull | string | string | null | string | null | string | string | stringA timestamp in RFC 3339 format / RFC 3339 time at which the server processed the event; null while a queued input has not started running. / When the event was recorded, RFC 3339.
data[].session_thread_idnull | stringIf 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.
data[].resultstringUserToolConfirmationResult enum / Always `allow`.
data[].tool_use_idstringThe 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. / The id of the AskUserQuestion `agent.tool_use` event this answers.
data[].deny_messagenull | stringOptional message providing context for a 'deny' decision. Only allowed when result is 'deny'.
data[].custom_tool_use_idstringThe 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_errornull | booleanWhether the tool execution resulted in an error.
data[].descriptionstringWhat the agent should produce. Copied from the input event.
data[].max_iterationsnull | numberEvaluate-then-revise cycles before giving up. Default 3, max 20.
data[].outcome_idstringServer-generated `outc_` ID for this outcome. Referenced by `span.outcome_evaluation_*` events and the session's `outcome_evaluations` list.
data[].rubricobjectRubric for grading the quality of an outcome.
data[].event_idstringId of the event this event refers to.
data[].answersobjectThe user's answer to each question, keyed by the question text; empty when the questions were dismissed.
data[].annotationsobjectPer-question notes, keyed by the question text.