Interface NetworkMesh
- All Superinterfaces:
com.tnsai.agents.groups.AgentGroup
- All Known Implementing Classes:
DefaultNetworkMesh
public interface NetworkMesh
extends com.tnsai.agents.groups.AgentGroup
A mesh network organization with peer-to-peer agent connections.
NetworkMesh extends AgentGroup with peer connection management, message routing through the mesh, and topology-based communication.
Key Features
- Peer connections: Dynamic connect/disconnect between agents
- Message routing: Route messages via shortest path
- Topology: Support for full mesh, partial mesh, ring, and star
- Broadcast: Send messages to all connected peers
Usage Example
NetworkMesh mesh = NetworkMesh.builder()
.name("Agent Network")
.topology(Topology.FULL_MESH)
.add(agent1, agent2, agent3)
.build();
mesh.start();
mesh.routeMessage("agent1", "agent3", "Hello!");
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionbroadcastMessage(String message) Broadcasts a message to all agents in the network.static NetworkMeshBuilderbuilder()Creates a new NetworkMesh builder.voidconnectPeers(String agentA, String agentB) Connects two peers bidirectionally.voiddisconnectPeers(String agentA, String agentB) Disconnects two peers bidirectionally.findShortestPath(String from, String to) Finds the shortest path between two agents.getConnectedPeers(String agentId) Returns the directly connected peers of an agent.Returns the connection manager.Returns the network topology.routeMessage(String from, String to, String message) Routes a message from one agent to another through the mesh.Methods inherited from interface com.tnsai.agents.groups.AgentGroup
addLifecycleListener, addMember, addMembershipListener, assignTask, broadcast, broadcast, dissolve, electLeader, electLeader, findMembers, getDescription, getEventBus, getId, getLeader, getLifecycle, getMember, getMemberCount, getMembers, getMembershipManager, getMetrics, getName, getPolicy, hasMember, isActive, isDissolved, removeLifecycleListener, removeMember, removeMembershipListener, scatter, scatter, scatterAsync, setPolicy, start, stop, stopNow
-
Method Details
-
getTopology
Topology getTopology()Returns the network topology.- Returns:
- topology type
-
connectPeers
Connects two peers bidirectionally.- Parameters:
agentA- first agent IDagentB- second agent ID- Throws:
IllegalArgumentException- if either agent is not a member
-
disconnectPeers
Disconnects two peers bidirectionally.- Parameters:
agentA- first agent IDagentB- second agent ID
-
getConnectedPeers
Returns the directly connected peers of an agent.- Parameters:
agentId- agent ID- Returns:
- set of connected peer IDs
-
findShortestPath
Finds the shortest path between two agents.- Parameters:
from- source agent IDto- target agent ID- Returns:
- list of agent IDs forming the path, or empty if no path
-
routeMessage
Routes a message from one agent to another through the mesh.- Parameters:
from- source agent IDto- target agent IDmessage- message content- Returns:
- routing result
-
broadcastMessage
Broadcasts a message to all agents in the network.- Parameters:
message- message content- Returns:
- broadcast result with all responses
-
getConnections
DynamicConnections getConnections()Returns the connection manager.- Returns:
- dynamic connections
-
builder
Creates a new NetworkMesh builder.- Returns:
- builder
-