Class AgentCommunicationManager

java.lang.Object
com.tnsai.communication.AgentCommunicationManager

public class AgentCommunicationManager extends Object
Central hub for routing messages between agents. Thread-safe implementation for multi-agent systems. Uses CommunicationTransport abstraction to support both local and distributed messaging.
  • Constructor Details

    • AgentCommunicationManager

      public AgentCommunicationManager()
    • AgentCommunicationManager

      public AgentCommunicationManager(CommunicationTransport transport)
  • Method Details

    • registerAgent

      public void registerAgent(AgentCommunicationManager.MessageReceiver agent)
      Registers an agent with the communication manager.
      Parameters:
      agent - The agent to register
      Throws:
      IllegalArgumentException - if agent is null
    • unregisterAgent

      public void unregisterAgent(String agentId)
      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

      public List<AgentMessage> getMessageHistory(String agentId)
      Gets all messages involving a specific agent (sent or received). Note: Only returns messages tracked by this local manager instance.
    • getConversation

      public List<AgentMessage> getConversation(String agentId1, String agentId2)
      Gets the conversation between two agents.
    • getThread

      public List<AgentMessage> getThread(String messageId)
      Gets a message thread (original message and all replies).
    • getRegisteredAgents

      public Set<String> 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.