This tutorial walks you through building an intelligent customer support system powered by multi-agent collaboration, showcasing AgentScope’s multi-agent orchestration capabilities. You will learn the following core features step by step:Documentation Index
Fetch the complete documentation index at: https://docs.agentscope.io/llms.txt
Use this file to discover all available pages before exploring further.
| Feature | Purpose |
|---|---|
| Structured Output | Structured output for routing decisions |
| MsgHub | Multi-agent message broadcasting and collaboration |
| Handoffs | Agent task delegation and dynamic dispatching |
| Hooks | Human-in-the-Loop review |
Environment Setup
Part 1: A Single Customer Support Agent
First, let’s create a basic customer support agent. This is the simplest scenario — a single agent handles all customer inquiries.Limitations of a Single Agent
While a single agent can handle basic conversations, it has obvious limitations:- Cannot handle all types of issues (technical, order, and complaint inquiries each require specialized knowledge)
- Complex problems require collaboration across multiple areas of expertise
- Lacks routing and dispatching mechanisms
Part 2: Intelligent Routing — Issue Classification
Use Structured Output to have the agent produce structured routing decisions. By defining the output format with a PydanticBaseModel,
the agent will return structured data according to the specified schema,
making it easy for downstream processing.
Tip: When using thestructured_modelparameter, it is recommended to set the model’sstreamtoFalseto ensure the integrity of structured output.
Advantages of Structured Output
- Output format is controllable, facilitating programmatic processing and downstream logic branching
- Includes meta-information like confidence scores, which can be used for fallback strategies
- Supports Pydantic model validation, automatically constraining data types and ranges
Structured output is stored in
response.metadata, while response.get_text_content() still returns the text content.Part 3: Multi-Agent Collaboration — MsgHub and Handoff
When a system involves multiple specialized agents, a mechanism is needed for them to collaborate efficiently. AgentScope provides multiple multi-agent collaboration patterns. Here we introduce two commonly used patterns:- MsgHub — Message broadcasting mode where all participants share context
- Handoff — Task delegation mode where the Orchestrator dynamically creates Workers to complete sub-tasks
3.1 MsgHub — Message Broadcasting Collaboration
MsgHub is AgentScope’s message broadcasting hub that allows multiple
agents to “hear” each other’s conversations within the same context,
forming a natural multi-party discussion.
- Agent calls within a MsgHub automatically broadcast messages
- Every agent can “hear” other agents’ replies
- This creates a natural multi-party conversation, ideal for scenarios that require collective discussion
3.2 Handoff — Task Delegation Pattern
Handoff (task handover/delegation) is another important multi-agent collaboration pattern. Unlike MsgHub’s “broadcast discussion”, Handoff uses an Orchestrator-Workers architecture:- An Orchestrator is responsible for decomposing tasks
- It dynamically creates Worker agents through tool calls
- Each Worker independently completes a sub-task and returns the result to the Orchestrator
- Dynamism: Workers can be created on-demand or pre-defined
- Context isolation: Workers do not share context with each other, reducing context pressure. The Orchestrator autonomously decides which tool to call (i.e., which specialized agent to delegate to).
3.3 MsgHub vs Handoff — Comparison and Selection Guide
Below is a comparison of the core differences between the two multi-agent collaboration patterns:| Feature | MsgHub (Message Broadcasting) | Handoff (Task Delegation) |
|---|---|---|
| Collaboration Mode | Equal discussion, multi-party conversation | Hierarchical division, task dispatching |
| Context Sharing | All participants share the complete conversation context | Workers only receive the task description assigned by the Orchestrator |
| Execution Flow | Requires explicit orchestration of call order | Orchestrator autonomously decides which Worker to invoke |
| Use Cases | Multi-party brainstorming, cross-referencing opinions, debate and discussion scenarios | Clear task decomposition, independent sub-task processing, parallelizable scenarios |
| Communication Overhead | High (each message is broadcast to all participants) | Low (communication only between Orchestrator and Workers) |
| Flexibility | Participants must be known in advance | New Worker types can be created dynamically |
- If the problem requires multiple experts to discuss and reference each other’s opinions → Use MsgHub
- If the problem can be decomposed into independent sub-tasks → Use Handoff
- In complex systems, both can be used together: the Orchestrator delegates sub-tasks via Handoff, while certain sub-tasks internally use MsgHub for multi-agent collaborative discussion
Part 4: Human-in-the-Loop — Using Hooks for Manual Review
In critical business scenarios, AI-generated responses may need manual review before being sent to the customer. AgentScope’s Hook mechanism provides an elegant way to implement Human-in-the-Loop without modifying the agent’s core code. Hooks are extension features of the agent’s core functions, allowing custom logic to be injected before and after execution:ReActAgent, there are more fine-grained hooks:
Tip: Hooks are implemented via metaclass and support inheritance. Subclasses automatically inherit Hook support from parent classes.The most common Human-in-the-Loop scenario is: after the agent generates a response, a human reviewer confirms whether it is satisfactory. If not, the agent is asked to regenerate.
Important: Hook function signatures are fixed:Where
- Pre-hook:
(self, kwargs) -> dict | None- Post-hook:
(self, kwargs, output) -> Any | Noneselfis the agent instance,kwargsis the function arguments dictionary, andoutputis the function return value. ReturningNonemeans no modification.
Part 5: Complete Customer Support System
Integrate all components — routing, MsgHub collaboration, Handoff delegation, and Human-in-the-Loop Hooks — to build a complete multi-agent customer support system.Run the Complete System
Next Steps
Congratulations on completing this tutorial! You have mastered AgentScope’s multi-agent orchestration capabilities. Next, you can explore:- Hooking Functions — Detailed usage of agent hooks, including Human-in-the-Loop patterns
- Orchestration — In-depth guide to routing strategies, MsgHub, and Orchestrator-Workers patterns