QueryMT Agent - Mesh Networking
Mesh networking enables QueryMT Agent to collaborate across multiple machines, allowing sessions to be shared, delegates to run remotely, and LLM calls to be routed to specific nodes.
Overview
Mesh networking uses the kameo actor framework with libp2p for peer-to-peer communication. This enables:
- Cross-machine sessions: Share sessions across multiple machines
- Remote agents: Access agents running on other machines
- Distributed computation: Run heavy tasks on specialized hardware
- Load balancing: Distribute work across multiple nodes
Architecture
flowchart LR
subgraph A["Machine A"]
AS[Agent Session]
AG[GPU Worker]
end
subgraph B["Machine B"]
BS[Agent Session]
BL[LLM Provider]
end
AS <-->|"Internet<br/>(libp2p Mesh)"| BS
Quick Start
Starting a Mesh Node
Connecting to a Mesh
Configuration
Basic Mesh Configuration
Discovery Methods
mDNS (Default)
Automatic discovery on local network:
- Pros: Zero-config, automatic
- Cons: Local network only, may miss peers on different subnets
Kademlia DHT
Distributed discovery across the internet:
- Pros: Cross-subnet, internet-wide
- Cons: Requires bootstrap nodes, more complex
Manual Peers
Explicit peer connections:
- Pros: Precise control, reliable
- Cons: Manual configuration required
Multiaddr Format
Mesh addresses use libp2p multiaddr format:
Examples
Remote Agents
Define agents that run on remote mesh nodes:
Remote Delegate
Delegates can run on remote nodes:
Behavior: - LLM calls are routed to the remote node - Tool execution happens locally on the planner node - Enables "remote model, local session" pattern
Session Management
Creating Remote Sessions
Listing Remote Nodes
Attaching Existing Sessions
Routing
Routing Table
The mesh maintains a routing table that maps agents to nodes:
Routing Snapshot
Use Cases
1. GPU-Accelerated Coding
flowchart LR
subgraph Local["Local Machine (CPU)"]
PA["Planner Agent<br/>(Lightweight)"]
LM[Local Model]
end
subgraph Remote["Remote Machine (GPU)"]
CA["Coder Agent<br/>(GPU-accelerated)"]
GM[GPU Model]
end
PA -->|"Delegates task"| CA
PA -->|"LLM calls<br/>(routed to GPU)"| GM
CA -->|"Fast model inference"| GM
Configuration:
2. Distributed Team Collaboration
flowchart TD
S1["Session 1<br/>(Feature A)"]
S2["Session 2<br/>(Feature B)"]
S3["Session 3<br/>(Feature C)"]
SS[("Shared State")]
S1 & S2 & S3 <--> SS
Benefits: - Share session state across team members - Collaborate on same codebase - Real-time synchronization
3. Load Distribution
flowchart LR
subgraph LB["Load Balancer Node"]
SR["Session Router<br/>- Distribute<br/>- Monitor"]
end
subgraph WN["Worker Nodes"]
W1["Worker 1<br/>(Handle Tasks)"]
W2["Worker 2<br/>(Handle Tasks)"]
end
SR --> W1 & W2
Configuration:
4. Specialized Hardware
flowchart LR
subgraph DM["Development Machine"]
DA[Development Agent]
end
subgraph SN["Specialized Nodes"]
GPU[GPU Worker]
TPU[TPU Worker]
FPGA[FPGA Worker]
end
DA --> GPU & TPU & FPGA
Security
Peer Authentication
Mesh nodes authenticate using libp2p's built-in peer ID system:
Firewall Configuration
Required ports for mesh networking:
| Direction | Port | Protocol | Purpose |
|---|---|---|---|
| Inbound | 9000 (default) | TCP | Mesh connections |
| Outbound | Any | TCP/UDP | Peer discovery |
Example firewall rules:
NAT Traversal
For nodes behind NAT:
- Port forwarding: Forward mesh port to internal node
- UPnP: Enable UPnP for automatic port forwarding
- Relay: Use libp2p relay servers
Monitoring
Node Status
Event Logging
Enable mesh logging:
Metrics
Key metrics to monitor:
- Connected peers: Number of active connections
- Latency: Round-trip time to peers
- Bandwidth: Data transfer rates
- Session count: Number of sessions per node
Troubleshooting
Cannot Connect to Peer
Symptoms: Mesh node shows no connected peers
Solutions: 1. Check firewall allows mesh port 2. Verify peer address is correct 3. Ensure peer is running and listening 4. Check NAT/firewall configuration
High Latency
Symptoms: Slow responses from remote agents
Solutions:
1. Check network bandwidth
2. Reduce mesh complexity (fewer peers)
3. Use closer geographic nodes
4. Increase request_timeout_secs
Peer Discovery Issues
Symptoms: Cannot find peers automatically
Solutions: 1. Try explicit peer configuration 2. Check mDNS is enabled on network 3. Verify firewall allows multicast 4. Use Kademlia for cross-subnet discovery
Session Attachment Fails
Symptoms: Cannot attach to remote session
Solutions: 1. Verify session exists on remote node 2. Check peer has correct permissions 3. Ensure mesh is properly configured 4. Review error logs for details
Best Practices
Network Configuration
- Use static IPs for mesh nodes
- Configure port forwarding for NAT environments
- Monitor bandwidth usage
- Use dedicated ports for mesh traffic
Node Organization
- Group by function: Separate planner and worker nodes
- Consider geography: Place nodes close to users
- Plan for redundancy: Multiple nodes for critical tasks
- Document topology: Keep track of node roles
Security
- Use strong peer IDs: Generate unique keys
- Limit peer access: Only allow known peers
- Monitor connections: Watch for unauthorized access
- Encrypt traffic: Use TLS where possible
Examples
Full Mesh Configuration
Command Line Examples
Related Documentation
- Delegation Guide - Remote delegation
- Configuration Guide - Mesh configuration
- API Reference - Mesh API types