Skip to content

DevDuck Swarms: When Terminal Agents Unite 🦆🦆🦆

Published: January 12, 2025

What happens when you connect multiple DevDuck agents together? You get a swarm - a distributed network of AI agents that can collaborate, share context, and work on parallel tasks.

The Swarm Vision

graph TB
    subgraph "Your Machine"
        D1[DevDuck Terminal 1]
        D2[DevDuck Terminal 2]
    end

    subgraph "Remote Machine"
        D3[DevDuck Remote]
    end

    subgraph "Cloud"
        D4[DevDuck AWS]
        D5[DevDuck GCP]
    end

    D1 <-->|Zenoh| D2
    D1 <-->|Zenoh| D3
    D1 <-->|Zenoh| D4
    D1 <-->|Zenoh| D5
    D2 <-->|Zenoh| D3
    D3 <-->|Zenoh| D4
    D4 <-->|Zenoh| D5

    style D1 fill:#f9f,stroke:#333,stroke-width:4px

Swarm Capabilities

  • 🔍 Auto-Discovery: Agents find each other via multicast
  • 📡 Broadcast: Send commands to ALL agents at once
  • 🎯 Direct Messaging: Target specific peers
  • 🧠 Shared Context: Dynamic context injection
  • 🔄 Load Distribution: Parallel task execution

How It Works: Zenoh Networking

sequenceDiagram
    participant D1 as DevDuck 1
    participant Z as Zenoh Network
    participant D2 as DevDuck 2
    participant D3 as DevDuck 3

    D1->>Z: zenoh_peer(action="start")
    D2->>Z: zenoh_peer(action="start")
    D3->>Z: zenoh_peer(action="start")

    Note over Z: Multicast Discovery<br/>224.0.0.224:7446

    Z->>D1: Peer discovered: D2, D3
    Z->>D2: Peer discovered: D1, D3
    Z->>D3: Peer discovered: D1, D2

    D1->>Z: broadcast("git pull && npm install")
    Z->>D2: Execute command
    Z->>D3: Execute command
    D2->>Z: Result
    D3->>Z: Result
    Z->>D1: Aggregated results

Starting a Swarm

Terminal 1:

$ devduck
🦆 DevDuck
🦆 ✓ Zenoh peer: host1-abc123

Terminal 2:

$ devduck  
🦆 DevDuck
🦆 ✓ Zenoh peer: host2-def456

They automatically discover each other!

Broadcasting Commands

# In any DevDuck terminal
🦆 broadcast 'git pull && npm test' to all peers

# Output shows results from ALL connected agents

Architecture: The Zenoh Peer Tool

@tool
def zenoh_peer(
    action: str,  # start, stop, status, list_peers, broadcast, send
    message: str = "",
    peer_id: str = "",
    connect: str = "",   # Remote endpoint
    listen: str = "",    # Accept connections
) -> dict:
flowchart LR
    subgraph "Local Network"
        A[DevDuck A] <-->|Multicast| B[DevDuck B]
        B <-->|Multicast| C[DevDuck C]
    end

    subgraph "Remote Network"
        D[DevDuck D] <-->|TCP| E[DevDuck E]
    end

    C <-->|tcp/remote:7447| D

    style A fill:#bbf
    style B fill:#bbf
    style C fill:#bbf
    style D fill:#bfb
    style E fill:#bfb

Cross-Network Connections

# On home machine - listen for connections
$ ZENOH_LISTEN="tcp/0.0.0.0:7447" devduck

# On work machine - connect to home
$ ZENOH_CONNECT="tcp/home.example.com:7447" devduck

Use Cases

1. Distributed Development

graph LR
    Dev[Developer] -->|Query| D1[DevDuck: Frontend]
    D1 -->|broadcast| D2[DevDuck: Backend]
    D1 -->|broadcast| D3[DevDuck: Tests]

    D2 -->|Result| D1
    D3 -->|Result| D1
    D1 -->|Aggregated| Dev
# "Deploy the app"
🦆 broadcast 'build and deploy your component'

