Skip to main content
Walks through WithErrorControl on one agent: fallback after an LLM error, one extra iteration, and a circuit breaker that skips a tool that keeps failing. Source: examples/agent_with_error_control/ The sample uses stub LLM clients and a stub tool so you can run it without a provider key. Set AGENT_RUNTIME=temporal or restate in examples/.env to exercise those runtimes. These callbacks are error control, not lifecycle WithHooks.

What you will see

Run

From examples/:

Expected output

Hook lines go to stderr. Scenario 3’s third tool call is skipped, so failed stays 2.

Temporal and Restate

Pass the same WithNamedLLMClients and WithErrorControl on the agent that starts the run and on the worker. The SDK fingerprints hook slots (not bodies), the fallback name, named-client model/provider, and breaker thresholds. On Restate, the hooks run in the process that serves the embedded endpoint.

Learn more

Error Control

How to configure fallback, extra iterations, and the breaker

Hooks

Lifecycle middleware — a different API