生命周期事件
使用run_with_events(...) 或 continue_with_events(...) 同步接收事件:
run.startedmodel.request.startedmodel.response.completedtool.startedtool.completedrun.pausedrun.resumedrun.completedrun.stopped
模型重试
max_retries统计首次请求之后的额外尝试次数。RunStep.model_attempts记录获得成功模型响应所需的尝试次数。
用量
RunResult.usage汇总以下数据:
input_tokensoutput_tokenscached_tokenstotal_tokens- 如果模型客户端填充了该值,则包含
cost
RunStep 还包含自己的用量摘要、请求 ID、提供商、模型和结束原因。
内置的 0.1 Gateway 适配器不会将 Gateway 的 cost_nanos 或 cost_cents 映射到 UsageSummary.cost。如需精确费用,请查看 Gateway 响应或生成记录。
错误
所有运行时故障均使用AgentError:
PhaseoError 会转换为 AgentError。如果应用需要原始 Gateway 状态和响应正文,请直接调用 phaseo 客户端,或实现自定义 ModelClient,并在错误处理中保留这些字段。
本地工具执行器错误会作为工具结果返回给模型,而不会立即结束运行。
步骤上限
AgentDefinition::max_steps(...)设置默认模型轮次上限。可为单次运行覆盖此值:
run.status为 stopped,run.stop_reason为 max_steps:<limit>。