subagent-orchestration
Use when designing or debugging the Master Orchestrator's routing logic, intent detection, escalation rules, or handoffs between the 4 sub-agents (customer-service / sales / lead-intake / operations).
SKILL.md.claude/skills/subagent-orchestration/SKILL.md
GitHubSub-agent Orchestration skill
When to invoke
- Touching
src/orchestrator/master.tsor its prompt - Adding a new sub-agent or new routing intent
- Debugging "wrong agent picked up the message"
- Modifying escalation-to-human logic
Architecture invariants
- Master sees full conversation history ג€” sub-agents see only their slice + relevant CRM context
- One agent active per turn ג€” no parallel sub-agent calls for the same customer message
- Tool:
route_to_agentis the only way Master delegates ג€” never inline-respond to a customer-facing message that should go through a sub-agent - Sub-agents cannot route to each other ג€” they return to Master, Master re-routes if needed
Routing decision tree (priority order)
- Compliance escalation trigger ג†’ human, regardless of intent
- Existing CRM process active ג†’ operations agent (continuity)
- New lead, no CRM record ג†’ lead-intake agent
- Qualified lead, awaiting booking ג†’ sales agent
- Existing customer, transactional question ג†’ customer-service agent
- Ambiguous ג†’ customer-service agent with explicit "ask clarifying question" instruction
Hard rules
- Never lose conversation state across routing ג€” Master passes a context object, sub-agent must acknowledge it
- Log every routing decision with reasoning (which rule fired) for debugging
- Escalation to human is terminal ג€” once escalated, no agent responds until human releases
- Hebrew intent detection ג€” never route based on English keyword match alone; Israeli customers code-switch frequently
Model choices (from CLAUDE.md)
- Master:
claude-opus-4-7(sees everything, needs strongest reasoning) - Sub-agents:
claude-sonnet-4-6(focused scope, cost-balanced) - Doc classification:
claude-haiku-4-5-20251001(cheap, fast)
Do not override without good reason ג€” costs add up fast at scale.
Common failure modes
- Ping-pong: Master keeps re-routing ג†’ add cycle detection, max 2 routes per customer turn
- Wrong agent for known customer: missing CRM lookup before routing ג€” always fetch CRM context first
- Lost Hebrew nuance: prompts written in English describing Hebrew intents ג€” write triggers in Hebrew with English comments