Orchestration Paradigms
AgentScope supports two primary orchestration paradigms for building multi-agent applications:Master-Worker Pattern
A central agent coordinates and delegates tasks to specialized workers. Best for task decomposition, routing, and hierarchical workflows.
Conversation / SOP / Workflow
Agents communicate peer-to-peer via
Msg objects. Best for multi-agent discussions, simulations, and message-driven pipelines.Master-Worker Pattern
In the master-worker pattern, a central agent (master) coordinates and delegates tasks to subordinate agents (workers). The master agent controls the execution flow and decides which worker should handle each task. Key characteristics:- Centralized control and decision-making
- Explicit task delegation and routing
- Workers typically don’t communicate directly with each other
- Clear hierarchical structure
- Task decomposition and parallel execution
- Specialized agents for different domains (e.g., code generation, web search, data analysis)
- Dynamic agent creation based on task requirements
- Complex workflows requiring orchestration logic
- Explicit routing: Use structured output or tool calls to route tasks to different agents
- Agent-as-tool: Wrap sub-agents as tool functions that the master agent can invoke
Conversation/SOP/Workflow Pattern
In the conversation pattern, agents communicate by broadcasting and passingMsg objects among themselves. There’s no central controller — agents interact peer-to-peer, and the execution flow emerges from their interactions.
Key characteristics:
- Decentralized communication
- Message-driven coordination
- Agents observe and respond to each other’s messages
- Flexible, dynamic interaction patterns
- Multi-agent discussions and debates
- Collaborative problem-solving
- Simulations with multiple autonomous entities
- Scenarios requiring peer-to-peer communication
- MsgHub: Automatically broadcasts messages among a group of agents
- Pipeline: Provides structured execution patterns (sequential, fanout)
Combining Both Paradigms
A single application can use both paradigms. For example, a master agent might orchestrate multiple conversation groups, or agents within a conversation might delegate specialized tasks to worker agents.Master-Worker Pattern
Explicit Routing
Route user queries to different downstream agents based on the query content. Approach 1: Structured OutputAgent-as-Tool
Wrap entire agents as tool functions to enable dynamic agent creation and delegation. The master agent invokes these tools to create and execute worker agents.- Dynamic worker creation based on task requirements
- Workers can have different capabilities and tools
- Master agent focuses on planning and coordination
- Workers are isolated and can run concurrently
Conversation/SOP/Workflow Pattern
MsgHub
MsgHub is an async context manager that automatically broadcasts messages among a group of agents:
MsgHub Parameter Reference
Methods:
How it works:
When entering the context,
MsgHub registers each participant as a subscriber of all other participants. When any participant generates a reply via __call__, the reply message is automatically sent to all other participants via their observe() method. On exit, all subscriptions are cleaned up.
Newly added participants (via
hub.add()) will not receive previous messages — only future ones.When
enable_auto_broadcast=False, MsgHub only broadcasts via the announcement parameter and the broadcast() method. This is useful when you want fine-grained control over message routing.Pipeline
Sequential Pipeline
Execute agents in order, passing output from one to the next.
Behavior: Equivalent to
msg = await alice(msg); msg = await bob(msg); msg = await charlie(msg).
Fanout Pipeline
Distribute the same input to multiple agents and collect responses.
Returns: A list of
Msg objects, one from each agent.
Stream Printing Messages
Convert an agent’s internal print messages into an async generator for streaming to a web UI or other consumers.
How messages are identified: Messages with the same
msg.id are considered the same message being updated (streaming). The content is accumulative (not delta), so each yield contains the latest full content.
ChatRoom
Internal forwarding loop: The
ChatRoom maintains a central asyncio.Queue. When a ServerEvent is received from any agent, it is forwarded to the outgoing_queue (for the frontend) and broadcast to all other agents (excluding the sender, identified by agent_id). When a ClientEvent is received, it is distributed to all agents via handle_input().
Formatter Reference
For an introduction to Chat vs MultiAgent formatters and how to choose one, see Model — Formatter.
Formatter Table
All formatters are importable from
agentscope.formatter.
Formatting Example
Example of howDashScopeMultiAgentFormatter transforms messages:
<history> section within a single user message, with each speaker’s name prefixed to their text.
Workflow Pattern Examples
This section provides practical code examples demonstrating how to implement common multi-agent orchestration patterns using both paradigms.Conversation/SOP Pattern Examples
User-Agent Conversation (Chatbot)
The simplest pattern — a user and an agent take turns:Multi-Agent Discussion
When more than two agents are involved, useMultiAgentFormatter (e.g., DashScopeMultiAgentFormatter) and MsgHub:
user/assistant roles.
Combined with MsgHub, a multi-agent discussion is simply:
Multi-Agent Debate
Multiple agents discuss a topic in rounds, with a moderator deciding when consensus is reached:Concurrent Agents
Useasyncio.gather() to run agents concurrently:
asyncio handles them efficiently).
Realtime Voice Chat Room
For realtime voice agent scenarios,ChatRoom orchestrates multiple RealtimeAgent instances sharing a session:
MsgHub (which works with text-based agents), ChatRoom handles ServerEvents and ClientEvents in the realtime voice pipeline. When one agent generates a response, ChatRoom forwards it both to the frontend and to other agents (excluding the sender).