基于sessions_spawn和sessions_send两个核心工具,帮助用户构建、管理和优化分布式Agent系统,实现任务分解...
Core tools: sessions_spawn (launch child Agents) and sessions_send (send messages to existing Agents).
text
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.
text
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).
ScenarioToolModeBackground data processing, one-shot analysissessions_spawnmode: "run"Parallel task decomposition (multiple spawns)sessions_spawnmode: "run"Multi-round code review (user-visible)sessions_spawnmode: "session", thread: trueReal-time collaborative Q&A between Agentssessions_sendtimeoutSeconds > 0Asynchronous delivery, no reply neededsessions_sendtimeoutSeconds: 0
Quick Judgment:
text
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.
text
Main Agent: agent:main:main
Child Agent: agent:main:subagent:<uuid>
Grandchild: agent:main:subagent:<uuid>:subagent:<uuid>
UUID ensures global uniqueness; the hierarchical structure facilitates routing and traceability.
FeaturerunsessionLifecycleOne-shot, deleted upon completionPersistent, awaits subsequent messagesThread BindingNot supportedRequired (thread=true)User Visibility❌ Completely invisible✅ Visible in threadApplicable ScenariosBackground data processingMulti-turn conversations, code reviews
⚠️ Note: mode="session" must also have thread=true set, otherwise subsequent messages cannot be routed correctly.
ConstraintDefault ValuePurposeMax Recursion Depth1Prevent infinite recursionMax Child Processes5/sessionPrevent resource exhaustionWhitelist MechanismConfigurableCross-Agent permission control
text
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
See references/config.md for details.
See references/patterns.md for details.