Skip to main content
Every AFK agent run produces a stream of AgentRunEvent instances that describe what happened during execution. These events form the run’s audit trail — they tell you when the run started, when LLM calls were made, when tools executed, when policy decisions were rendered, and how the run terminated. Understanding the event contract is essential for building real-time UIs, logging pipelines, eval assertions, and debugging tools. This page documents every event type, explains when each fires, describes the data it carries, and provides patterns for consuming events safely.

Event stream model

Every run begins with run_started and ends with exactly one terminal event: run_completed, run_failed, run_interrupted, or run_cancelled. Between those boundaries, the runner emits step, LLM, tool, policy, and subagent events in the order they occur.

Event reference

AgentRunEvent structure

Each event is an AgentRunEvent dataclass with the following fields:

Consuming events

The primary way to consume events is through the run handle’s events async iterator:

Pattern: event-type branching

The recommended consumption pattern is a simple if/elif chain that branches on event.type. This is explicit, readable, and easy to extend:

Forward compatibility

The event contract is append-only. New event types may be added in future releases, but existing event types will not be removed or have their data fields changed. Your event consumer should always handle unknown event types gracefully. The simplest approach is a default branch that logs or ignores unknown types:
This ensures your code continues to work when AFK adds new event types without requiring a code update.