Events
The Agent User Interaction Protocol Python SDK uses a streaming event-based architecture. Events are the fundamental units of communication between agents and the frontend. This section documents the event types and their properties.EventType Enum
from ag_ui.core import EventType
The EventType enum defines all possible event types in the system:
BaseEvent
from ag_ui.core import BaseEvent
All events inherit from the BaseEvent class, which provides common properties
shared across all event types.
| Property | Type | Description | 
|---|---|---|
type | EventType | The type of event (discriminator field for the union) | 
timestamp | Optional[int] | Timestamp when the event was created | 
raw_event | Optional[Any] | Original event data if this event was transformed | 
Lifecycle Events
These events represent the lifecycle of an agent run.RunStartedEvent
from ag_ui.core import RunStartedEvent
Signals the start of an agent run.
| Property | Type | Description | 
|---|---|---|
thread_id | str | ID of the conversation thread | 
run_id | str | ID of the agent run | 
parent_run_id | Optional[str] | (Optional) Lineage pointer for branching/time travel. If present, refers to a prior run within the same thread | 
input | Optional[RunAgentInput] | (Optional) The exact agent input payload sent to the agent for this run. May omit messages already in history | 
RunFinishedEvent
from ag_ui.core import RunFinishedEvent
Signals the successful completion of an agent run.
| Property | Type | Description | 
|---|---|---|
thread_id | str | ID of the conversation thread | 
run_id | str | ID of the agent run | 
result | Optional[Any] | Result data from the agent run | 
RunErrorEvent
from ag_ui.core import RunErrorEvent
Signals an error during an agent run.
| Property | Type | Description | 
|---|---|---|
message | str | Error message | 
code | Optional[str] | Error code | 
StepStartedEvent
from ag_ui.core import StepStartedEvent
Signals the start of a step within an agent run.
| Property | Type | Description | 
|---|---|---|
step_name | str | Name of the step | 
StepFinishedEvent
from ag_ui.core import StepFinishedEvent
Signals the completion of a step within an agent run.
| Property | Type | Description | 
|---|---|---|
step_name | str | Name of the step | 
Text Message Events
These events represent the lifecycle of text messages in a conversation.TextMessageStartEvent
from ag_ui.core import TextMessageStartEvent
Signals the start of a text message.
| Property | Type | Description | 
|---|---|---|
message_id | str | Unique identifier for the message | 
role | Literal["assistant"] | Role is always “assistant” | 
TextMessageContentEvent
from ag_ui.core import TextMessageContentEvent
Represents a chunk of content in a streaming text message.
| Property | Type | Description | 
|---|---|---|
message_id | str | Matches the ID from TextMessageStartEvent | 
delta | str | Text content chunk (non-empty) | 
TextMessageEndEvent
from ag_ui.core import TextMessageEndEvent
Signals the end of a text message.
| Property | Type | Description | 
|---|---|---|
message_id | str | Matches the ID from TextMessageStartEvent | 
Tool Call Events
These events represent the lifecycle of tool calls made by agents.ToolCallStartEvent
from ag_ui.core import ToolCallStartEvent
Signals the start of a tool call.
| Property | Type | Description | 
|---|---|---|
tool_call_id | str | Unique identifier for the tool call | 
tool_call_name | str | Name of the tool being called | 
parent_message_id | Optional[str] | ID of the parent message | 
ToolCallArgsEvent
from ag_ui.core import ToolCallArgsEvent
Represents a chunk of argument data for a tool call.
| Property | Type | Description | 
|---|---|---|
tool_call_id | str | Matches the ID from ToolCallStartEvent | 
delta | str | Argument data chunk | 
ToolCallEndEvent
from ag_ui.core import ToolCallEndEvent
Signals the end of a tool call.
| Property | Type | Description | 
|---|---|---|
tool_call_id | str | Matches the ID from ToolCallStartEvent | 
ToolCallResultEvent
from ag_ui.core import ToolCallResultEvent
Provides the result of a tool call execution.
| Property | Type | Description | 
|---|---|---|
message_id | str | ID of the conversation message this result belongs to | 
tool_call_id | str | Matches the ID from the corresponding ToolCallStartEvent | 
content | str | The actual result/output content from the tool execution | 
role | Optional[Literal["tool"]] | Optional role identifier, typically “tool” for tool results | 
State Management Events
These events are used to manage agent state.StateSnapshotEvent
from ag_ui.core import StateSnapshotEvent
Provides a complete snapshot of an agent’s state.
| Property | Type | Description | 
|---|---|---|
snapshot | State | Complete state snapshot | 
StateDeltaEvent
from ag_ui.core import StateDeltaEvent
Provides a partial update to an agent’s state using JSON Patch.
| Property | Type | Description | 
|---|---|---|
delta | List[Any] | Array of JSON Patch operations | 
MessagesSnapshotEvent
from ag_ui.core import MessagesSnapshotEvent
Provides a snapshot of all messages in a conversation.
| Property | Type | Description | 
|---|---|---|
messages | List[Message] | Array of message objects | 
ActivitySnapshotEvent
from ag_ui.core import ActivitySnapshotEvent
Delivers a complete snapshot of an activity message.
| Property | Type | Description | 
|---|---|---|
message_id | str | Identifier for the target ActivityMessage | 
activity_type | str | Activity discriminator such as "PLAN" or "SEARCH" | 
content | Any | Structured payload describing the full activity state | 
replace | bool (default True) | When False, the snapshot is ignored if a message with the same ID already exists | 
ActivityDeltaEvent
from ag_ui.core import ActivityDeltaEvent
Provides incremental updates to an activity snapshot using JSON Patch.
| Property | Type | Description | 
|---|---|---|
message_id | str | Identifier for the target ActivityMessage | 
activity_type | str | Activity discriminator mirroring the most recent snapshot | 
patch | List[Any] | JSON Patch operations applied to the structured activity content | 
Special Events
RawEvent
from ag_ui.core import RawEvent
Used to pass through events from external systems.
| Property | Type | Description | 
|---|---|---|
event | Any | Original event data | 
source | Optional[str] | Source of the event | 
CustomEvent
from ag_ui.core import CustomEvent
Used for application-specific custom events.
| Property | Type | Description | 
|---|---|---|
name | str | Name of the custom event | 
value | Any | Value associated with the event | 
Event Discrimination
from ag_ui.core import Event
The SDK uses Pydantic’s discriminated unions for event validation: