Skip to main content
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:

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
Next, we’ll implement intelligent routing using Structured Output.

Part 2: Intelligent Routing — Issue Classification

Use Structured Output to have the agent produce structured routing decisions. By defining the output format with a Pydantic BaseModel, the agent will return structured data according to the specified schema, making it easy for downstream processing.
Tip: When using the structured_model parameter, it is recommended to set the model’s stream to False to 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:
  1. MsgHub — Message broadcasting mode where all participants share context
  2. Handoff — Task delegation mode where the Orchestrator dynamically creates Workers to complete sub-tasks
Below we implement both patterns and then provide a comparative analysis.

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
In AgentScope, Handoff is implemented by wrapping agent creation and invocation as tool functions — when the Orchestrator calls a tool, the tool function internally creates and runs a specialized Worker agent.
The core advantages of this pattern are:
  1. Dynamism: Workers can be created on-demand or pre-defined
  2. 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).
First, let’s define the tool functions that Workers will use:
Next, define the tool functions for creating each type of specialized Worker:
Now create the Orchestrator and register the Worker creation functions as tools:

3.3 MsgHub vs Handoff — Comparison and Selection Guide

Below is a comparison of the core differences between the two multi-agent collaboration patterns: Selection Guidelines:
  • 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:
For 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:
  • Pre-hook: (self, kwargs) -> dict | None
  • Post-hook: (self, kwargs, output) -> Any | None
Where self is the agent instance, kwargs is the function arguments dictionary, and output is the function return value. Returning None means 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