Feature Request: Add sessions.spawn gateway method for direct subagent spawning
Summary
Add a sessions.spawn gateway method that allows spawning subagent sessions directly without requiring an LLM in the loop.
Motivation
Currently, spawning subagents requires using the sessions_spawn tool from within an agent session, which means:
- Every spawn operation requires an LLM call (~$0.01+ per spawn)
- External automation (systemd timers, cron scripts, CI/CD) cannot spawn subagents directly
- Task orchestration systems must go through expensive LLM intermediaries
For autonomous agent systems that need to spawn many workers (e.g., task dispatchers, build systems, test runners), this creates unnecessary cost and latency.
Proposed Solution
Add sessions.spawn as a gateway method that:
- Accepts the same parameters as the
sessions_spawntool (task, label, model, thinking, timeout, cleanup) - Validates permissions (only main/cron sessions can spawn, not subagents)
- Creates the subagent session and triggers the agent run
- Returns the childSessionKey and runId
Use Cases
- Task Dispatchers: Automated systems that pick tasks from a queue and spawn workers
- CI/CD Integration: External build systems triggering agent runs
- Scheduled Jobs: Cron-like systems spawning workers without LLM overhead
- Cost Optimization: Reducing per-spawn cost from ~$0.01 to ~$0 for high-volume orchestration
Implementation Notes
The implementation would largely mirror the existing sessions_spawn tool logic in src/agents/tools/sessions-spawn-tool.ts, adapted for the gateway context. Key additions:
- Schema validation in
params-schema.ts - Add to
METHOD_LISTinserver-methods-list.ts - Handler in
src/gateway/server-methods/sessions.ts
I've prototyped this locally and can submit a PR with the implementation.
---
*Submitted on behalf of @DeviousCham
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