Delegate & Sub-agents
One agent can call another. Two patterns: delegate (sub-query without losing your active agent) and handoff (transfer the whole session). Sub-agents run multiple agents in parallel.
Delegate โ sub-query another specialist
Keeps your current agent active. Spawns a sub-session keyed by parent::delegate::<target>:
curl -X POST http://127.0.0.1:18789/agent/delegate \
-d '{
"parentSessionKey": "user-123",
"delegateAgent": "code-reviewer",
"query": "Review this snippet for race conditions"
}'Handoff โ transfer the conversation
Changes session.agent permanently. Future messages route to the new agent:
curl -X POST http://127.0.0.1:18789/agent/handoff \
-d '{"sessionKey": "user-123", "newAgent": "defi-strategist"}'Sub-agents โ parallel execution
Up to 10 agents in parallel, each with its own sub-session. Useful for second opinions:
curl -X POST http://127.0.0.1:18789/agent/subagents \
-d '{
"parentSessionKey": "user-123",
"tasks": [
{"agent": "bags-hunter", "query": "Is $XYZ a rug?"},
{"agent": "defi-strategist", "query": "Is $XYZ overvalued?"},
{"agent": "security-reviewer", "query": "Audit $XYZ contract"}
]
}'Returns an array of { agent, query, reply, durationMs, error? }. Sub-agents share the global concurrency lane โ they queue if all lanes busy.
Source
Implementation: apps/gateway/src/delegate.ts