Event reference
An AG-UI run is a sequence of events. On the wire each is a JSON object with a
type field holding a SCREAMING_SNAKE_CASE name; in Rust each is a variant of
Event, and
EventType is that
discriminator on its own.
AG-UI 1.0 defines 31 event types. Rust’s EventType::ALL contains 36
variants because the client also accepts five retired THINKING_* types from
historical streams. cargo run -p xtask -- drift-check compares the 31 current
types with the reviewed 1.0 schema baseline on every pull request — see
Verification.
Both enums are exhaustive on purpose, so a protocol addition is a compile error
where you match rather than something a _ arm swallows.
Design commitments explains why, and what it
costs.
The events
Section titled “The events”Every variant wraps a payload struct named after it — Event::TextMessageStart
carries a TextMessageStartEvent, and so on the whole way down. The payload’s
fields are serialized beside type, not nested under a key, and every payload
also carries the optional timestamp, rawEvent and metadata fields of
BaseEvent, flattened into the same object. metadata is an object open by
key — token usage, a trace id, whatever an application needs to carry — and it
is absent or an object, never null. A consumer merges each event’s metadata
into the message that event builds, key by key with the last write winning;
ag_ui::metadata has the rules
and the one reserved key.
The order below is EventType::ALL’s order; the five legacy variants appear after the tool events.
| Wire name | Rust variant | Family | What it means |
|---|---|---|---|
TEXT_MESSAGE_START |
TextMessageStart |
Text | Opens a text message under a messageId. role defaults to assistant when omitted; an explicit JSON null is rejected. |
TEXT_MESSAGE_CONTENT |
TextMessageContent |
Text | Appends delta to the open message. |
TEXT_MESSAGE_END |
TextMessageEnd |
Text | Closes the message. |
TEXT_MESSAGE_CHUNK |
TextMessageChunk |
Text | Opens or continues a text message. |
TOOL_CALL_START |
ToolCallStart |
Tool | Opens a call, naming the tool and the toolCallId that correlates everything after it. |
TOOL_CALL_ARGS |
ToolCallArgs |
Tool | Appends a fragment of the argument JSON. Fragments concatenate; one on its own is usually not valid JSON. |
TOOL_CALL_END |
ToolCallEnd |
Tool | Closes the call. The arguments are complete. |
TOOL_CALL_CHUNK |
ToolCallChunk |
Tool | Opens or continues a tool call. |
TOOL_CALL_RESULT |
ToolCallResult |
Tool | The call’s result, as a tool message appended to the thread. |
THINKING_START |
ThinkingStart |
Thinking (deprecated) | Opens a thinking block, with an optional title. Use REASONING_START. |
THINKING_END |
ThinkingEnd |
Thinking (deprecated) | Closes the thinking block. Use REASONING_END. |
THINKING_TEXT_MESSAGE_START |
ThinkingTextMessageStart |
Thinking (deprecated) | Opens a thinking message. Use REASONING_MESSAGE_START. |
THINKING_TEXT_MESSAGE_CONTENT |
ThinkingTextMessageContent |
Thinking (deprecated) | Appends thinking text. Carries no message id — a block could only ever have one message in flight, which is why it was replaced. |
THINKING_TEXT_MESSAGE_END |
ThinkingTextMessageEnd |
Thinking (deprecated) | Closes the thinking message. Use REASONING_MESSAGE_END. |
STATE_SNAPSHOT |
StateSnapshot |
State | Replaces the shared state wholesale. Free-form JSON, opaque to the protocol. |
STATE_DELTA |
StateDelta |
State | Patches the shared state with RFC 6902 operations, applied in order. |
MESSAGES_SNAPSHOT |
MessagesSnapshot |
State | Replaces the message history — after a reconnect, or when an agent rewrites history. |
ACTIVITY_SNAPSHOT |
ActivitySnapshot |
Activity | Publishes an activity’s content under a client-defined activityType. replace defaults to true. |
ACTIVITY_DELTA |
ActivityDelta |
Activity | Patches an activity’s content with RFC 6902 operations. |
RAW |
Raw |
Escape hatch | Forwards a provider event verbatim, with an optional source. |
CUSTOM |
Custom |
Escape hatch | A named application-defined event. The protocol guarantees the envelope and nothing else. |
RUN_STARTED |
RunStarted |
Lifecycle | The first event of every run: threadId, runId, optionally a parent run and the input that started it. |
RUN_FINISHED |
RunFinished |
Lifecycle | outcome distinguishes success, interruption and cancellation. |
RUN_ERROR |
RunError |
Lifecycle | A run failed. A new run may follow. |
STEP_STARTED |
StepStarted |
Lifecycle | Opens a named step within the run. |
STEP_FINISHED |
StepFinished |
Lifecycle | Closes the named step. |
REASONING_START |
ReasoningStart |
Reasoning | Opens a reasoning block for a message id. |
REASONING_MESSAGE_START |
ReasoningMessageStart |
Reasoning | Opens a reasoning message. role is required here, unlike on TEXT_MESSAGE_START, and is always reasoning. |
REASONING_MESSAGE_CONTENT |
ReasoningMessageContent |
Reasoning | Appends reasoning text. |
REASONING_MESSAGE_END |
ReasoningMessageEnd |
Reasoning | Closes the reasoning message. |
REASONING_MESSAGE_CHUNK |
ReasoningMessageChunk |
Reasoning | Opens or continues a reasoning message. |
REASONING_END |
ReasoningEnd |
Reasoning | Closes the reasoning block. |
REASONING_ENCRYPTED_VALUE |
ReasoningEncryptedValue |
Reasoning | A provider’s opaque reasoning blob, for zero-data-retention modes. subtype says whether entityId names a tool-call or a message. |
SUBAGENT_STARTED |
SubagentStarted |
Subagent | Announces a subagent invocation under a subagentRunId, with a display name. Optionally a description, the enclosing parentSubagentRunId, and the parentToolCallId / parentMessageId that spawned it. |
SUBAGENT_FINISHED |
SubagentFinished |
Subagent | Closes the invocation. outcome is success or suspended — the latter naming the interruptIds the subagent owns — and absent reads as success. result mirrors RUN_FINISHED.result. |
SUBAGENT_ERROR |
SubagentError |
Subagent | The invocation failed: a message for a human and an optional machine-readable code. |
The 31 current types are 4 text, 5 tool, 3 state, 2 activity, 2 escape hatches, 5 lifecycle, 7 reasoning and 3 subagent. Five legacy thinking variants bring the Rust total to 36.
Attribution
Section titled “Attribution”Among the 31 current types, 24 carry an optional subagentRunId naming
the subagent that produced them: the text, tool, state, activity, reasoning and
step families, plus RAW and CUSTOM. An event without one belongs to the
parent agent. The seven current types without optional attribution are
RUN_STARTED, RUN_FINISHED, RUN_ERROR, MESSAGES_SNAPSHOT and the three
SUBAGENT_* lifecycle events, whose IDs name their subjects. The five legacy
THINKING_* variants cannot carry it either. EventType::is_attributable
reports this per type, and Event::subagent_run_id reads the tag.
Subagents is what to do with it.
On the wire
Section titled “On the wire”type is the tag and the payload is flat beside it:
use ag_ui::{Event, EventType};
fn main() { // Current protocol events plus five legacy receive-only variants. assert_eq!(EventType::ALL.len(), 36);
// The discriminator is the wire name, both ways. assert_eq!(EventType::TextMessageContent.as_str(), "TEXT_MESSAGE_CONTENT"); assert_eq!( "TEXT_MESSAGE_CONTENT".parse::<EventType>().unwrap(), EventType::TextMessageContent, );
let event = Event::text_message_content("msg-1", "Hello"); assert_eq!(event.event_type(), EventType::TextMessageContent); assert_eq!( serde_json::to_string(&event).unwrap(), r#"{"type":"TEXT_MESSAGE_CONTENT","messageId":"msg-1","delta":"Hello"}"#, );}An event type this build does not know fails to deserialize. That is deliberate: a frontend talking to a newer agent stops with an error naming the unknown type rather than quietly rendering three quarters of a conversation.
The THINKING_* family is deprecated
Section titled “The THINKING_* family is deprecated”AG-UI 1.0 excludes these five types. The client still parses them in older
streams, but current producers reject them and emit REASONING_* instead.
THINKING_TEXT_MESSAGE_CONTENT carried no message id, so a thinking block
could only ever have one message in flight.
The Rust variants and payload structs are marked #[deprecated]. ag-ui’s
own event module carries #![allow(deprecated)] — it has to name these types in
the union, in event_type() and in the factories, and warning at itself for
supporting historical input helps nobody. The suppression is local to that
module, so a consumer that names one still gets the warning at its own use site,
which is where the decision to keep using it is actually being made.
Event::is_deprecated answers the question at runtime, without a match:
use ag_ui::Event;
fn main() { let event: Event = serde_json::from_str(r#"{"type":"THINKING_END"}"#).unwrap();
assert_eq!(event.event_type().as_str(), "THINKING_END"); assert!(event.is_deprecated());
let current = Event::reasoning_end("msg-1"); assert!(!current.is_deprecated());}The *_CHUNK events
Section titled “The *_CHUNK events”Each TEXT_MESSAGE_CHUNK, TOOL_CALL_CHUNK, or
REASONING_MESSAGE_CHUNK either opens an item or continues one. Include the
item ID on the first chunk and preserve any opening metadata when repeating it.
Later chunks can omit the ID while that stream is open. The parent agent and
each subagent have separate lanes.
Opening a new item in a lane closes the previous chunk stream in that lane.
A run boundary or a MESSAGES_SNAPSHOT closes all lanes. A subagent’s
terminal event closes its lane. In this example the third chunk closes the
first message:
TEXT_MESSAGE_CHUNK { messageId: "msg-1", delta: "Hel" }TEXT_MESSAGE_CHUNK { delta: "lo" }TEXT_MESSAGE_CHUNK { messageId: "msg-2", delta: "Bye" } <- msg-1 just endedOn the consuming side that bookkeeping is ag_ui::client::chunks, which expands
a run of chunks back into the equivalent start/content/end triple before
anything else sees them. On the emitting side there is deliberately no
handle. The typestate emitters in ag_ui::server exist to make sure what you
open gets closed; a chunk has nothing to close, so wrapping one in an RAII
handle would only add a way to get it wrong. Emit them with ctx.emit — the
supported path, not a gap waiting for an API.
Interleaved parallel tool calls are the other case that belongs to ctx.emit.
Two open ToolCallHandles at once is a borrow-check error by design, so a
provider streaming args(a) args(b) args(a) end(a) end(b) cannot be mirrored
handle-for-call. Either accumulate each call and emit it whole once its
arguments are complete — the only mapping that cannot splice two calls’
arguments into each other — or emit the interleaving yourself. The ordering
verifier keys everything by id, so it accepts the interleaved stream; what it
will not let you do is close a call you never opened. See
Verification.
Protobuf support
Section titled “Protobuf support”Upstream generates events.proto from the AG-UI 1.0 JSON Schema. It covers all
31 current event types and omits the five retired THINKING_* events. The
SDK’s protobuf feature names the media type and provides a formatter stub.
Encoding returns Error::UnsupportedTransport, and HTTP content negotiation
does not select protobuf. Use SSE to stream events. See the
protobuf rustdoc and
issue #46.