- 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
An instance of theMsg class in AgentScope contains a complete conversation turn — a user input, or a complete assistant response, organized through different types of content blocks (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:
msg.role=="user"messages can only containTextBlockandDataBlock;msg.role=="system"messages can only containTextBlock;msg.role=="assistant"messages can contain all block types.
TextBlock
Text data
TextBlock
Text data
ThinkingBlock
The model's reasoning process
ThinkingBlock
The model's reasoning process
This content block allows passing through custom metadata defined by the model provider (such as the
signature in Anthropic models, etc.).DataBlock
Multimodal data (such as image, audio, video, etc.)
DataBlock
Multimodal data (such as image, audio, video, etc.)
Data Source Configuration:
Base64Source:type: Fixed as"base64".data: Base64-encoded binary data.media_type: Media type (e.g.,"image/png","audio/mpeg","video/mp4", etc.).
URLSource:type: Fixed as"url".url: A valid URI/URL string satisfying the RFC 3986 standard.media_type: Media type (e.g.,"image/png","audio/wav", etc.).
HintBlock
Hint information used to guide the LLM
HintBlock
Hint information used to guide the LLM
When finally passed to the LLM API,
HintBlock is also converted to a standard user message (User message).To avoid confusion with user inputs, it is recommended to use XML tags (e.g., <system-reminder>...</system-reminder>) to wrap the hint content.ToolCallBlock
Data and state of a tool call
ToolCallBlock
Data and state of a tool call
ToolResultBlock
Data and state of tool execution results
ToolResultBlock
Data and state of tool execution results
The
id of a ToolResultBlock must match the id of the launching ToolCallBlock. Supports multimodal data.Create Messages
AgentScope provides three shortcut methods to constructMsg objects to avoid repeatedly setting the role parameter, and supports building TextBlocks from strings:
When the
content parameter is a 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
AgentScope provides TypeScript versions of messages and event primitives, so frontends can use the exact sameappendEvent API to reconstruct messages from the event stream.
Install the TypeScript version of AgentScope:
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