OpenAI 提交会话输入事件

2026-11-18 18:01 更新

post /agents/sessions/{session_id}/events

向托管智能体会话提交消息、取消、工具结果或计算机使用审批响应事件。如果后端执行已结束,但该轮仍显示为开放,可通过取消将其恢复到已取消状态。未发布的输出将被丢弃,已保存的结果、已发布的文件和已有的终态结果均会保留。HTTP 202 表示已受理,最终完成状态需另行确认。参见会话事件。

请求头参数

  • "Idempotency-Key": optional string

minLength: 1, maxLength: 256

路径参数

  • session_id: string

会话 ID。

minLength: 0, maxLength: 1048576

请求体参数

内容类型为 application/json。

  • events: array of AgentSessionInputParam

要提交到会话的输入事件。

minItems: 0, maxItems: 16384

  • AgentSessionInputMcpApprovalRequestResult object { request_id, response, type }

响应待处理的 MCP 工具调用审批请求。

  • request_id: string

必需操作提供的不透明审批 ID。

minLength: 0, maxLength: 1048576

  • response: object { decision, type }

用户对待处理 MCP 工具调用的决定。

  • decision: "approve" or "deny" or "cancel"

取消此请求并关闭提示,会话和当前轮次仍然保留。

  • "approve"

  • "deny"

  • "cancel"

  • type: "mcp_tool_call" (default: "mcp_tool_call")

对象类型,固定为 mcp_tool_call。

  • "mcp_tool_call"

  • type: "agent.session.input.mcp_approval_request_result" (default: "agent.session.input.mcp_approval_request_result")

对象类型,固定为 agent.session.input.mcp_approval_request_result。

  • "agent.session.input.mcp_approval_request_result"

  • AgentSessionInputComputerUseApprovalRequestResult object { request_id, response, type }

响应待处理的计算机使用审批请求。

  • request_id: string

必需操作提供的已注册请求 ID。

minLength: 0, maxLength: 1048576

  • response: AgentBrowserAuthenticationSubmitParam or AgentBrowserAuthenticationCancelParam or AgentBrowserOriginAccessParam

此请求类型对应的响应。

  • AgentBrowserAuthenticationSubmitParam object { action, fields, type, selected_option }

  • action: "submit" (default: "submit")

  • "submit"

  • fields: array of object { field_id, value }

最多为必需操作中的 6 个活动字段提供值。提交的字段值映射与选定选项合计不得超过 120 KiB 的 JSON。

minItems: 0, maxItems: 6

  • field_id: string

必需操作提供的字段 ID。

minLength: 0, maxLength: 1048576

  • value: string

要填入已注册控件的值。

minLength: 0, maxLength: 16384

  • type: "browser_authentication" (default: "browser_authentication")

  • "browser_authentication"

  • selected_option: optional string or null

选中的方式。必需操作包含可选方式时,此项必填。

minLength: 0, maxLength: 1048576

  • AgentBrowserAuthenticationCancelParam object { action, type }

  • action: "cancel" (default: "cancel")

  • "cancel"

  • type: "browser_authentication" (default: "browser_authentication")

  • "browser_authentication"

  • AgentBrowserOriginAccessParam object { decision, type }

  • decision: "approve" or "deny" or "cancel"

允许、拒绝或取消所请求的源站访问。

  • "approve"

允许浏览器访问此源站。

  • "deny"

拒绝访问此源站。

  • "cancel"

关闭此请求,访问保持未获批准。

  • type: "browser_origin_access" (default: "browser_origin_access")

  • "browser_origin_access"

  • type: "agent.session.input.computer_use_approval_request_result" (default: "agent.session.input.computer_use_approval_request_result")

对象类型,固定为 agent.session.input.computer_use_approval_request_result。

  • "agent.session.input.computer_use_approval_request_result"

  • AgentSessionInputMessage object { input, type }

添加一条或多条用户消息并开始一轮交互。

  • input: array of AgentSessionInputMessageParam

要添加到会话的用户消息。

minItems: 0, maxItems: 16384

  • content: array of InputContentParam

消息内容。

minItems: 0, maxItems: 16384

  • InputText object { text, type }

提供给模型的文本输入。

  • text: string

发送给模型的文本。

minLength: 0, maxLength: 1048576

  • type: "input_text" (default: "input_text")

对象类型,固定为 input_text。

  • "input_text"

  • InputImage object { image_url, type }

提供给模型的图像输入。

  • image_url: string

发送给模型的图像 URL。

minLength: 0, maxLength: 1048576

  • type: "input_image" (default: "input_image")

对象类型,固定为 input_image。

  • "input_image"

  • role: "user" (default: "user")

消息作者的角色,固定为 user。

  • "user"

  • type: optional "message" (default: "message")

输入条目类型,固定为 message。

  • "message"

  • type: "agent.session.input.message" (default: "agent.session.input.message")

对象类型,固定为 agent.session.input.message。

  • "agent.session.input.message"

  • AgentSessionInputCancel object { type }

取消会话中正在进行的轮次。

  • type: "agent.session.input.cancel" (default: "agent.session.input.cancel")

对象类型,固定为 agent.session.input.cancel。

  • "agent.session.input.cancel"

  • AgentSessionInputToolResult object { call_id, success, turn_id, 3 more }

提交函数调用的结果。

  • call_id: string

函数调用 ID。

minLength: 0, maxLength: 1048576

  • success: boolean

函数调用是否成功。

  • turn_id: string

请求函数调用的轮次 ID。

minLength: 0, maxLength: 1048576

  • type: "agent.session.input.tool_result" (default: "agent.session.input.tool_result")

对象类型,固定为 agent.session.input.tool_result。

  • "agent.session.input.tool_result"

  • error: optional string or null

调用失败时返回的错误消息。

minLength: 0, maxLength: 1048576

  • output: optional AgentFunctionCallOutputParam or null

调用成功时返回的函数结果。

  • string

minLength: 0, maxLength: 1048576

  • array of InputContentParam

minItems: 0, maxItems: 16384

  • InputText object { text, type }

提供给模型的文本输入。

  • InputImage object { image_url, type }

提供给模型的图像输入。

示例

## 从环境变量读取 API 密钥。
## 将 SESSION_ID 设置为目标会话的 ID。
## 将 request_id 替换为本会话待审批请求的实际 ID,按用户的审批决定提交。
curl https://api.openai.com/v1/agents/sessions/$SESSION_ID/events \
    -H 'Content-Type: application/json' \
    -H 'OpenAI-Beta: agents=v1' \
    -H "Authorization: Bearer $OPENAI_API_KEY" \
    -d '{
          "events": [
            {
              "request_id": "request_id",
              "response": {
                "decision": "approve",
                "type": "mcp_tool_call"
              },
              "type": "agent.session.input.mcp_approval_request_result"
            }
          ]
        }'
以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号