Skip to main content

Events

The AG-UI protocol uses a comprehensive event system for agent-UI communication. All events extend from BaseEvent and are strongly typed for compile-time safety.

BaseEvent

The base class for all protocol events:

Lifecycle Events

Track the execution lifecycle of agent runs and steps.

RunStartedEvent

Signals the beginning of an agent run:

RunFinishedEvent

Signals the completion of an agent run:

StepStartedEvent

Marks the beginning of a processing step:

StepFinishedEvent

Marks the completion of a processing step:

Example Usage

Text Message Events

Handle streaming text responses from the assistant.

TextMessageStartedEvent

Indicates the start of a text message:

TextMessageDeltaEvent

Streams incremental text content:

TextMessageFinishedEvent

Signals message completion:

Example: Streaming Text

Tool Call Events

Track tool/function invocations by the agent.

ToolCallStartedEvent

Signals the start of a tool call:

ToolCallProgressEvent

Reports progress during tool execution:

ToolCallFinishedEvent

Signals tool call completion:

Example: Tool Tracking

State Management Events

Handle agent state updates and synchronization.

StateSnapshotEvent

Provides a complete state snapshot:

StateDeltaEvent

Provides incremental state updates using JSON Patch:

MessagesSnapshotEvent

Provides conversation history:

Example: State Management

Special Events

Handle raw data and custom event types.

RawEvent

For custom or unrecognized events:

ErrorEvent

For error notifications:

MetadataEvent

For metadata updates:

Event Handling Patterns

Complete Handler

Handle all event types comprehensively:

Stream Transformations

Transform event streams for specific use cases:

Event Aggregation

Collect related events:

Testing Events

Create mock events for testing: