Events
The Agent User Interaction Protocol 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
TheEventType enum defines all possible event types in the system:
BaseEvent
All events inherit from theBaseEvent type, which provides common properties
shared across all event types.
metadata is open by key: any JSON value is allowed under a key, including
null. The object may be absent, but a present one is never null — an
explicit null parses as absent. The ag-ui key is reserved for AG-UI’s own
use. Use mergeMetadata from @ag-ui/core to fold event metadata into a
message; see Metadata.
Lifecycle Events
These events represent the lifecycle of an agent run.RunStartedEvent
Signals the start of an agent run.TokenUsage
A reusable, numeric-only token usage summary carried on terminal run events. It intentionally contains only provider/model labels and token counts — no prompts, completions, messages, or identifiers. The counts follow the protocol’s accounting: the input and output counts are totals, and the cache and reasoning counts are parts of them, never additions.RunFinishedEvent
Signals the successful completion of an agent run.RunErrorEvent
Signals an error during an agent run.StepStartedEvent
Signals the start of a step within an agent run.StepFinishedEvent
Signals the completion of a step within an agent run.Text Message Events
These events represent the lifecycle of text messages in a conversation.TextMessageStartEvent
Signals the start of a text message.TextMessageContentEvent
Represents a chunk of content in a streaming text message.TextMessageEndEvent
Signals the end of a text message.TextMessageChunkEvent
Convenience event that expands toTextMessageStart → TextMessageContent →
TextMessageEnd automatically in the JS/TS client.
- Omit start/end: The client transforms chunk sequences into the standard start/content/end triad, so you don’t need to emit them manually.
- First chunk requirements: The first chunk for a message must include
messageId. Whenroleis omitted, it defaults toassistant. - Streaming: Subsequent chunks with the same
messageIdemitTextMessageContentevents.TextMessageEndis emitted automatically when a different message starts or when the stream completes.
Tool Call Events
These events represent the lifecycle of tool calls made by agents.ToolCallStartEvent
Signals the start of a tool call.ToolCallArgsEvent
Represents a chunk of argument data for a tool call.ToolCallEndEvent
Signals the end of a tool call.ToolCallResultEvent
Provides the result of a tool call execution.State Management Events
These events are used to manage agent state.StateSnapshotEvent
Provides a complete snapshot of an agent’s state.StateDeltaEvent
Provides a partial update to an agent’s state using JSON Patch.MessagesSnapshotEvent
Provides a snapshot of all messages in a conversation.ActivitySnapshotEvent
Delivers a complete snapshot of an activity message.ActivityDeltaEvent
Provides incremental updates to an activity snapshot using JSON Patch.Reasoning Events
These events represent the lifecycle of reasoning/thinking processes within an agent. Reasoning events allow agents to expose their internal thought process to the frontend, creatingReasoningMessage objects that persist in the message
history with the role "reasoning".
ReasoningStartEvent
Signals the start of a reasoning phase. This is a pass-through event that notifies subscribers but does not create messages.ReasoningMessageStartEvent
Signals the start of a reasoning message. Creates a newReasoningMessage in
the message history.
ReasoningMessageContentEvent
Represents a chunk of content in a streaming reasoning message.ReasoningMessageEndEvent
Signals the end of a reasoning message.ReasoningMessageChunkEvent
Convenience event that expands toReasoningMessageStart →
ReasoningMessageContent → ReasoningMessageEnd automatically in the JS/TS
client.
- Omit start/end: The client transforms chunk sequences into the standard start/content/end triad.
- First chunk requirements: The first chunk for a message must include
messageId. - Streaming: Subsequent chunks with the same
messageIdemitReasoningMessageContentevents.ReasoningMessageEndis emitted automatically when a different message starts or when the stream completes.
ReasoningEndEvent
Signals the end of a reasoning phase. This is a pass-through event that notifies subscribers but does not modify messages.ReasoningEncryptedValueEvent
Attaches an encrypted value to a message or tool call. When this event is emitted, it finds the referenced entity byentityId and sets its
encryptedValue field.
Subagent Events
These events report that the agent delegated work to a child agent, so a frontend can attribute output to the subagent that produced it. Attribution itself travels as an optionalsubagentRunId on most other event types.
subagentRunId identifies one invocation, not a reusable subagent
definition — the same subagent run twice yields two different values. See
Subagents for the full model.
SubagentStartedEvent
Announces a new subagent invocation and names it for display.SubagentFinishedEvent
Marks a subagent invocation as complete.SubagentErrorEvent
Marks a subagent invocation as failed.Attribution on other events
Most event types accept an optionalsubagentRunId. An event without it belongs
to the parent agent, so a stream that never sets the field behaves exactly as it
did before subagents existed.
RunStartedEvent, RunFinishedEvent and RunErrorEvent are not attributable —
they describe the run as a whole. MessagesSnapshotEvent carries attribution
per-message instead, since one snapshot mixes messages from several producers.
StateSnapshotEvent and StateDeltaEvent are attributable, but attribution on
them is provenance rather than ownership — it records which subagent produced the
update. State stays run-scoped, so an attributed snapshot or delta is applied to
the run’s one state document just as an unattributed one is. There is no
per-subagent state.
Subscribers can react to the lifecycle directly via onSubagentStartedEvent,
onSubagentFinishedEvent and onSubagentErrorEvent.
Special Events
RawEvent
Used to pass through events from external systems.CustomEvent
Used for application-specific custom events.Deprecated Events
Thinking Events (Deprecated)
The following event types are deprecated:
See Reasoning Migration
for detailed migration guidance.
Event Schemas
The SDK uses Zod schemas to validate events:ToolCallChunkEvent
Convenience event that expands toToolCallStart → ToolCallArgs →
ToolCallEnd automatically in the JS/TS client.
- Omit start/end: The client transforms chunk sequences into the standard start/args/end triad.
- First chunk requirements: The first chunk must include both
toolCallIdandtoolCallName;parentMessageIdis propagated toToolCallStartif given. - Streaming: Subsequent chunks with the same
toolCallIdemitToolCallArgs.ToolCallEndis emitted automatically when the tool call changes or when the stream completes.