> This page is for version Dev.
> For other versions, use one of these documentation indexes:
> - Latest (v0.4.0) (default): https://docs.nvidia.com/nemo/switchyard/latest/llms.txt
> - Dev: https://docs.nvidia.com/nemo/switchyard/dev/llms.txt

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/nemo/switchyard/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.nvidia.com/nemo/switchyard/_mcp/server.

# Sub-Agent-Aware Routing

Sub-agent-aware routing leaves parent-agent traffic with its configured routing
algorithm while routing delegated sub-agent work separately. It is available on
`passthrough`, `stage_router`, and `composite` routes through the optional
`subagents` table.

```toml
schema_version = 1

[llm_clients.openrouter]
format = "openai_chat"
base_url = "https://openrouter.ai/api/v1"
api_key_env = "OPENROUTER_API_KEY"

[targets.parent]
id = "anthropic/claude-sonnet-5"
llm_client = "openrouter"

[targets.classifier]
id = "openai/gpt-4.1-mini"
llm_client = "openrouter"

[targets.worker]
id = "openai/gpt-5.4-mini"
llm_client = "openrouter"

[targets.reviewer]
id = "anthropic/claude-opus-5"
llm_client = "openrouter"

[routes.agent]
id = "agent"
type = "passthrough"
target = "parent"
context_window = 400000
tool_calling = true
reasoning_levels = ["low", "medium", "high", "max"]

[routes.agent.subagents]
type = "llm_classifier"
mode = "custom"
models = { judge = ["classifier"], capable = ["reviewer"], efficient = ["worker"], any = ["worker", "reviewer"] }
default_target = "efficient"
classify_trigger = "new_session"
max_output_tokens = 64
prompt = """
Select exactly one target for the delegated task.

- Select "capable" for code review, critique, auditing, or correctness analysis.
- Select "efficient" for implementation, research, explanation, and other delegated work.

Return only JSON matching the response schema.
"""
response_schema = '''
{
  "type": "object",
  "properties": {
    "target": {"type": "string", "enum": ["capable", "efficient"]}
  },
  "required": ["target"],
  "additionalProperties": false
}
'''
policy = { type = "target_selector", selector = "/target" }
```

Set `OPENROUTER_API_KEY`, save the configuration as `routes.toml`, and validate it
before starting the server:

```bash
export OPENROUTER_API_KEY="sk-or-v1-..."  # pragma: allowlist secret
switchyard-server --config routes.toml --dry-run
switchyard-server --config routes.toml --port 4000
```

The `subagents` table has its own model groups, separate from the parent
route's. A category name in the sub-agent table always means the sub-agent's own
models, even when the parent route uses that category too, and the parent never
falls back onto a model only the sub-agents were given.

The parent always uses `parent`. For a delegated request, the classifier sees
the prompt supplied by the parent and selects one configured target. With
`classify_trigger = "new_session"`, Switchyard reuses that decision for later
requests from the same `session + agent` identity. Use `every_request` to
classify each delegated request. `user_turn` is not supported for sub-agent
routing. Harness-maintenance requests continue through the parent route.

To use Stage Router for parent traffic, replace the `[routes.agent]` table in the
example with the following. The nested `[routes.agent.subagents]` classifier is
unchanged.

```toml
[routes.agent]
id = "agent"
type = "stage_router"
capable_target = "reviewer"
efficient_target = "worker"
picker = "efficient_first"
confidence_threshold = 0.7
context_window = 400000
tool_calling = true
reasoning_levels = ["low", "high", "max"]
```

The parent stage route may also declare `[routes.agent.tool_semantics]` to map
domain-specific tools; delegated sub-agent policy configuration is unaffected.

Clients must still request the route ID (`agent` above). An explicit model name
that is not registered as a route is rejected before sub-agent classification.
`message_hash_fallback` is not supported for sub-agent routing because affinity
requires harness-provided child identity.

Claude Code sends child identity (`x-claude-code-agent-id`) starting with version
2.1.139. Older builds send only the session id, so Switchyard cannot tell a
sub-agent request from the parent's and routes it through the parent route.
When a route with a `subagents` table sees an older Claude Code, Switchyard logs
one warning that a harness upgrade may be required. Upgrade Claude Code to
2.1.139 or later.

To send every delegated sub-agent request to one fixed target without calling a
classifier, replace the `subagents` table above with:

```toml
[routes.agent.subagents]
type = "passthrough"
target = "worker"
```