Events
Documentation for the events used in the Agent User Interaction Protocol Python SDK
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 |
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 |
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 |
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 |
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:
This allows for runtime validation of events and type checking at development time.