Skip to content

Error Handling

Tools return ToolResult.Success(...) or ToolResult.Error(...). Tool failures are still part of the event stream, so you can inspect and react before deciding whether to continue.

When using StepAsync(), inspect TurnResult:

  • FinishReason tells you why the turn stopped.
  • ToolCalls shows the requested tool executions.
  • RequiresNextTurn tells you whether the loop should continue.

Agent exposes ContinueOnMaxTokens. Leave it off for bounded work or turn it on for long-form generation that should continue past one max-token boundary.

  • ToolTimeout caps tool execution time.
  • SessionHelpers.RemoveFailedTools(...) and Rewind(...) help recover from failed branches.
  • CreateCheckpoint(...) is useful before risky operations.

If a workflow needs a human decision, pair StepAsync() with tool inspection or use interactive tooling through IToolContextProvider and AskUserQuestion.