Multi-Agent Communication
by @openlark
Based on two core tools, sessions_spawn and sessions_send, to help users build, manage, and optimize distributed Agent systems, enabling task decomposition,...
clawhub install multi-agent-communicationπ About This Skill
name: multi-agent-communication description: Based on two core tools, sessions_spawn and sessions_send, to help users build, manage, and optimize distributed Agent systems, enabling task decomposition, parallel processing, and efficient coordination among Agents.
Multi-Agent Communication
Core tools: sessions_spawn (launch child Agents) and sessions_send (send messages to existing Agents).
Use Cases
Two Core Tools
sessions_spawn β Create a new Agent instance
sessions_spawn({
task: "Review PR #123",
agent: "code-reviewer", // Agent ID (not SOUL name)
mode: "run", // run=one-shot, session=persistent
thread: false, // Whether to bind to a message thread
runTimeoutSeconds: 300 // Optional, timeout duration
})
Essence: Fork a new process. Creates an independent session and execution environment, automatically pushing results back to the parent Agent upon completion. In mode="run", the child Agent's execution process is not visible to the user by default.
sessions_send β Send a message to an existing Agent
sessions_send({
sessionKey: "agent:main:subagent:abc",
label: "security", // Use sessionKey or label
message: "Check security",
timeoutSeconds: 30 // Synchronous wait; 0=asynchronous delivery
})
Essence: Inter-Process Communication (IPC). Sends messages to an existing session, supporting multi-round A2A negotiation (up to 5 rounds of ping-pong).
Core Decision: Which One to Choose?
| Scenario | Tool | Mode | |----------|------|------| | Background data processing, one-shot analysis | sessions_spawn | mode: "run" | | Parallel task decomposition (multiple spawns) | sessions_spawn | mode: "run" | | Multi-round code review (user-visible) | sessions_spawn | mode: "session", thread: true | | Real-time collaborative Q&A between Agents | sessions_send | timeoutSeconds > 0 | | Asynchronous delivery, no reply needed | sessions_send | timeoutSeconds: 0 |
Quick Judgment:
Spawn Execution Flow (10 Stages)
User Request β Main Agent β sessions_spawn
β
[1. Permission Check] β Verify depth, concurrency, whitelist
β
[2. Session Creation] β Generate unique sessionKey
β
[3. Thread Binding] β (Optional) Bind to Discord/Slack thread
β
[4. Attachment Handling] β Snapshot transfer (independent lifecycle)
β
[5. System Prompt] β Inject task context
β
[6. Working Directory] β Inherit parent Agent or use target Agent config
β
[7. Agent Launch] β Via Gateway RPC
β
[8. Runtime Registration] β Record in SubagentRegistry
β
[9. Hook Trigger] β Notify plugins
β
[10. Result Return] β Return childSessionKey
Results are automatically pushed back to the parent Agent via Sweeper (checks every 1-8 seconds), no manual polling required.
Session Key Design
Main Agent: agent:main:main
Child Agent: agent:main:subagent:
Grandchild: agent:main:subagent::subagent:
UUID ensures global uniqueness; the hierarchical structure facilitates routing and traceability.
mode="run" vs. mode="session"
| Feature | run | session | |---------|-----|---------| | Lifecycle | One-shot, deleted upon completion | Persistent, awaits subsequent messages | | Thread Binding | Not supported | Required (thread=true) | | User Visibility | β Completely invisible | β Visible in thread | | Applicable Scenarios | Background data processing | Multi-turn conversations, code reviews |
β οΈ Note: mode="session" must also have thread=true set, otherwise subsequent messages cannot be routed correctly.
Three-Tier Security Protection
| Constraint | Default Value | Purpose | |------------|---------------|---------| | Max Recursion Depth | 1 | Prevent infinite recursion | | Max Child Processes | 5/session | Prevent resource exhaustion | | Whitelist Mechanism | Configurable | Cross-Agent permission control |
A2A Multi-Round Negotiation (sessions_send)
Agent A ββ"Format this code"βββ Agent B
ββ"Which style do you prefer?"
Agent A ββ"Use Prettier"ββββββ Agent B
ββ"Done"
Agent A ββREPLY_SKIPβββββββββββ Agent B
Key Design Decisions
Configuration Suggestions
See references/config.md for details.
Design Patterns
See references/patterns.md for details.