Skip to main content

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

The EventType enum defines all possible event types in the system:

BaseEvent

All events inherit from the BaseEvent 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 to TextMessageStart → TextMessageContent → TextMessageEnd automatically in the JS/TS client.
Behavior
  • 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. When role is omitted, it defaults to assistant.
  • Streaming: Subsequent chunks with the same messageId emit TextMessageContent events. TextMessageEnd is 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, creating ReasoningMessage 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 new ReasoningMessage 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 to ReasoningMessageStart → ReasoningMessageContent → ReasoningMessageEnd automatically in the JS/TS client.
Behavior
  • 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 messageId emit ReasoningMessageContent events. ReasoningMessageEnd is 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 by entityId 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 optional subagentRunId 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 optional subagentRunId. 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

The THINKING_* events are deprecated and will be removed in version 1.0.0. New implementations should use REASONING_* events instead.

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:
This allows for runtime validation of events and provides TypeScript type inference.

ToolCallChunkEvent

Convenience event that expands to ToolCallStart → ToolCallArgs → ToolCallEnd automatically in the JS/TS client.
Behavior
  • Omit start/end: The client transforms chunk sequences into the standard start/args/end triad.
  • First chunk requirements: The first chunk must include both toolCallId and toolCallName; parentMessageId is propagated to ToolCallStart if given.
  • Streaming: Subsequent chunks with the same toolCallId emit ToolCallArgs. ToolCallEnd is emitted automatically when the tool call changes or when the stream completes.