ab ovo
This commit is contained in:
162
examples/a2a/README.md
Normal file
162
examples/a2a/README.md
Normal file
@@ -0,0 +1,162 @@
|
||||
# A2A: Agent-to-Agent Communication over P2P
|
||||
|
||||
Decentralized LLM agent communication using OpenAI-compatible protocol over encrypted P2P network.
|
||||
|
||||
## Features
|
||||
|
||||
- **OpenAI API Compatible**: Works with Ollama, OpenAI, and any compatible provider
|
||||
- **End-to-End Encrypted**: Noise Protocol (same as WireGuard)
|
||||
- **NAT Traversal**: STUN/TURN/hole punching built-in
|
||||
- **Zero Central Server**: True peer-to-peer, no intermediaries
|
||||
- **DHT Discovery**: Agents discover each other via Kademlia DHT
|
||||
|
||||
## Quick Start
|
||||
|
||||
### 1. Start Ollama
|
||||
|
||||
```bash
|
||||
# Install Ollama: https://ollama.ai
|
||||
ollama pull deepseek-v3.1:671b-cloud # or any model you have
|
||||
ollama serve # Runs on http://localhost:11434
|
||||
```
|
||||
zig build run-a2a-agent -- --port 9001 --model deepseek-v3.1:671b-cloud --connect 127.0.0.1:9000
|
||||
### 2. Start LLM Agent
|
||||
|
||||
```bash
|
||||
# Terminal 1: Start an LLM agent that wraps Ollama
|
||||
zig build run-llm-agent -- --port 9000
|
||||
# Default model: deepseek-v3.1:671b-cloud (can override with --model)
|
||||
```
|
||||
|
||||
### 3. Connect Client
|
||||
|
||||
```bash
|
||||
# Terminal 2: Send a message
|
||||
zig build run-client-agent -- --connect 127.0.0.1:9000 --message "What is 2+2?"
|
||||
```
|
||||
|
||||
## Architecture
|
||||
|
||||
```
|
||||
┌─────────────────┐ P2P (Encrypted) ┌─────────────────┐
|
||||
│ Client Agent │◄──────────────────────────────►│ LLM Agent │
|
||||
│ │ Noise Protocol + DHT │ │
|
||||
│ - Chat REPL │ │ - Ollama API │
|
||||
│ - Multi-agent │ │ - OpenAI API │
|
||||
└─────────────────┘ └─────────────────┘
|
||||
│
|
||||
▼
|
||||
┌───────────────┐
|
||||
│ Ollama │
|
||||
│ llama3.2 │
|
||||
│ mistral │
|
||||
│ codellama │
|
||||
└───────────────┘
|
||||
```
|
||||
|
||||
## Protocol
|
||||
|
||||
### Request (OpenAI-compatible)
|
||||
```json
|
||||
{
|
||||
"request_id": "a1b2c3d4...",
|
||||
"model": "llama3.2",
|
||||
"capability": "chat",
|
||||
"temperature": 0.7,
|
||||
"messages": [
|
||||
{"role": "system", "content": "You are helpful."},
|
||||
{"role": "user", "content": "Hello!"}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
### Response
|
||||
```json
|
||||
{
|
||||
"request_id": "a1b2c3d4...",
|
||||
"success": true,
|
||||
"model": "llama3.2",
|
||||
"content": "Hello! How can I help you today?",
|
||||
"agent_id": "peer_id_hex...",
|
||||
"tokens_used": 42
|
||||
}
|
||||
```
|
||||
|
||||
## Multi-Agent Setup
|
||||
|
||||
Run multiple specialized agents:
|
||||
|
||||
```bash
|
||||
# Terminal 1: General chat agent
|
||||
zig build run-llm-agent -- --port 9000 --model llama3.2 --capability chat
|
||||
|
||||
# Terminal 2: Code agent
|
||||
zig build run-llm-agent -- --port 9001 --model codellama --capability code
|
||||
|
||||
# Terminal 3: Summarization agent
|
||||
zig build run-llm-agent -- --port 9002 --model mistral --capability summarize
|
||||
```
|
||||
|
||||
Connect to any:
|
||||
|
||||
```bash
|
||||
zig build run-client-agent -- --connect 127.0.0.1:9001 --model codellama
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
### LLM Agent Options
|
||||
|
||||
| Option | Default | Description |
|
||||
|--------|---------|-------------|
|
||||
| `--port` | 9000 | P2P listen port |
|
||||
| `--model` | llama3.2 | Default LLM model |
|
||||
| `--ollama-url` | http://localhost:11434 | Ollama API endpoint |
|
||||
| `--capability` | chat | Agent capability name |
|
||||
| `--bootstrap` | - | Bootstrap peer address |
|
||||
|
||||
### Client Options
|
||||
|
||||
| Option | Default | Description |
|
||||
|--------|---------|-------------|
|
||||
| `--connect` | (required) | LLM agent address |
|
||||
| `--port` | 9100 | Our listen port |
|
||||
| `--model` | llama3.2 | Model to request |
|
||||
| `--message` | - | Single message (non-interactive) |
|
||||
| `--system` | "You are helpful..." | System prompt |
|
||||
|
||||
## Security
|
||||
|
||||
- **Encryption**: ChaCha20-Poly1305 (via Noise Protocol)
|
||||
- **Authentication**: Mutual peer authentication
|
||||
- **Key Exchange**: X25519 ECDH
|
||||
- **DoS Protection**: Cookie challenge + rate limiting
|
||||
|
||||
All traffic is encrypted end-to-end. No plaintext messages on the wire.
|
||||
|
||||
## Use Cases
|
||||
|
||||
1. **Private LLM Network**: Run LLMs on-premise, access from anywhere
|
||||
2. **Multi-Agent Systems**: Specialized agents collaborate over P2P
|
||||
3. **Federated Inference**: Distribute load across multiple LLM servers
|
||||
4. **Edge AI**: LLM agents at the edge, discovered via DHT
|
||||
5. **Censorship Resistance**: No central server to block
|
||||
|
||||
## Comparison
|
||||
|
||||
| Feature | A2A (zig-p2p) | OpenAI API | Ollama Direct |
|
||||
|---------|---------------|------------|---------------|
|
||||
| Decentralized | ✅ | ❌ | ❌ |
|
||||
| E2E Encrypted | ✅ | TLS only | ❌ |
|
||||
| NAT Traversal | ✅ | N/A | ❌ |
|
||||
| Multi-Agent | ✅ | ❌ | ❌ |
|
||||
| Discovery | DHT | N/A | Manual |
|
||||
| Dependencies | 0 | SDK | None |
|
||||
|
||||
## Future Enhancements
|
||||
|
||||
- [ ] Agent capability negotiation
|
||||
- [ ] Load balancing across agents
|
||||
- [ ] Streaming responses
|
||||
- [ ] Tool use / function calling
|
||||
- [ ] Agent-to-agent delegation
|
||||
Reference in New Issue
Block a user