- Message — the unit of inter-agent communication and persistence. Each
Msgrepresents a complete conversation turn that is stored in context and exchanged between agents. - Event — the unit of frontend interaction and streaming. Events carry incremental progress updates (text tokens, tool call fragments, permission requests) and drive real-time UIs and human-in-the-loop workflows.
reply call accumulates into exactly one assistant Msg. This guarantees that the complete message state is always recoverable from its event stream.
Message
AMsg represents a single turn in a conversation — a user input, an assistant response, or a system instruction, carrying structured content as a list of typed blocks.
Structure
TheMsg class has the following core fields:
Content Blocks
Message content is composed of typed blocks. Each block represents a distinct piece of information:Role constraints are enforced at construction:
user messages can only contain TextBlock and DataBlock; system messages can only contain TextBlock; assistant messages can contain all block types.Create Messages
AgentScope provides three shortcut factory functions for quickly creating messages with the correct role, without manually specifyingrole or wrapping content into blocks:
When
content is a plain string, it is automatically wrapped into a TextBlock.
Access Content
Msg provides helper methods to extract specific block types:
Event
Events are the streaming counterpart of messages. While the agent executes, it yields a sequence ofAgentEvent objects that represent incremental progress — text tokens arriving, tool calls being constructed, results streaming back. Each event is lightweight and self-contained.
Event Lifecycle
Every event carries areply_id that links it to the message being constructed. Within a reply, block_id or tool_call_id identifies which content block an event belongs to. Events follow a start → delta → end pattern for each content block:
All events within the same reply share the same reply_id. Within a reply, use block_id to correlate text/thinking/data block events, and tool_call_id to correlate tool call and tool result events.
Event Types
All events inherit fromEventBase which provides common fields:
Events are grouped by category below. Every event also carries a
reply_id field (except where noted) that links it to the message being constructed.
Lifecycle Events
Lifecycle Events
ReplyStartEvent — Agent begins a new reply.
ReplyEndEvent — Agent finishes the reply.
ExceedMaxItersEvent — Agent reached the maximum reasoning-acting iterations.
Text Streaming Events
Text Streaming Events
TextBlockStartEvent — A new text block begins.
TextBlockDeltaEvent — Incremental text content arrives.
TextBlockEndEvent — The text block is complete.
Thinking Streaming Events
Thinking Streaming Events
ThinkingBlockStartEvent — A new thinking block begins.
ThinkingBlockDeltaEvent — Incremental thinking content arrives.
ThinkingBlockEndEvent — The thinking block is complete.
Data Streaming Events
Data Streaming Events
DataBlockStartEvent — A new data block begins (image, audio, etc.).
DataBlockDeltaEvent — Incremental binary data arrives.
DataBlockEndEvent — The data block is complete.
Tool Call Streaming Events
Tool Call Streaming Events
ToolCallStartEvent — The agent begins a tool call.
ToolCallDeltaEvent — Incremental tool call input arrives.
ToolCallEndEvent — The tool call input is complete.
Tool Result Streaming Events
Tool Result Streaming Events
ToolResultStartEvent — Tool execution begins.
ToolResultTextDeltaEvent — Incremental text output from the tool.
ToolResultDataDeltaEvent — Binary data output from the tool.
ToolResultEndEvent — Tool execution is complete.
Model Call Events
Model Call Events
ModelCallStartEvent — A model API call begins.
ModelCallEndEvent — A model API call completes.
Human-in-the-Loop Events
Human-in-the-Loop Events
RequireUserConfirmEvent — Agent pauses for user confirmation.
RequireExternalExecutionEvent — Agent pauses for external execution.
UserConfirmResultEvent — User provides confirmation results (input event).
ExternalExecutionResultEvent — External system provides execution results (input event).
One-shot Events
One-shot Events
Unlike text / thinking / data / tool blocks, these events do not follow the start → delta → end pattern. The full payload arrives in a single event because it is known up-front rather than streamed.HintBlockEvent — A
HintBlock is injected into the agent’s context (e.g. a scheduled-task trigger, a team message, a result returned by an offloaded background tool).CustomEvent — Generic extensible event used by service-layer middleware to notify subscribers about state changes (task progress, team membership, permission updates, …) without polluting the core agent event enum.
Reconstruct Messages from Events
Events and messages are not independent — they are two views of the same data. Every event produced byreply_stream can be applied to a Msg via append_event(), reconstructing the complete message incrementally. This guarantees that the final message state is fully recoverable from the event stream alone.
append_event method handles all event types:
TypeScript Support
A TypeScript version of the message and event primitives is available on npm, so frontends can reconstruct messages from the event stream with the sameappendEvent API:
Example: Streaming UI
A typical pattern for building a streaming interface:Further Reading
Agent
How the agent produces events and messages in the ReAct loop
Context
How messages are stored, compressed, and offloaded