Expand description
§switchyard-libsy
Provider-neutral orchestration for multi-LLM optimization. A libsy
Algorithm decides which model targets to call, in what order, and how to
combine their results. It hands every call back to the host rather than making
it, allowing it to embed in proxies, gateways, and agent runtimes without owning
an HTTP stack.
§Setup
[dependencies]
async-trait = "0.1"
futures = "0.3"
switchyard-libsy = { git = "https://github.com/NVIDIA-NeMo/Switchyard.git" }
switchyard-protocol = { git = "https://github.com/NVIDIA-NeMo/Switchyard.git" }
tokio = { version = "1", features = ["macros", "rt"] }§Built-in algorithms
| Type | Purpose |
|---|---|
Passthrough | Always call one configured target. |
Random | Select among any number of targets using uniform or weighted routing. |
LlmTaskClassifier | Ask a judge model to choose an efficient or capable target. |
StageRouter | Route coding-agent turns from tool and progress signals, with an optional judge fallback. |
Noop is a test helper, not a production routing algorithm.
§How it fits together
LlmTarget names a routing destination. An Algorithm selects targets and
records Decisions, offloading every model call
to its caller: Algorithm::run_stream yields a Step stream whose
Step::CallModel items the host serves over its own transport. libsy makes no
network calls itself — switchyard-llm-client’s run is a ready-made consumer
that drives the stream and performs the calls over HTTP.
The provider-neutral Request, Response, Usage, and LlmResponse
contracts come from switchyard-protocol.
§License
Licensed under the Apache License, Version 2.0.
Structs§
- Advisor
Gate - Advisor review gate: executor turns pass through until the first terminal turn, which a stronger advisor reviews once per scope budget (APPROVE releases it, REDO feeds the plan back and re-invokes the executor).
- Advisor
Gate Config - Gate knobs; defaults mirror the benchmarked Python advisor configuration.
- Affinity
Router - Retains a model per request identity and forces it on later matching requests.
- Call
Model - An offloaded model call, surfaced inside
Step::CallModel. - Classifier
Contract Config - User-configurable parts of a classifier’s prompt and verdict contract.
- Coding
Agent Dimensions - The two-axis feature view of a single
ToolSignals. - Custom
Classifier Config - Settings for a classifier whose JSON Schema and target-selection policy are user supplied.
- Driver
- How an algorithm’s
routemakes model calls. - Escalation
Judge Config - The tuning surface for the trajectory judge.
- Handoff
Note Config - The notes a stage router hands the model it routed to, and the gate deciding which one a turn earns.
- LlmFallback
- The capability judge a stage router falls through to.
- LlmTarget
- A named routing target an algorithm routes by. Serving its calls is the stream
consumer’s concern: the selected identifier reaches the consumer as
decision.selected_model_id()on the offloadedCallModel. - LlmTarget
Set - The set of targets an algorithm may route among. An algorithm is constructed
with one and picks targets by position (
targets) or by name (get_target). - LlmTask
Classifier - Routes requests through a capability, escalation, or custom classifier mode.
- Noop
- Test helper that returns a hard-coded response without routing or model I/O.
- Passthrough
- Routing algorithm that always calls one configured target.
- Random
- Random router implemented as a stateless fall-through composition.
- Random
Classifier - Stateless weighted classifier used by random fall-through routing.
- Score
- One classifier’s recommendation of a routing
target, with a[0.0, 1.0]confidence. - Score
Result - A signed score in
(-1, +1)and its magnitude.confidence == score.abs(). - Stage
Classifier - Signal-only stage-router classifier: scores each turn onto the capable/efficient tiers from tool-result signals, via the configured picker mode and the confidence the scorer must reach before it acts on the signal alone.
- Stage
Router - Routes coding-agent turns between a capable and an efficient tier: tool signals decide first, an optional capability judge takes the turns they cannot, and the picker’s default tier closes the cascade so a turn is never left unrouted.
- Stage
Router Config - How a stage router scores turns, and what it hands the model it picks.
- Stage
Targets - The targets a stage router’s two tiers route to.
- State
- Routing facts accumulated across one session’s algorithm runs.
- Subagent
Override - Scores a fixed worker target for delegated sub-agent work; abstains otherwise.
- System
Prompt Processor - Prepends the routed target’s system prompt to the outbound request.
- Target
Prompts - System prompts keyed by routing target. A target left unset is routed untouched.
- Task
Classifier Config - Settings that control capability classifier prompting and routing.
- Tool
Signals - Tool-execution signals extracted from a normalized
Request.
Enums§
- Classification
- A classifier’s verdict for a request: a set of target
Scores, flagged by how confident the classifier is that they are decisive. - Custom
Classifier Policy - Policy that maps a custom classifier verdict to a routing target.
- Decision
Source - What produced a decision — for stats and explainability.
- Driver
Error - Failures in the step-stream driver.
- Event
- An event observed by the algorithm. Events are consumed by
Processorto mutate state. - Gate
Trigger - How the gate decides a buffered executor turn is terminal.
- Libsy
Error - Failures surfaced while selecting a route, driving an algorithm, or serving a model call.
- LlmClassifier
Config - Complete construction settings for one LLM classifier mode.
- Pick
Outcome - Outcome of
pick_tier: either a resolved decision, or a signal that the caller should consult its (impl-specific, async) classifier. - Picker
Mode - Which tier to default to when the scorer is not confident.
- State
Value - A value in a session’s
State. - Step
- One item in the stream returned by
Algorithm::run_stream. - Tier
- The two tiers a turn can route to.
Constants§
- DECISION_
SOURCE_ KEY State.extrakey under which the turn’sDecisionSourceis recorded.- DEFAULT_
RECENT_ WINDOW - Default sliding-window size for
recent_*counts and windowed severity.
Traits§
- Algorithm
- An optimization strategy. Implement
route; callers drive it withrun_stream, serving eachStep::CallModelit emits.switchyard-llm-client’srunis the ready-made consumer that does this over HTTP. - Classifier
- Scores targets from the current request and the composition’s state.
- Processor
- Collects events as the algorithm runs and mutates the composition’s state.
Functions§
- append_
note - Appends
noteto the request as conversation text. - dimensions_
from_ signal - Project a
ToolSignalsonto the two-axis dimension space. - drive
- Drive
Algorithm::run_streamto completion, handing each offloaded call toserve. - initialize_
metrics - Registers process-wide compatibility gauges with the global meter provider.
- pick_
tier - Decide a turn’s tier from its signal.
- score_
signal - Score a signal: weighted sum of the dimensions,
tanh-squashed.
Type Aliases§
- Result
- Result type returned by libsy APIs.
- Step
Stream - A boxed,
Sendstream ofSteps — the output ofAlgorithm::run_stream. Boxed so the trait method that produces it keepsArc<dyn Algorithm>object-safe.