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::CallLlm 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§
- Affinity
Router - Retains a model per request identity and forces it on later matching requests.
- Call
LlmRequest - The host-facing half of an offloaded model call, surfaced inside
Step::CallLlm. - 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
- The offload channel handed to an algorithm’s
create_run_task. The algorithm makes model calls withcall_llmand publishes itsDecisions withinfo; each call is offloaded to the request’sStepstream and awaits the consumer’s response. The step channel is bounded, so the consumer paces the algorithm one step at a time. - 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.
- LlmCall
Observation - One completed model call observed at the algorithm offload boundary.
- 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 target’s name reaches the consumer as
decision.selected_model()on the offloadedRoutedRequest. - 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.
- Noop
Decision - Test decision carrying the inbound model or a fixed placeholder.
- Passthrough
- Routing algorithm that always calls one configured target.
- Passthrough
Decision - Decision emitted before
Passthroughcalls its configured target. - Random
- Random router implemented as a stateless fall-through composition.
- Random
Classifier - Stateless weighted classifier used by random fall-through routing.
- Routed
Request - A request paired with the routing
Decisionthat produced it — the offload payload a host reads (viaCallLlmRequest::get_routed) to serve the call. - 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 type-erased promise-over-stream driver.
- Event
- An event observed by the algorithm. Events are consumed by
Processorto mutate state. - 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.
- RunObservation
- One request-scoped observation emitted by the algorithm runner.
- State
Value - A value in a session’s
State. - Step
- One item in the stream returned by
Driver::stream/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
create_run_task; callers drive it withrun_stream, serving eachStep::CallLlmit 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§
- algorithm_
label - The algorithm label
Algorithm::run_streamstamps into a request context; empty until stamped. - 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§
- Random
Decision - Compatibility name for the decision produced by
Random. - Result
- Result type returned by libsy APIs.
- RunObserver
- Request-scoped callback for algorithm-run observations.
- Step
Stream - A boxed,
Sendstream ofSteps — the output ofAlgorithm::run_stream. Boxed so the trait method that produces it keepsArc<dyn Algorithm>object-safe.