Skip to main content

Event Stream

@llm_chat calls return an AsyncGenerator[ReactOutput, None]; @llm_function exposes the same event stream through fn.stream(...). Each yielded item is either a response (final output) or an event (lifecycle signal).

ReactOutput

Use type guards to distinguish:

ResponseYield

Contains the final agent output:

EventYield

Contains a lifecycle event:

The 14 Event Types

Loop Lifecycle

LLM Call

Tool Execution

Custom Events

Custom events are emitted by tools via ToolEventEmitter — used for streaming tool output (e.g., PyRepl stdout, shell output).

Convenience Filters

EventOrigin (Fork Routing)

When using SelfRef forks, events come from multiple agents. EventOrigin identifies the source:
Use this to route events to different UI panels (e.g., main agent vs. child agents).

Common Patterns

Streaming Text to Terminal

Progress Tracking

Event Observer Decorator

For cross-cutting event handling without modifying consumption logic:
API Reference: Events