Switchyard lets LLM applications route traffic across models and providers while preserving native OpenAI and Anthropic API compatibility - enabling flexible model selection, benchmarking, and cost/performance optimization.
Rust
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Two-tier custom-mode classifier routing for multi-turn customer-support traffic.
# The classifier answers with a target name, which `policy.selector` reads directly.
#
# Calibrated against:
# Benchmark tau2-bench, telecom customer support (multi-turn, tool-using), full 114 tasks
# Strong tier Anthropic Claude Opus 4.7
# Weak tier Qwen3.6-35B-A3B, served on-device (llama.cpp)
# Classifier the same on-device Qwen3.6-35B-A3B
# Measured 0.891 +/- 0.029 solve rate at approximately 85% of turns served by the weak tier
# Rubric frozen; the `prompt` below is the text that was measured
#
# The routing parameters and the classifier rubric below are exactly as run. The model
# wiring is not: the measured runs used NVIDIA-internal endpoints and an on-device weak
# tier, replaced here with the closest publicly reachable OpenRouter models so the
# deployment runs as written. The weak tier in particular is a near equivalent rather
# than the same build, so treat the figures above as the operating point of the
# calibrated pair, not a prediction for this file as configured.
#
# Aggressive trades roughly one point of solve rate for nearly twice the offload of the
# balanced profile. Whether that trade is acceptable is a per-deployment decision.
#
# These numbers describe this tier pair on this traffic. A different pair of models, or a
# different traffic domain, will sit at a different operating point: recalibrate rather
# than assuming the thresholds transfer.
#
# switchyard-server --config benchmark/routing-profiles/tau2-telecom-custom-opus-qwen-aggressive.toml --port 4000
schema_version = 1
[llm_clients.openrouter]
format = "openai_chat"
base_url = "https://openrouter.ai/api/v1"
api_key_env = "OPENROUTER_API_KEY"
[targets.strong]
id = "anthropic/claude-opus-4.7"
llm_client = "openrouter"
[targets.weak]
id = "qwen/qwen3-35b-a3b"
llm_client = "openrouter"
[targets.classifier]
id = "qwen/qwen3-35b-a3b"
llm_client = "openrouter"
[routes.switchyard]
id = "switchyard"
type = "llm_classifier"
mode = "custom"
recent_turn_window = 6
# Re-classify when the user speaks again, and hold that target across the tool calls
# in between, so a tool chain never switches tier mid-task.
classify_trigger = "user_turn"
models = { judge = ["classifier"], capable = ["strong"], efficient = ["weak"], any = ["strong", "weak"] }
default_target = "capable"
response_schema = '''
{
"type": "object",
"properties": {
"route": { "type": "string", "enum": ["efficient", "capable"] },
"confidence": { "type": "number" },
"abstain": { "type": "boolean" }
},
"required": ["route", "confidence", "abstain"],
"additionalProperties": false
}
'''
prompt = '''
You are a routing classifier inside a customer-service agent. Return exactly
one JSON object:
{"route": "efficient" or "capable", "confidence": number 0..1, "abstain": boolean}
State the route DIRECTLY: "efficient" = the on-device assistant handles this turn;
"capable" = escalate this turn to the frontier model.
ROUTING BIAS: the efficient tier is the DEFAULT — it handles nearly all support
work end-to-end: lookups, standard actions, troubleshooting with known steps,
collecting info, confirmations, relaying tool results, single-policy checks.
ROUTE TO efficient UNLESS YOU CAN NAME A SPECIFIC REASON IT WILL FAIL.
Escalate to capable only for a CONCRETE hard property: reconciling multiple
conflicting policy conditions, multi-account/line arithmetic, diagnosis still
unexplained after tool checks, or an exception decision where a wrong answer
harms the customer. When in doubt, choose efficient.
Set abstain=true only when truly unclassifiable. No markdown, no
chain-of-thought — only the JSON object.
'''
[routes.switchyard.policy]
type = "target_selector"
selector = "/route"