Switchyard is an LLM router library. It sits between an agent's request (e.g. Claude Code, Codex CLI) and an inference server, selecting the best model for that request.
It is written in Rust with Python bindings.
Core components in crates/. These are layered:
libsy: The core library and routing algorithms. This is the heart of Switchyard. Main entry point isAlgorithm::run_streammethod.libsy-llm-client: HTTP client that makes requests forlibsyalgorithms, and drivesrun_stream. Main entry point isrunfunction inrun.rs.switchyard-runner: Parsing TOML configuration, useslibsy-llm-clientto run until the algorithm resolves to the selected model. The entry point isRunnerstruct.switchyard-server: A thin HTTP demo server wrapped aroundswitchyard-runner. Has a TOML config file.switchyard-py: Python bindings forlibsyandlibsy-llm-client.
Support components (also in crates/):
protocol: Types shared between many components.switchyard-translation: Convert between various JSON inference formats: OpenAI Chat Completions, OpenAI Responses and Anthropic Messages. We convert to/from a vendor neutral independent representation (IR). All the core components with with this IR.
Integrations:
crates/switchyard-nemo-relay-plugin/: Integrate with NeMo Relay.examples/litellm/: Integrate with LiteLLM.
Write for a high-school level in short, simple sentences. Avoid jargon, analogies and metaphors. Be direct.
- Prefer the smallest direct solution.
- Avoid abstractions, configurability, and defensive code for hypothetical needs.
- If the implementation grows unexpectedly large, reconsider and simplify it.
- For bugs, reproduce the failure before fixing it; for refactors, establish a behavioral baseline first.
- Make reasonable, reversible assumptions when consequences are small. Ask only when ambiguity would materially change the result, expand scope, or risk an irreversible acti
- Comments Explain Code, Not Project Management
Source comments are about the code. Tracking lives in the tracker.
- No issue/PLAN/step references in code (
TODO(step-6), "lands in step 4", "tracked as ISSUE-001", links todocs/issues/). These rot the moment the plan changes and leak project-management state into source. - A plain
// TODO:describing a concrete code gap is fine; a// TODOpointing at a tracker step is not. - Comment what isn't obvious from the code: why a thing is done this way, invariants, non-obvious edge cases. Don't narrate what the code already says.
- Module doc comments should state what the module is for, not its build schedule or its "empty for now" status.
- Commit Discipline
One step, one reviewed, one-line commit.
- One focused commit per step; every changed line traces to that step.
- Single-line commit message in Conventional Commits form
(
type(scope): summary). No body, noCo-Authored-Bytrailer. - Pull request titles use the same Conventional Commits form.
- Use
git commit -sso every commit carries the required DCO sign-off. - Never commit unprompted. Show the diff, get approval, then commit.