API Reference

Session 类型与结果

Session 输入输出对象里最重要的字段和语义

Session 类型与结果

最常见的输入输出对象有:

  • AgentSession
  • RemoteAgentSession
  • AgentSessionSetInput
  • AgentSessionSetOptions
  • RemoteSessionSetInput
  • AgentSessionStatus
  • AgentSessionPromptInput
  • AgentSessionStopResult
  • AgentSessionTurnHandle
  • AgentSessionTurnResult
  • SessionMutation
  • SessionMessage
  • SessionPendingInteraction
  • RespondSessionInteractionInput
  • AgentSessionInfo

先按用途选择类型

你要做什么应该消费的对象
首次加载、历史与重连恢复SessionMessagePage / SessionMessage
实时文本、工具和标题SessionMutation
等待一次执行结束AgentSessionTurnHandle / AgentSessionTurnResult
展示或提交用户异步交互SessionPendingInteraction / SessionInteractionResult
侧边栏与当前会话头部AgentSessionSummary / AgentSessionInfo
运行状态与安全策略AgentSessionStatus

AgentSessionStatus.security 同时提供 configured approval_mode 与检查点已经提交的 effective_approval_mode。两者不同时,配置仍在 Session Queue 中等待执行。

AgentSessionSetOptions 控制真实配置变化提交后的可观测输出:persist_action 决定是否写入 Action Message,publish_mutation 决定是否通过 Session 订阅发布对应 Mutation。两者均省略时保持默认的持久化与发布行为。

AgentSessionPromptInput

核心字段:

  • query

AgentSessionTurnHandle

核心字段:

  • id
  • result
  • finished

AgentSessionTurnResult

核心字段:

  • turn_id
  • success
  • error
  • text

text 用于简洁的最终结果。结构化 Assistant Message 只有一份 canonical 状态, 应通过 session.messages()session.subscribe() 读取,不会在 Turn Result 中复制。

AgentSessionStopResult

核心字段:

  • stopped
  • turn_id
  • cancelled_queued_prompts
  • reason

session.stop() 会停止当前 turn,并取消尚未被当前 turn 吸收的排队 prompt。空闲时调用不会抛错,会返回 stopped: falsereason: "idle"

深入阅读