# DevDuck Frontend: npm run build && vercel deploy
# DevDuck Backend: docker build && kubectl apply
# DevDuck Tests: npm test && report results

2. Research Parallelization

# Main DevDuck coordinates research
🦆 send to researcher-1: "analyze user authentication patterns"
🦆 send to researcher-2: "analyze database performance"
🦆 send to researcher-3: "analyze API response times"

# Results stream back and aggregate

3. Code Review Swarm

sequenceDiagram
    participant Lead as Lead DevDuck
    participant Security as Security Duck
    participant Perf as Performance Duck
    participant Style as Style Duck

    Lead->>Security: Review PR #42 for security
    Lead->>Perf: Review PR #42 for performance
    Lead->>Style: Review PR #42 for code style

    Security-->>Lead: XSS vulnerability in line 42
    Perf-->>Lead: N+1 query in user fetch
    Style-->>Lead: Inconsistent naming

    Lead->>Lead: Compile review

Dynamic Context Injection

DevDuck automatically injects swarm state into every query:

## Zenoh Network Status:
- **My Instance ID**: host1-abc123
- **Connected Peers**: 2

### Active Peers:
- `host2-def456` (laptop) - model: claude-sonnet, seen 5s ago
- `host3-ghi789` (server) - model: claude-opus, seen 12s ago

**Use**: `zenoh_peer(action='broadcast', message='...')` to send to all

This means the agent knows about other agents and can orchestrate them.

Ambient Mode + Swarm

stateDiagram-v2
    [*] --> Idle: User inactive
    Idle --> AmbientThinking: 30s idle
    AmbientThinking --> BroadcastTask: Complex task
    BroadcastTask --> PeerExecution: Parallel
    PeerExecution --> AggregateResults
    AggregateResults --> StoreResults
    StoreResults --> Idle

    Idle --> UserQuery: User returns
    UserQuery --> InjectResults: Ambient results ready
    InjectResults --> Response

When you're idle, DevDuck can: 1. Start ambient thinking 2. Delegate sub-tasks to peers 3. Aggregate results 4. Inject into your next query

Configuration

# Enable Zenoh by default
export DEVDUCK_ENABLE_ZENOH=true

# Auto-connect to specific peers
export ZENOH_CONNECT="tcp/peer1:7447,tcp/peer2:7447"

# Listen for incoming connections
export ZENOH_LISTEN="tcp/0.0.0.0:7447"

Swarm Patterns

Hub & Spoke

graph TD
    Hub[Hub DevDuck] --> S1[Worker 1]
    Hub --> S2[Worker 2]
    Hub --> S3[Worker 3]
    Hub --> S4[Worker 4]

    style Hub fill:#f9f,stroke:#333,stroke-width:4px

One coordinator distributes tasks to workers.

Mesh Network

graph TD
    A[DevDuck A] <--> B[DevDuck B]
    B <--> C[DevDuck C]
    C <--> D[DevDuck D]
    D <--> A
    A <--> C
    B <--> D

Every agent can talk to every other agent.

Hierarchical

graph TD
    Lead[Lead Agent] --> Team1Lead[Team 1 Lead]
    Lead --> Team2Lead[Team 2 Lead]
    Team1Lead --> W1[Worker 1]
    Team1Lead --> W2[Worker 2]
    Team2Lead --> W3[Worker 3]
    Team2Lead --> W4[Worker 4]

Agents organized in teams with leads.

Security Considerations

Swarm Security

  • Zenoh multicast only works on local network by default
  • Remote connections require explicit configuration
  • No built-in authentication (yet)
  • Use VPN for sensitive cross-network swarms

Getting Started

# Terminal 1: Start first agent
$ devduck

# Terminal 2: Start second agent (auto-discovers first)
$ devduck

# In either terminal
🦆 list peers
# Shows: host2-xxx123

🦆 broadcast "pwd" to all peers
# Shows current directory from both agents

🦆 send to host2-xxx123: "what files are here?"
# Queries specific peer

One duck is helpful. A swarm is unstoppable. 🦆🦆🦆