Skip to main content
Run outcomes give every agent execution a typed status so your code can handle success, failure, timeout, cancellation, and invalid output exhaustively — no string matching.
The user handles every finish state in code; the agent returns a typed AgentRunOutcome instead of an ambiguous string.

Quick Start

1

Simple Usage

Every agent execution returns an AgentRunOutcome that you can check for success.
2

Exhaustive Matching

Match all five status types exhaustively to handle every possible outcome.
3

Validation Routing

Access typed outcomes from task validation instead of parsing strings.

How It Works

Every agent execution produces an AgentRunOutcome with a typed status that enables exhaustive pattern matching:
StatusMeaningRetryableWhen It Occurs
successCompleted successfullyNoAgent produced valid output
failureNon-retryable logic errorNoUnhandled exception, logic error
timeoutOperation exceeded time limitYesSlow LLM, network hang
cancelledExternal cancel signalNoUser Ctrl-C, parent cancelled child
invalid_outputOutput didn’t pass validationYesWrong format, validator rejected

The Five Statuses

StatusMeaningRetryableTypical Cause
successCompleted successfullyNoAgent produced valid output
failureNon-retryable logic errorNoUnhandled exception, validation logic error
timeoutOperation exceeded time limitYesSlow LLM, slow tool, network hang
cancelledExternal cancel signalNoUser Ctrl-C, parent agent cancelled child
invalid_outputOutput didn’t pass validationYesWrong format, missing fields, validator rejected

Creating Outcomes

Create outcomes using factory methods — each sets appropriate defaults automatically.

Retry Decisions

Use is_retryable() to determine if an operation can be retried safely.

Reading the Outcome From a Task

After task validation routing, check both the new typed outcome and legacy feedback.

HandoffResult Integration

Handoff results now include typed outcomes automatically derived from legacy fields.

Migration from String-Based Validation

Replace string parsing with typed status matching for safer code. Before:
After:
For gradual migration, use the compatibility helper:

Decision Flow


Best Practices

Always match against the typed status field instead of parsing error messages or legacy strings.
Let the outcome determine retry behavior instead of hardcoding status lists.
Use the context field for machine-readable metadata, keep error human-readable.
Exhaustive matching prevents bugs from unhandled cases. Avoid fall-through else clauses.

Task Validation & Feedback

Task validation with typed outcomes

Agent Handoffs

Agent-to-agent delegation with outcomes