How It Works
Quick Start
Callback Types
| Type | When it fires |
|---|---|
interaction | User message and agent response |
tool_call | Before or during a tool invocation |
error | Agent or tool error |
llm_start / llm_end | LLM request lifecycle |
llm_content | Streaming token chunks |
autonomy_iteration | Autonomous loop iteration |
autonomy_doom_loop | Doom loop detected in autonomy mode |
retry | Retry after transient failure |
register_display_callback(type, fn, is_async=False). Alias: add_display_callback.
Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
display_type | str | — | One of the supported callback types above |
callback_fn | callable | — | Sync or async handler |
is_async | bool | False | Store in the async registry when True |
message, response, tool_name, agent_name). Extra kwargs are filtered to the function signature automatically.
Best Practices
Keep handlers lightweight
Keep handlers lightweight
Display callbacks run on the hot path. Log or enqueue work — avoid heavy I/O in sync handlers.
Use async for network and UI
Use async for network and UI
Set
is_async=True when writing to WebSockets, Slack, or dashboards so the agent loop stays responsive.Wrap custom logic in try/except
Wrap custom logic in try/except
A failing callback should not crash the agent. Catch, log, and return.
Compose with hooks for fine control
Compose with hooks for fine control
Use display callbacks for output formatting; use hooks when you need to allow, block, or mutate tool calls.
Related
Display System
TaskOutput, terminal rendering, and global registries
Callbacks
Broader callback patterns for agents and tasks

