Skip to main content

生命周期事件

使用 run_with_events(...) 或 continue_with_events(...) 同步接收事件:
运行时目前会发出以下事件:
  • run.started
  • model.request.started
  • model.response.completed
  • tool.started
  • tool.completed
  • run.paused
  • run.resumed
  • run.completed
  • run.stopped
回调在运行所在的线程中执行。请保持回调快速,或将工作交给其他组件。

模型重试

max_retries统计首次请求之后的额外尝试次数。RunStep.model_attempts记录获得成功模型响应所需的尝试次数。

用量

RunResult.usage汇总以下数据:
  • input_tokens
  • output_tokens
  • cached_tokens
  • total_tokens
  • 如果模型客户端填充了该值,则包含 cost
每个 RunStep 还包含自己的用量摘要、请求 ID、提供商、模型和结束原因。 内置的 0.1 Gateway 适配器不会将 Gateway 的 cost_nanos 或 cost_cents 映射到 UsageSummary.cost。如需精确费用,请查看 Gateway 响应或生成记录。

错误

所有运行时故障均使用 AgentError:
Gateway 的 PhaseoError 会转换为 AgentError。如果应用需要原始 Gateway 状态和响应正文,请直接调用 phaseo 客户端,或实现自定义 ModelClient,并在错误处理中保留这些字段。 本地工具执行器错误会作为工具结果返回给模型,而不会立即结束运行。

步骤上限

AgentDefinition::max_steps(...)设置默认模型轮次上限。可为单次运行覆盖此值:
达到上限时,run.status为 stopped,run.stop_reason为 max_steps:<limit>。
最后修改于 2026年10月2日