Swarm Intelligence
Swarm intelligence enables agents to share knowledge and collaborate through a shared memory system.
Overview
┌─────────────────────────────────────────────────────┐
│ Swarm Memory │
│ (~/.moxxy/swarm.db) │
├─────────────────────────────────────────────────────┤
│ │
│ ┌─────────┐ ┌─────────┐ ┌─────────┐ │
│ │ Agent A │ │ Agent B │ │ Agent C │ │
│ │ │ │ │ │ │ │
│ │ [WRITE] │ │ [READ] │ │ [READ] │ │
│ └────┬────┘ └────┬────┘ └────┬────┘ │
│ │ │ │ │
│ └─────────────┼─────────────┘ │
│ │ │
│ ▼ │
│ ┌───────────────┐ │
│ │ Shared Facts │ │
│ │ • Alerts │ │
│ │ • Knowledge │ │
│ │ • Status │ │
│ └───────────────┘ │
│ │
└─────────────────────────────────────────────────────┘How It Works
Announcing Facts
Agents can share information using the [ANNOUNCE] tag:
[ANNOUNCE] Production API is experiencing intermittent 503 errors since 10:30 UTCThis fact is:
- Extracted from the agent's response
- Stored in the shared swarm database
- Made available to all other agents
Retrieving Facts
Agents automatically retrieve relevant swarm facts:
User: "Is there anything I should be aware of?"
Agent retrieves from swarm:
- Production API issues (from Agent A)
- New deployment scheduled (from Agent B)
Agent: I've found a couple of things from the team:
1. The production API is having intermittent issues
2. There's a deployment scheduled for 3pmUse Cases
System Monitoring
Agent: Monitor
I've detected high CPU usage on the production server.
[ANNOUNCE] CPU usage alert: 95% on prod-server-1Agent: Assistant (later)
User: Any system issues?
Agent: Yes, there's been a CPU alert on prod-server-1 showing 95% usage.Knowledge Sharing
Agent: Researcher
I found that the API rate limit is 1000 requests/minute.
[ANNOUNCE] API rate limit confirmed at 1000 req/minAgent: Developer (later)
User: What's the API rate limit?
Agent: According to research, it's 1000 requests per minute.Task Coordination
Agent: Task Manager
Build #4521 started.
[ANNOUNCE] Build #4521 in progress - expected completion 15 minutesAgent: Notifier
User: Any builds running?
Agent: Build #4521 is currently in progress.Alert Broadcasting
Agent: Watchdog
[ANNOUNCE] CRITICAL: Database connection pool exhaustedAll agents are now aware of this critical issue.
Architecture
Shared Database
Swarm memory is stored in a shared SQLite database:
~/.moxxy/swarm.dbSchema
CREATE TABLE swarm_facts (
id INTEGER PRIMARY KEY,
source_agent TEXT NOT NULL,
content TEXT NOT NULL,
embedding BLOB,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
expires_at DATETIME
);Fact Properties
| Property | Description |
|---|---|
source_agent | Which agent announced it |
content | The fact content |
embedding | Vector embedding for search |
created_at | When it was announced |
expires_at | Optional expiration |
Fact Lifecycle
Creation
- Agent generates response with
[ANNOUNCE] - Content is extracted
- Embedding is created
- Stored in swarm.db
Retrieval
- Query is embedded
- Similar facts are found
- Top-k results are returned
- Injected into agent context
Expiration
Facts can have an expiration time:
[ANNOUNCE:TTL=3600] Temporary issue resolved - will auto-expire in 1 hourExpired facts are automatically cleaned up.
Configuration
Enable/Disable
Swarm is enabled by default. To disable:
moxxy run --agent default --prompt "Store 'false' in vault as swarm_enabled"Fact Retention
Set how long facts are kept:
# Keep facts for 7 days
moxxy run --agent default --prompt "Store '7' in vault as swarm_retention_days"Maximum Facts
Limit stored facts:
moxxy run --agent default --prompt "Store '1000' in vault as swarm_max_facts"API Access
Get Swarm Facts
curl http://localhost:17890/api/swarm/factsSearch Swarm
curl -X POST http://localhost:17890/api/swarm/search \
-H "Content-Type: application/json" \
-d '{"query": "production issues", "limit": 10}'Add Fact Manually
curl -X POST http://localhost:17890/api/swarm/facts \
-H "Content-Type: application/json" \
-d '{
"content": "Manual fact entry",
"source_agent": "admin",
"ttl_seconds": 86400
}'Clear Swarm
curl -X DELETE http://localhost:17890/api/swarm/factsAgent Delegation
Agents can delegate tasks to other agents:
Using delegate_task
Ask the researcher agent to investigate the API documentationThis triggers:
delegate_taskskill is invoked- Target agent receives the task
- Target agent processes and responds
- Result is returned to original agent
Example Flow
User: "Research the competitor's pricing"
Agent A: I'll delegate this to the researcher agent.
<invoke name="delegate_task">["researcher", "Research competitor pricing"]</invoke>
[Agent B (researcher) activates]
Agent B: I'll research the competitor's pricing...
[processes task]
Result: Competitor pricing is $X for basic, $Y for pro...
[Back to Agent A]
Agent A: Based on the research, the competitor charges...Privacy Considerations
What Gets Shared
- Shared: Facts explicitly announced with
[ANNOUNCE] - Not Shared: Private conversations, secrets, personal data
Agent Isolation
Each agent still maintains:
- Private memory (STM/LTM)
- Private vault
- Private skills
Opt-Out
To prevent an agent from participating in swarm:
moxxy run --agent private_agent --prompt "Store 'false' in vault as swarm_participate"Best Practices
What to Announce
Good:
- System alerts and status
- Important discoveries
- Team-relevant knowledge
- Task progress updates
Avoid:
- User personal information
- Sensitive credentials
- Temporary/fluid information
TTL Usage
Use appropriate TTLs:
[ANNOUNCE:TTL=300] Server rebooting in 5 minutes
[ANNOUNCE:TTL=3600] Brief outage resolved
[ANNOUNCE:TTL=86400] New deployment version: v2.3.1
[ANNOUNCE] Permanent config change (no expiration)Naming Conventions
Prefix facts for clarity:
[ANNOUNCE] ALERT: High memory usage
[ANNOUNCE] INFO: Deployment complete
[ANNOUNCE] TASK: Build started
[ANNOUNCE] CONFIG: Rate limit updatedTroubleshooting
Facts Not Appearing
Check swarm is enabled:
bashsqlite3 ~/.moxxy/swarm.db "SELECT COUNT(*) FROM swarm_facts;"Verify agent participation:
bashmoxxy run --agent default --prompt "Is swarm participation enabled?"
Old Facts Persisting
- Check retention settings
- Manually clean old facts:bash
sqlite3 ~/.moxxy/swarm.db "DELETE FROM swarm_facts WHERE created_at < datetime('now', '-7 days');"
Search Not Working
Verify embeddings:
bashsqlite3 ~/.moxxy/swarm.db "SELECT COUNT(*) FROM swarm_facts WHERE embedding IS NOT NULL;"Check embedding model configuration