Host Integration
Add libsy where your gateway or agent harness chooses and calls a model. Your application keeps its transport, credentials, and lifecycle.
Start with the Rust quickstart for a working example. Use Mechanics of Libsy for execution and Switchyard Protocols for data conversion. This page covers the responsibilities specific to your host.
Choose the integration boundary
Host responsibilities
Dispatch every requested call. Apply your credentials, budgets, and access policy to routing-time judge calls as well as answer calls. Send internal calls through model dispatch without entering the same router again. Supply only models your host can reach. See call handling and final-outcome handling.
Keep history and state. Supply the tool history required by the algorithm; provider continuation IDs alone can hide that evidence. Scope session IDs to the tenant and conversation. Reuse algorithm instances when they retain session decisions, and decide how your host handles concurrent turns and multiple processes. State behavior is algorithm-specific; see Composite sessions and the Plan/Execute history requirement.
Observe the complete run. Include judge calls and final model work in your host’s observations. Configure telemetry collection in your application and instrument model I/O performed by your own clients. See the OpenTelemetry reference.
For existing integrations, check NeMo Relay or the LiteLLM compatibility notes. The experimental LiteLLM plugin supports decision-only routing and cannot serve intermediate model calls.
Serve routing-time calls
Use your existing client as shown in the Step loop. The shared client traits below are optional.
Python bindings
The bindings run the same Rust algorithms. The local routing example below works with the released package. For the asynchronous callbacks and cleanup described after it, build matching development bindings and follow the complete Python host example.
Python setup, callbacks, and metadata
With Python 3.10+ and uv, create a project and install the released package:
Save as route.py:
uv run route.py prints Selected: Efficient without making a network call.
Target requirements (development)
With matching development bindings, load deployment TOML that declares target labels and route eligibility. Build once and reuse the returned handles:
For each Step.CallModel, resolve the returned target before calling your client.
Here clients is supplied by the gateway and keyed by the TOML client aliases,
not a new Switchyard interface. Its clients follow the
Python host example: they accept a normalized request
and provider model ID, and return LlmResponse.Agg or LlmResponse.Stream.
Use the first routing-time candidate and pass client failures back to Switchyard.
Typed Decision calls use targets[call.model] and their own Decision handler.
For a final answer candidate, use targets[outcome.selected_model_ids[0]].
The lookup contains all possible targets, not the eligible pool for this request;
use only keys returned by calls and outcomes. build() handles reject this lookup.
The host supplies the assessment and an authorized task ID. An explicit task ID
overrides a task ID from headers. Omitted labels mean no assessment; [] supplies
no new requirements. In task scope, earlier requirements remain in effect.
Invalid requirements or missing approved targets fail before any routing call.
Consume steps through the same model and Decision call handlers. Switchyard
does not create provider clients or read their credentials. The host owns target
prompts, provider settings and transport, and must keep answer attempts and
fallbacks within the returned candidates. Existing build() handles do not
accept target requirements. Per-run libsy state is not carried between Python calls.
Concurrent calls and cancellation
The client coroutine returns LlmResponse.Agg or LlmResponse.Stream.
Pass the coroutine itself to respond:
respond cancels and awaits the supplied provider work before returning.
For concurrent algorithms, create handler tasks and cancel and await the remaining
handlers when the run ends, as in the Python host example.
Awaiting one handler at a time serializes execution. call.fail(error) is also
awaitable; decision calls use the same reply pattern.
For the shared cancellation behavior and upstream limits, see Mechanics.
Metadata and telemetry
After checking that outcome.metadata is present, read its outcome_id,
algorithm, and evidence attributes. Evidence is a normal Python value, usually
a dictionary; algorithms without evidence return None. See the
OpenTelemetry reference for signals and export setup.