Events
Documentation for the events used in the Agent Wire Protocol SDK
Events
The Agent Wire 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.
Property | Type | Description |
---|---|---|
type | EventType | The type of event (discriminator field for the union) |
timestamp | number (optional) | Timestamp when the event was created |
rawEvent | any (optional) | Original event data if this event was transformed |
Lifecycle Events
These events represent the lifecycle of an agent run.
RunStartedEvent
Signals the start of an agent run.
Property | Type | Description |
---|---|---|
threadId | string | ID of the conversation thread |
runId | string | ID of the agent run |
RunFinishedEvent
Signals the successful completion of an agent run.
Property | Type | Description |
---|---|---|
threadId | string | ID of the conversation thread |
runId | string | ID of the agent run |
RunErrorEvent
Signals an error during an agent run.
Property | Type | Description |
---|---|---|
message | string | Error message |
code | string (optional) | Error code |
StepStartedEvent
Signals the start of a step within an agent run.
Property | Type | Description |
---|---|---|
stepName | string | Name of the step |
StepFinishedEvent
Signals the completion of a step within an agent run.
Property | Type | Description |
---|---|---|
stepName | string | Name of the step |
Text Message Events
These events represent the lifecycle of text messages in a conversation.
TextMessageStartEvent
Signals the start of a text message.
Property | Type | Description |
---|---|---|
messageId | string | Unique identifier for the message |
role | "assistant" | Role is always “assistant” |
TextMessageContentEvent
Represents a chunk of content in a streaming text message.
Property | Type | Description |
---|---|---|
messageId | string | Matches the ID from TextMessageStartEvent |
delta | string | Text content chunk (non-empty) |
TextMessageEndEvent
Signals the end of a text message.
Property | Type | Description |
---|---|---|
messageId | string | Matches the ID from TextMessageStartEvent |
Tool Call Events
These events represent the lifecycle of tool calls made by agents.
ToolCallStartEvent
Signals the start of a tool call.
Property | Type | Description |
---|---|---|
toolCallId | string | Unique identifier for the tool call |
toolCallName | string | Name of the tool being called |
parentMessageId | string (optional) | ID of the parent message |
ToolCallArgsEvent
Represents a chunk of argument data for a tool call.
Property | Type | Description |
---|---|---|
toolCallId | string | Matches the ID from ToolCallStartEvent |
delta | string | Argument data chunk |
ToolCallEndEvent
Signals the end of a tool call.
Property | Type | Description |
---|---|---|
toolCallId | string | Matches the ID from ToolCallStartEvent |
State Management Events
These events are used to manage agent state.
StateSnapshotEvent
Provides a complete snapshot of an agent’s state.
Property | Type | Description |
---|---|---|
snapshot | any | Complete state snapshot |
StateDeltaEvent
Provides a partial update to an agent’s state using JSON Patch.
Property | Type | Description |
---|---|---|
delta | any[] | Array of JSON Patch operations |
MessagesSnapshotEvent
Provides a snapshot of all messages in a conversation.
Property | Type | Description |
---|---|---|
messages | Message[] | Array of message objects |
Special Events
RawEvent
Used to pass through events from external systems.
Property | Type | Description |
---|---|---|
event | any | Original event data |
source | string (optional) | Source of the event |
CustomEvent
Used for application-specific custom events.
Property | Type | Description |
---|---|---|
name | string | Name of the custom event |
value | any | Value associated with the event |
Event Schemas
The SDK uses Zod schemas to validate events:
This allows for runtime validation of events and provides TypeScript type inference.