Events
The agent communicates state transitions via an event bus. Every meaningful action emits an sdk.Event to all registered subscribers.
Subscribing
Multiple subscribers are allowed. Each runs in its own goroutine. The EventBus is non-blocking — Publish enqueues to a 4096-item buffered channel per subscriber and returns immediately, so slow subscribers drop events rather than stalling the agent loop.
Event Reference
| Type constant | Payload | Fired when |
|---|---|---|
EventAgentStart | — | Prompt() called, agent loop begins |
EventAgentEnd | — | Agent loop completes (all turns done) |
EventTurnStart | — | An LLM request turn begins |
EventTurnEnd | — | A turn’s tool calls finish |
EventMessageStart | — | LLM starts streaming a response |
EventMessageEnd | — | LLM response stream complete |
EventTextDelta | e.Content string | Incremental response text chunk |
EventThinkingDelta | e.Content string | Incremental extended-thinking chunk |
EventToolCall | e.ToolCall | Tool invocation requested by LLM |
EventToolDelta | e.Content string | Streaming partial output from a running tool |
EventToolOutput | e.ToolOutput | Final tool result (success or error) |
Event Flow Per Prompt
Agent State Machine
The agent transitions through explicit states visible via EventAgentStart/EventAgentEnd and the ag.Idle() channel:
ag.Idle() returns a channel that closes when the agent returns to Idle. Use it to block until a prompt completes: