Multi-agent communication is the core functionality of any multi-agent system. Unlike all other frameworks, Agency Swarm not only allows you to define communication flows in any way you want (uniform communication flows), but also to configure the underlying logic for this feature. This means that you can create entirely new types of communication or adjust it to your own needs. Below you will find a guide on how to do all this, along with some common examples.Documentation Index
Fetch the complete documentation index at: https://agency-swarm.ai/llms.txt
Use this file to discover all available pages before exploring further.
Pre-Made SendMessage Classes
Agency Swarm contains multiple commonly requested classes for communication flows. Currently, the following classes are available:| Class Name | Description | When to Use | Code Link |
|---|---|---|---|
SendMessage (default) | This is the default class for sending messages to other agents. It uses synchronous communication with basic COT (Chain of Thought) prompting and allows agents to relay files and modify system instructions for each other. | Suitable for most use cases. Balances speed and functionality. | link |
Handoff | Enables unidirectional transfer of control to a specialized agent. When a handoff occurs, the receiving agent takes over the interaction and continues the conversation. (SendMessageHandoff is deprecated.) | Use for routing queries to specialized agents or sequential workflows where control should transfer completely. | link |
Customizing Communication Flows
To select your own custom send message tool, simply provide it as the last argument to the communication flow tuple.Handoff tool will be used specifically for ceo -> worker communication and nowhere else. If there were other agents in the agency connected to ceo, they would be using regular SendMessage for agent-to-agent conversations.
Creating Your Own Unique Communication Flows
To create your own communication flow, you will first need to extend theFunctionTool class from the agents SDK. The SendMessage class is built on top of FunctionTool, providing a flexible foundation for creating custom communication patterns tailored to your specific needs.
Custom SendMessage Class
To customize SendMessage parameters, extend theSendMessage class and declare extra fields directly as class-level annotations with Field():
Key Components
In general, allSendMessage tools have the following components:
- FunctionTool Base: Extends the
FunctionToolclass from the agents SDK, providing async execution and standardized tool interfaces. - Dynamic Initialization: Tools are created dynamically for specific sender->recipient pairs with custom parameter schemas.
- JSON Schema: Parameters are defined using JSON schema for validation and type safety.
- Async Communication: Uses
async/awaitfor non-blocking communication between agents.
SendMessage tools, extend FunctionTool and implement the on_invoke_tool method with your custom communication logic.
Custom Handoff Class
By default, whenever a handoff occurs, prior to transferring the chat, a special system message will be added to the chat history to remind the recipient agent that a handoff has happened. This helps to reduce the amount of hallucinations and agent confusion whenever a chat transfer happens. You can customize the reminder message or disable it entirely by defining a custom Handoff class as follows (seeadd_reminder and handoff_reminder parameters). Set handoff_reminder on the agent that receives the handoff so the message appears in its context: