Pre-Made SendMessage Classes
Agency Swarm contains multiple commonly requested classes for communication flows. Currently, the following classes are available: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: