Package com.tnsai.communication
Class AgentCommunicationManager
java.lang.Object
com.tnsai.communication.AgentCommunicationManager
Central hub for routing messages between agents.
Thread-safe implementation for multi-agent systems.
Uses CommunicationTransport abstraction to support both local and distributed messaging.
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbroadcastMessage(String senderId, MessageTypeMarker messageType, Map<String, Object> content) Broadcasts a message to all agents.voidClears all message history (useful for testing).getConversation(String agentId1, String agentId2) Gets the conversation between two agents.intGets the total number of messages in history.getMessageHistory(String agentId) Gets all messages involving a specific agent (sent or received).Gets all locally known registered agent IDs.Gets a message thread (original message and all replies).voidRegisters an agent with the communication manager.sendMessage(String senderId, String receiverId, MessageTypeMarker messageType, Map<String, Object> content) Sends a message from one agent to another.voidshutdown()Shuts down the underlying transport.voidunregisterAgent(String agentId) Unregisters an agent from the communication manager.
-
Constructor Details
-
AgentCommunicationManager
public AgentCommunicationManager() -
AgentCommunicationManager
-
-
Method Details
-
registerAgent
Registers an agent with the communication manager.- Parameters:
agent- The agent to register- Throws:
IllegalArgumentException- if agent is null
-
unregisterAgent
Unregisters an agent from the communication manager. -
sendMessage
public AgentMessage sendMessage(String senderId, String receiverId, MessageTypeMarker messageType, Map<String, Object> content) Sends a message from one agent to another. The message is automatically routed to the receiver. -
broadcastMessage
public AgentMessage broadcastMessage(String senderId, MessageTypeMarker messageType, Map<String, Object> content) Broadcasts a message to all agents. -
getMessageHistory
Gets all messages involving a specific agent (sent or received). Note: Only returns messages tracked by this local manager instance. -
getConversation
Gets the conversation between two agents. -
getThread
Gets a message thread (original message and all replies). -
getRegisteredAgents
Gets all locally known registered agent IDs. -
getMessageCount
public int getMessageCount()Gets the total number of messages in history. -
clearHistory
public void clearHistory()Clears all message history (useful for testing). -
shutdown
public void shutdown()Shuts down the underlying transport.
-