Overview
When building multi-agent applications, you often need agents to communicate with each other. Without MsgHub, you would have to manually pass messages between agents:Core Features
- Automatic Broadcasting: Messages from any participant are automatically broadcast to all other participants
- Dynamic Participants: Add or remove agents during conversation
- Announcement Messages: Send initial messages when entering the hub
- Manual Broadcasting: Broadcast messages manually when needed
- Lifecycle Management: Automatic cleanup with try-with-resources
Basic Usage
Creating and Using MsgHub
Important: When using MsgHub, use DashScopeMultiAgentFormatter (or equivalent for other providers) instead of the standard formatter. This formatter properly handles messages from multiple agents with different names.
Lifecycle Methods
MsgHub follows an enter/exit lifecycle:close() is called automatically, which internally calls exit().
Dynamic Participant Management
You can add or remove participants during a conversation:Adding Participants
Removing Participants
Note: Newly added participants will NOT receive previous messages. They only receive messages from the point they join.
Manual Broadcasting
You can disable automatic broadcasting and manually control message distribution:Disabling Auto-Broadcast
Toggling Auto-Broadcast
You can toggle auto-broadcast mode during conversation:Broadcasting Multiple Messages
Reactive Programming Style
MsgHub supports fully reactive programming with Project Reactor:API Reference
Builder Methods
Instance Methods
Related Documentation
- Pipeline - Sequential and parallel agent execution
- Multi-Agent Debate - Debate workflow pattern