从工具错误中恢复
如果模型有可能从工具故障中恢复,请在工具上设置OnError: "return-to-model"。SDK 会将错误转换为工具结果,让下一轮选择其他操作。对于不安全或无法恢复的故障,请保留默认的运行失败行为。
遵循取消信号
将请求上下文传递给Run、Continue 或 Stream。取消该上下文会停止模型流式传输,并阻止启动新的工具任务。
Documentation Index
Fetch the complete documentation index at: /docs/llms.txt
Use this file to discover all available pages before exploring further.
处理 Go Agent 中的模型、工具、验证、取消和继续运行错误。
OnError: "return-to-model"。SDK 会将错误转换为工具结果,让下一轮选择其他操作。对于不安全或无法恢复的故障,请保留默认的运行失败行为。
Run、Continue 或 Stream。取消该上下文会停止模型流式传输,并阻止启动新的工具任务。
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
result, err := agent.Run(ctx, options)
if errors.Is(err, context.DeadlineExceeded) {
// Persist enough application state to retry or report the timeout.
}