Package com.tnsai.protocols


package com.tnsai.protocols
Agent communication protocols for multi-agent coordination.

This package provides various communication patterns for agents to exchange messages and coordinate actions. Protocols define how agents discover each other and exchange information.

Communication Patterns

 ┌─────────────────────────────────────────────────────────────┐
 │                    Communication Patterns                    │
 ├─────────────────────────────────────────────────────────────┤
 │                                                              │
 │  Direct (Point-to-Point)        Broadcast (One-to-Many)     │
 │  ─────────────────────          ────────────────────────     │
 │    Agent A ──► Agent B            Agent A ──┬──► Agent B    │
 │                                             ├──► Agent C    │
 │                                             └──► Agent D    │
 │                                                              │
 │  PubSub (Topic-Based)           Request-Reply               │
 │  ─────────────────────          ─────────────────            │
 │    Publishers ──► Topic         Agent A ──► Agent B         │
 │                    │                    ◄────────           │
 │    Subscribers ◄───┘            (bidirectional)             │
 │                                                              │
 └─────────────────────────────────────────────────────────────┘
 

Available Protocols

ProtocolPatternUse Case
DirectProtocolPoint-to-pointTargeted agent communication
BroadcastProtocolOne-to-manyAnnouncements, notifications
PubSubProtocolTopic-basedEvent-driven architectures
RequestReplyProtocolBidirectionalQueries, RPC-style calls

Usage Example


 // Protocol Manager coordinates all protocols
 ProtocolManager manager = new ProtocolManager();

 // Register agents
 manager.register(researchAgent);
 manager.register(writerAgent);

 // Direct communication
 manager.send("writer-agent", "Please write about: " + topic);

 // Broadcast to all
 manager.broadcast("System maintenance in 5 minutes");

 // PubSub pattern
 manager.subscribe("news-topic", newsAgent);
 manager.publish("news-topic", "Breaking news: ...");

 // Request-Reply
 String response = manager.request("research-agent", "Find papers on AI");
 

Protocol Selection Guide

  • Direct: When you know the specific recipient
  • Broadcast: For system-wide announcements
  • PubSub: For decoupled, event-driven systems
  • Request-Reply: When you need a response

Transport Layer

Protocols are transport-agnostic. See tnsai-distributed-redis module for Redis-based distributed transport.

Since:
0.0.2
See Also:
  • Agent