API reference
Every public module, class and function with its signature, generated from the source.
Every module of the opensmartroute package and every public name it exports, generated from the source.
The first line of each docstring is the summary; help() on a name gives the full contract. Narrative
documentation: User guide (usage), SDK guide (stability, extension points),
Architecture, Mathematics, Enterprise builder,
Security model, Research.
Stability: names re-exported from opensmartroute (the top-level package) are frozen and follow SemVer.
Sub-module names are public but may change in a minor release with a CHANGELOG entry.
Modules
opensmartroute- OpenSmartRoute — an open, intelligent route to the right decision, solution, or destination. (92 names)opensmartroute.__main__-python -m opensmartroute ...is theosrcommand (IDE MCP configs, containers without the script on PATH). (0 names)opensmartroute.adapters- Adapters connect OpenSmartRoute to real providers and infrastructure. (87 names)opensmartroute.adapters.a2a- Import A2A (Agent-to-Agent protocol) Agent Cards asTargetKind.AGENTtargets. (5 names)opensmartroute.adapters.anthropic_client- Native Anthropic Messages API client - route TO Claude, not only accept Claude-dialect requests. (8 names)opensmartroute.adapters.catalogue- Live model catalogue: collect model cards (price, context, modalities, benchmarks) from public sources. (11 names)opensmartroute.adapters.frameworks- Drop-in nodes for agent frameworks. (7 names)opensmartroute.adapters.handlers- Executors for non-LLM targets: HTTP endpoints, MCP tools and asynchronous queues. (7 names)opensmartroute.adapters.harness- Agent-harness adapters: route to a runtime, not just a model. (7 names)opensmartroute.adapters.marketplace- Pull skills, agents, tools and templates from an OpenSmartRoute marketplace into a router. (8 names)opensmartroute.adapters.mcp- Import MCP (Model Context Protocol) tools asTargetKind.TOOLtargets. (15 names)opensmartroute.adapters.mcp_servers- MCP server recommendation (MCP-Zero 2506.01056; ToolRet 2603.06467). (3 names)opensmartroute.adapters.mock_client- A provider that answers deterministically without a network: themockprovider kind. (3 names)opensmartroute.adapters.openai_compat- OpenAI-compatible HTTP client (stdlib only). (10 names)opensmartroute.adapters.optional- Optional adapters that need extra dependencies. Everything is lazily imported so the. (3 names)opensmartroute.adapters.personas- Import persona catalogues asTargetKind.PERSONAtargets. (4 names)opensmartroute.adapters.semantic_router- Import a vLLM semantic-router configuration (vllm-project/semantic-router). (3 names)opensmartroute.adapters.skills- Load Agent-SkillsSKILL.mdpackages asTargetKind.SKILLtargets. (4 names)opensmartroute.adapters.websearch- Web knowledge for the self-improving router: stdlib HTTP fetch, search providers, page text. (20 names)opensmartroute.agents-osr run <agent>: launch a coding agent or AI client with the router as its model endpoint. (5 names)opensmartroute.aio- Async façade. Routing itself is CPU-bound and sub-millisecond, so we run it in. (1 names)opensmartroute.anthropic- Anthropic Messages API (POST /v1/messages) on top of the chat-completions proxy. (9 names)opensmartroute.branding- OpenSmartRoute naming conventions: one place for every brand-bound identifier. (28 names)opensmartroute.cli-osrcommand-line interface. (5 names)opensmartroute.client- Client for the hosted platform and a self-hostedosr serve: route, quote, report, chat - standard library only. (10 names)opensmartroute.compress- Prompt compaction: fewer tokens into the model without changing what it is asked. (4 names)opensmartroute.config- Configuration loading: targets and rules from JSON or YAML. (3 names)opensmartroute.core- see module (17 names)opensmartroute.core.registry- Target registry: the catalogue of everything a request may be routed to. (1 names)opensmartroute.core.types- Core data model for OpenSmartRoute. (17 names)opensmartroute.credentials- Credentials for theosrCLI: where the access token lives and how it is obtained. (18 names)opensmartroute.data- Data files shipped inside the package. (0 names)opensmartroute.discovery- Tool discovery beyond text similarity. (5 names)opensmartroute.enterprise- Enterprise integration layer: ports (hexagonal architecture), middleware and telemetry. (22 names)opensmartroute.enterprise.grounding- Live web context in front of the model: search the web for requests about now and hand the hits to the target. (4 names)opensmartroute.enterprise.ops- Operational controls: shadow / A-B routing, tenant fairness and queue-aware latency. (7 names)opensmartroute.enterprise.savings- Savings ledger - the always-on savings report that backs the ROI story and the dashboard. (3 names)opensmartroute.enterprise.stores- Production state-store backends and wrappers. (8 names)opensmartroute.errors- Exception hierarchy. Every error raised by the SDK derives from :class:OpenSmartRouteError. (13 names)opensmartroute.estimate- Token, cost and latency estimates before a request is sent anywhere. (13 names)opensmartroute.eval- RouterBench-style evaluation harness. (21 names)opensmartroute.eval.agentic- tau-bench-style agentic task evaluation: does per-step routing beat the best single agent?. (4 names)opensmartroute.eval.audit- Routing Audit - shadow-mode replay of logged LLM traffic to quantify what the router would change. (6 names)opensmartroute.eval.baselines- Baselines every router must beat, plus oracle ceilings and the sampling noise floor. (15 names)opensmartroute.eval.collect- Collect routing datasets from the Hugging Face Hub, your own feedback log and synthetic seeds. (32 names)opensmartroute.eval.criteria- Offline realisations of the release exit criteria. (15 names)opensmartroute.eval.datasets- Adapters from public routing benchmarks to :class:EvalRow. (7 names)opensmartroute.eval.frontier- Three-objective frontier and ablations. (3 names)opensmartroute.eval.headroom- Routing headroom: when does routing pay, and how much catalogue does it need?. (7 names)opensmartroute.eval.ope- Off-policy evaluation from logged routing decisions. (6 names)opensmartroute.eval.robustness- Robustness and fairness checks for a router. (6 names)opensmartroute.execution- Plan-aware execution: turn a :class:RouteDecisioninto a real answer. (17 names)opensmartroute.feedback- Feedback store: append-only outcome log that closes the learning loop. (1 names)opensmartroute.gemini- Google Gemini API dialect:generateContent/streamGenerateContentover the routed chat path. (9 names)opensmartroute.inference- Run open-weight models on the CPU and RAM you have: footprint arithmetic, host planning, Ollama control. (25 names)opensmartroute.inference.footprint- What an open-weight model needs from a CPU host: memory for weights and KV cache, and the tokens per second. (14 names)opensmartroute.inference.ollama- Talk to an Ollama server's control API: which models it has, their exact shape, which are resident, load and unload. (4 names)opensmartroute.inference.planner- Place models on hosts and write the server settings that make them fit and stay warm. (7 names)opensmartroute.jsonrepair- Repair the JSON a model almost produced. (3 names)opensmartroute.knowledge- Knowledge management and context engineering: a knowledge graph the router learns into and reads from. (21 names)opensmartroute.knowledge.context- Context engineering: what the model should know for this request, chosen and trimmed to a token budget. (6 names)opensmartroute.knowledge.graph- The knowledge graph: typed facts with provenance, in memory, in one JSONL file, exportable to the open formats. (7 names)opensmartroute.knowledge.ingest- Turning what the router sees into facts: catalogue, conversations, decisions, outcomes and live web hits. (8 names)opensmartroute.learning- Auto-learning strategies built on :mod:opensmartroute.math. (71 names)opensmartroute.learning.attention- A pure-Python transformer block for the routing SLM's query encoder. (2 names)opensmartroute.learning.autopilot- Self-operation: the routing SLM runs its own improvement loop inside the live process. (2 names)opensmartroute.learning.coldstart- Cold start for new targets and self-improving target descriptions. (8 names)opensmartroute.learning.contrastive- Contrastive and reward-distilled router training (RouterDC, NeurIPS 2024; Zooter 2311.08692). (5 names)opensmartroute.learning.credit- Delayed, task-level credit assignment for agentic trajectories. (2 names)opensmartroute.learning.embed- Pretrained transformer embeddings as frozen features for the routing SLM. (3 names)opensmartroute.learning.handoff- Permanent-handoff policy from censored teacher signals (TACIT-Switch 2608.27911). (3 names)opensmartroute.learning.implicit- Implicit feedback: outcomes inferred from the answer itself and from what the user does next. (5 names)opensmartroute.learning.kge- A learned link predictor for the knowledge graph (optional extratensorflowto train; numpy to use). (1 names)opensmartroute.learning.multiturn- Multi-turn routing with history-target joint embeddings (MTRouter 2604.23530). (3 names)opensmartroute.learning.neural- TensorFlow / Keras models that sharpen two things the router does on every request (optional extratensorflow). (7 names)opensmartroute.learning.personal- Few-shot personalisation (GMTRouter 2511.08590; SkillFeed 2608.28241). (4 names)opensmartroute.learning.policy_gradient- End-to-end policy-gradient routing (Router-R1 2506.09033; RLCascadeRouter 2608.15817). (4 names)opensmartroute.learning.quant- Weight quantisation for the routing SLM's model file. (5 names)opensmartroute.learning.self_improve- Self-improvement loop: refresh the catalogue, gather evidence, train a challenger, promote it only if better. (3 names)opensmartroute.learning.slm- The OpenSmartRoute routing SLM: a small, self-contained model that picks the target for a prompt. (16 names)opensmartroute.learning.window- The reading window of the routing SLM over a long prompt. (6 names)opensmartroute.math- Mathematical toolkit behind OpenSmartRoute's decisions. (46 names)opensmartroute.math.bandits- Multi-armed and contextual bandits for online routing decisions. (8 names)opensmartroute.math.calibration- Calibration and distribution-free risk control for routing confidence. (6 names)opensmartroute.math.decision- Multi-objective decision helpers and queueing theory for real-time routing. (9 names)opensmartroute.math.dirichlet- Dirichlet probe over host hidden states (ProbeDirichlet, RouterXBench 2602.11877). (2 names)opensmartroute.math.energy- Hardware-aware energy characterisation (HW-Router 2608.14575; 2608.28044). (3 names)opensmartroute.math.estimators- Streaming estimators, drift detection and calibration. (11 names)opensmartroute.math.irt- Item Response Theory for routing (IRT-Router, ACL 2025). (3 names)opensmartroute.math.markov- Markov chains and MDPs for conversational / multi-step routing. (2 names)opensmartroute.math.preference- Bradley–Terry pairwise preference model (RouteLLM, Prompt-to-Leaderboard). (2 names)opensmartroute.mcp_server- Model Context Protocol server: the router as a set of tools for any IDE or agent. (15 names)opensmartroute.media- Speech and image adapters for the OpenAI-compatible proxy (osr serveand the hosted platform). (20 names)opensmartroute.migrate- Import another gateway's configuration as a routing catalogue. (6 names)opensmartroute.observability- Tracing and observability: every step of routing, execution and learning as a structured event. (20 names)opensmartroute.ocm- Open Capability Manifest (OCM) - a vendor-neutral description of any routable capability. (12 names)opensmartroute.policy- Policy layer: hard constraints that are never traded off against utility. (20 names)opensmartroute.realtime- Real-time operational controls: health, circuit breaking, rate & budget limits. (11 names)opensmartroute.responses- OpenAI Responses API (POST /v1/responses) on top of the chat-completions proxy. (7 names)opensmartroute.retrieval- Retrieval-based candidate narrowing for very large target pools (ToolRet / Skill-RAG). (12 names)opensmartroute.router- The Router: signals -> policy -> strategies -> ensemble -> decision (+plan). (3 names)opensmartroute.sdk- OpenSmartRoute SDK: decorator-driven registration of routing components. (34 names)opensmartroute.security- Security controls for the routing control plane. (33 names)opensmartroute.security.gadget- Learned confounder-gadget detector (Rerouting LLM Routers, Shafran et al. 2025). (6 names)opensmartroute.security.injection- Instruction-injection detection for text that is not the user's request. (4 names)opensmartroute.security.limits- Resource-amplification limits ("Beyond Max Tokens"). (8 names)opensmartroute.security.moderation-POST /v1/moderationsover the router's own guards. (5 names)opensmartroute.security.output- Response-side guard: what a target answered is screened before it leaves the router. (8 names)opensmartroute.security.provenance- Origin (provenance) policy for tool parameters – ROPE-style control-flow integrity. (12 names)opensmartroute.security.safety- Safety-routing regression suite ("When Safety Routing Breaks"). (4 names)opensmartroute.server- Optional FastAPI server exposing the router over HTTP. (23 names)opensmartroute.settings- Typed, environment-overridable settings: the only home for OpenSmartRoute's tunable constants. (21 names)opensmartroute.signals- Signal extraction: cheap, deterministic features computed from the request. (50 names)opensmartroute.signals.corpus- Natural-language prompts per task type: how people actually ask, not how the ontology templates phrase it. (1 names)opensmartroute.signals.events- Event- and workflow-driven signals for agentic inputs. (7 names)opensmartroute.signals.models- Learned signal models: hashed n-gram linear models with no dependencies. (7 names)opensmartroute.signals.ontology- Task ontology: families -> types -> subtypes, with an orthogonal domain axis. (4 names)opensmartroute.signals.uncertainty- Uncertainty signals that come from outside the query text. (12 names)opensmartroute.stack- Declarative stacks: one document that describes a whole routing setup. (13 names)opensmartroute.strategies- see module (67 names)opensmartroute.strategies.aggregate- Routing / aggregation switch (Mixture-of-Agents, Wang et al. 2024; JiSi 2601.01330). (5 names)opensmartroute.strategies.auction- Error-aware reverse auction across providers (EA-RAM 2608.12719). (5 names)opensmartroute.strategies.bandit- Online-learning strategy: contextual Thompson-sampling bandit. (1 names)opensmartroute.strategies.base- Strategy interface. (3 names)opensmartroute.strategies.capability- Capability-fit strategy: match request signals to a target's declared capabilities. (3 names)opensmartroute.strategies.cascade- Cascade execution (FrugalGPT / Router-R1 multi-round / AutoMix POMDP). (5 names)opensmartroute.strategies.defer- Defer-to-human and effort ("think or not") strategies. (3 names)opensmartroute.strategies.edge- Edge-cloud token-aware routing (Pro-Router 2608.28726; RelayLLM 2601.05167). (1 names)opensmartroute.strategies.elastic- Token-budget-aware routing to elastic / many-in-one models (Nemotron Elastic 2511.16664; Star 2605.07182). (3 names)opensmartroute.strategies.escalation- Bayesian self-escalation during generation (2608.24087). (5 names)opensmartroute.strategies.human- Routing among human annotators and experts (QUORUM 2608.27974; Dawid-Skene 1979). (5 names)opensmartroute.strategies.llm_judge- Generative routing: let an LLM act as the router (Router-R1 / LLM-as-judge). (2 names)opensmartroute.strategies.memory- Memory-tier routing for agents (BudgetMem 2602.06025; Gated-Memory Routing 2609.00237). (5 names)opensmartroute.strategies.modality- Multimodal routing and modality escalation (LatentRouter 2605.11301; modality escalation. (4 names)opensmartroute.strategies.probe- Hidden-state routing with a Dirichlet probe (ProbeDirichlet, RouterXBench 2602.11877). (2 names)opensmartroute.strategies.progress- Agentic trajectories: per-step routing and multi-round execution. (5 names)opensmartroute.strategies.protocol- Collaboration-protocol selection (2608.14927). (7 names)opensmartroute.strategies.rules- Declarative rule-based routing (Arch-Router-style domain/action preferences). (2 names)opensmartroute.strategies.semantic_cache- Semantic caching as a routing target (GPTCache; vLLM semantic router 2603.04444). (4 names)opensmartroute.strategies.session- Session affinity: keep a conversation with the target that is already serving it. (2 names)opensmartroute.strategies.similarity- Similarity-based routing (UniRoute / GraphRouter flavour). (3 names)opensmartroute.strategies.speculative- Speculative (draft-based) cascades (speculative cascades, Narasimhan et al. 2024; Differential. (3 names)opensmartroute.strategies.spread- Weighted spread across interchangeable deployments (LiteLLM "simple-shuffle", OpenRouter provider weights). (1 names)opensmartroute.strategies.task_table- Static task table strategy (SCX Router, 2609.02292). (1 names)
opensmartroute
OpenSmartRoute — an open, intelligent route to the right decision, solution, or destination.
| Name | Kind | Summary |
|---|---|---|
APIError | re-export of opensmartroute.errors.APIError | The platform or osr serve answered a call with an error status; status, detail and the. |
AsyncRouter | re-export of opensmartroute.aio.AsyncRouter | await-able wrapper around a Router or EnterpriseRouter: route / learn / execute / run off the event loop. |
AuthenticationError | re-export of opensmartroute.errors.AuthenticationError | The CLI has no valid access token for the platform / server, or a sign-in was denied or timed out. |
BanditStrategy | re-export of opensmartroute.strategies.bandit.BanditStrategy | Thompson-sampling Beta bandit per (context, target); context = dominant domain (+ plan role). |
Capabilities | re-export of opensmartroute.core.types.Capabilities | Declarative description of what a target is good at. |
CapabilityStrategy | re-export of opensmartroute.strategies.capability.CapabilityStrategy | Declarative fit: domain / action overlap, complexity band, language, modality and quality prior. |
Cascade | re-export of opensmartroute.strategies.cascade.Cascade | Execute ranked targets in planner order (cheapest / MDP / POMDP), stopping when the quality gate passes. |
CascadePlanner | re-export of opensmartroute.strategies.cascade.CascadePlanner | Finite-horizon MDP over an ordered cascade with a stop action after each step. |
ComponentRegistry | re-export of opensmartroute.sdk.ComponentRegistry | Blueprints for every routing component, with decorators that register into it. |
ConfigurationError | re-export of opensmartroute.errors.ConfigurationError | Invalid catalogue, rules, SKILL.md, settings or a missing optional dependency. |
ContextEngineer | re-export of opensmartroute.knowledge.context.ContextEngineer | Builds the engineered context (module docstring). budget_tokens / max_facts / max_web_hits. |
ContextMiddleware | re-export of opensmartroute.knowledge.context.ContextMiddleware | Run the :class:ContextEngineer in front of every routed request and teach the graph from the traffic. |
DeferStrategy | re-export of opensmartroute.strategies.defer.DeferStrategy | Learning-to-defer: scores human targets by risk, PII, escalation intent, frustration and model uncertainty. |
EffortStrategy | re-export of opensmartroute.strategies.defer.EffortStrategy | Match a target's reasoning effort_level to signals.reasoning_need; penalise over- and under-thinking. |
Event | re-export of opensmartroute.observability.Event | One captured span or event: flat, JSON-friendly, never carries request text. |
EventSink | re-export of opensmartroute.observability.EventSink | Receiver port: override :meth:emit; live bridges may also implement :meth:span_start / :meth:span_end. |
ExecutionError | re-export of opensmartroute.errors.ExecutionError | A target handler failed while executing a plan. |
ExecutionResult | re-export of opensmartroute.execution.ExecutionResult | What happened when a decision was executed. |
ExecutionStep | re-export of opensmartroute.execution.ExecutionStep | One executed plan slot: role, target, latency and whether it succeeded. stage orders the steps. |
FeedbackStore | re-export of opensmartroute.feedback.FeedbackStore | Append-only :class:Outcome log (in memory or JSONL file) with per-target statistics. |
KnowledgeGraph | re-export of opensmartroute.knowledge.graph.KnowledgeGraph | Facts indexed three ways, upserted on their key, persisted as JSONL (see the module docstring). |
KnowledgeStrategy | re-export of opensmartroute.knowledge.context.KnowledgeStrategy | Scores candidates by what the graph knows worked on this kind of task: the performed_on facts of each. |
LLMJudgeStrategy | re-export of opensmartroute.strategies.llm_judge.LLMJudgeStrategy | LLM-as-router with optional score calibration. |
NoRouteError | re-export of opensmartroute.errors.NoRouteError | No target satisfied the hard constraints. |
Objective | re-export of opensmartroute.core.types.Objective | What the caller wants to optimise. Weights are relative. |
OpenSmartRoute | re-export of opensmartroute.client.OpenSmartRoute | A client for the platform (https://opensmartroute.ai or your own deployment) and for osr serve. |
OpenSmartRouteError | re-export of opensmartroute.errors.OpenSmartRouteError | Base class for all SDK errors. |
Outcome | re-export of opensmartroute.core.types.Outcome | Feedback about how a routed request actually went. |
PlanSlot | re-export of opensmartroute.core.types.PlanSlot | One filled slot of a multi-target plan (persona -> skill -> model). |
Policy | re-export of opensmartroute.policy.Policy | Ordered chain of :data:PolicyRule; returns the first rejection reason or None. |
ProgressRouter | re-export of opensmartroute.strategies.progress.ProgressRouter | Route each step of a task with trajectory context. |
RankedTarget | re-export of opensmartroute.core.types.RankedTarget | A scored candidate: utility, ensemble quality estimate and the per-strategy breakdown. |
RateLimitError | re-export of opensmartroute.errors.RateLimitError | 429: the rate limit, the monthly quota or a budget is exhausted; retry_after says when to try again. |
RemoteDecision | re-export of opensmartroute.client.RemoteDecision | What route() returns: the decision as the server sent it (raw) with the fields people read first. |
RequestConstraints | re-export of opensmartroute.core.types.RequestConstraints | Hard constraints on the request (never traded off). |
RouteDecision | re-export of opensmartroute.core.types.RouteDecision | The answer to route(): chosen target, confidence, alternatives, optional plan, trace and propensities. |
RoutePlan | re-export of opensmartroute.core.types.RoutePlan | A composed route (MasRouter-style): several targets working together, executed in stages. |
RouteRequest | re-export of opensmartroute.core.types.RouteRequest | The customer need. |
RouteTarget | re-export of opensmartroute.core.types.RouteTarget | A routable destination: an LLM, agent, skill, persona, tool, workflow or human. |
RouteTrace | re-export of opensmartroute.core.types.RouteTrace | Everything needed to explain a decision. |
Router | re-export of opensmartroute.router.Router | Signals -> policy -> strategies -> ensemble -> decision (+ optional plan). |
RouterSLM | re-export of opensmartroute.learning.slm.RouterSLM | Small routing model: dual encoder + target catalogue snapshot + calibration, in one JSON file. |
Rule | re-export of opensmartroute.strategies.rules.Rule | If all when conditions match, boost prefer targets and penalise avoid. |
RulesStrategy | re-export of opensmartroute.strategies.rules.RulesStrategy | Applies declarative :class:Rule preferences (prefer / avoid / pin) when their when conditions match. |
SLMStrategy | re-export of opensmartroute.learning.slm.SLMStrategy | Ensemble member backed by a :class:RouterSLM: scores are its probabilities, it keeps learning online. |
SecurityError | re-export of opensmartroute.errors.SecurityError | Request rejected by an input guard (prompt injection, oversize, etc.). |
SelfImprover | re-export of opensmartroute.learning.self_improve.SelfImprover | Closed loop that keeps a :class:RouterSLM current with the model market and its own traffic. |
Settings | re-export of opensmartroute.settings.Settings | All tunables, grouped by consumer. Immutable; derive variants with :meth:replace. |
Signals | re-export of opensmartroute.core.types.Signals | Cheap deterministic features extracted from a request. |
SimilarityStrategy | re-export of opensmartroute.strategies.similarity.SimilarityStrategy | Embed the request and each target's examples / description; score by best and top-k mean similarity. |
Span | re-export of opensmartroute.observability.Span | An open unit of work; a context manager that records duration, status and nested events. |
StateStoreError | re-export of opensmartroute.errors.StateStoreError | A learner-state store failed to load, save or migrate. |
Strategy | re-export of opensmartroute.strategies.base.Strategy | Scores each candidate target in [0, 1] and explains why. |
StrategyScore | re-export of opensmartroute.core.types.StrategyScore | One strategy's opinion about one target. |
TargetConstraints | re-export of opensmartroute.core.types.TargetConstraints | Where / for whom a target may be used. Checked by the policy layer. |
TargetKind | re-export of opensmartroute.core.types.TargetKind | Kinds of things a request can be routed to. |
TargetRegistry | re-export of opensmartroute.core.registry.TargetRegistry | In-memory catalogue of :class:RouteTarget by id: add / upsert / remove, filtered listing, (de)serialisation. |
TargetUnavailableError | re-export of opensmartroute.errors.TargetUnavailableError | A remote target or catalogue source could not be reached. |
TaskTableStrategy | re-export of opensmartroute.strategies.task_table.TaskTableStrategy | Static task_type -> target -> quality table with family and prior fallbacks; learns from outcomes. |
Tracer | re-export of opensmartroute.observability.Tracer | Opens spans, records events and fans them out to sinks; sample_rate < 1 traces a share of requests. |
ValidationError | re-export of opensmartroute.errors.ValidationError | A request, outcome or target failed validation. |
__version__ | constant | |
agent | re-export of opensmartroute.sdk.agent | @agent(id, ...): shorthand for an agent target. |
aroute | re-export of opensmartroute.sdk.aroute | await aroute(text): the async form of route(). |
arun | re-export of opensmartroute.sdk.arun | await arun(text): the async form of run(); coroutine handlers are awaited. |
components | re-export of opensmartroute.sdk.components | : The process-wide registry that the top-level decorators (opensmartroute.strategy ...) bind to. |
configure | re-export of opensmartroute.settings.configure | Install process-wide settings. configure() with no arguments re-reads the environment;. |
configure_tracing | re-export of opensmartroute.observability.configure_tracing | Install sinks on the process-wide tracer. With no sinks, use the ones named by settings. |
feedback | re-export of opensmartroute.sdk.feedback | feedback(decision, success=, quality=): learn from a decision in one call. |
get_settings | re-export of opensmartroute.settings.get_settings | The process-wide :class:Settings (environment overlay applied once, lazily). |
get_tracer | re-export of opensmartroute.observability.get_tracer | The process-wide tracer (disabled until :func:configure_tracing adds sinks). |
guard | re-export of opensmartroute.sdk.guard | @guard: fn(request) -> reason | RouteRequest | None runs before routing. |
handler | re-export of opensmartroute.sdk.handler | @handler(*target_ids): bind code to targets declared in a catalogue. |
human | re-export of opensmartroute.sdk.human | @human(id, ...): shorthand for a human target. |
llm | re-export of opensmartroute.sdk.llm | @llm(id, ...): shorthand for an llm target. |
load_rules | re-export of opensmartroute.config.load_rules | Load a rules file (top-level list or rules: key) into a :class:RulesStrategy. |
load_targets | re-export of opensmartroute.config.load_targets | Load a catalogue file (top-level list or targets: key) into a :class:TargetRegistry. |
middleware | re-export of opensmartroute.sdk.middleware | @middleware: register a Middleware class or fn(request, next_route). |
on_decision | re-export of opensmartroute.sdk.on_decision | @on_decision: fn(request, decision) after every route. |
on_error | re-export of opensmartroute.sdk.on_error | @on_error: fn(request, error) when a route fails. |
on_outcome | re-export of opensmartroute.sdk.on_outcome | @on_outcome: fn(outcome) for every outcome learned. |
persona | re-export of opensmartroute.sdk.persona | @persona(id, ...): shorthand for a slot-only persona target. |
policy_rule | re-export of opensmartroute.sdk.policy_rule | @policy_rule: register fn(target, request, signals) -> reason | None. |
route | re-export of opensmartroute.sdk.route | route(text): one request through the process-wide registry's router. |
rule | re-export of opensmartroute.sdk.rule | rule(name, prefer=, avoid=, pin=, **when) or @rule(...) over a predicate. |
run | re-export of opensmartroute.sdk.run | run(text): route + execute + learn through the process-wide registry. |
signal | re-export of opensmartroute.sdk.signal | @signal: register a SignalExtractor class or fn(request, signals) -> mapping | value. |
skill | re-export of opensmartroute.sdk.skill | @skill(id, ...): shorthand for a skill target. |
strategy | re-export of opensmartroute.sdk.strategy | @strategy(weight=, name=): register a Strategy class or fn(request, signals, candidates). |
target | re-export of opensmartroute.sdk.target | @target(id, kind, ...): the decorated callable becomes a RouteTarget handler. |
telemetry | re-export of opensmartroute.sdk.telemetry | @telemetry: register a Telemetry sink class or factory. |
tool | re-export of opensmartroute.sdk.tool | @tool(id, ...): shorthand for a tool target. |
opensmartroute.__main__
python -m opensmartroute ... is the osr command (IDE MCP configs, containers without the script on PATH).
No public names.
opensmartroute.adapters
Adapters connect OpenSmartRoute to real providers and infrastructure.
| Name | Kind | Summary |
|---|---|---|
AgentHarness | re-export of opensmartroute.adapters.harness.AgentHarness | Structural interface of an agent runtime: run(task, context=, history=) -> HarnessResult. |
AnthropicClient | re-export of opensmartroute.adapters.anthropic_client.AnthropicClient | The Messages API behind the :class:OpenAICompatClient surface: chat / stream_chat take. |
CallableHarness | re-export of opensmartroute.adapters.harness.CallableHarness | Wrap an in-process agent: fn(task, context, history) -> str | dict | HarnessResult. |
ChatResult | re-export of opensmartroute.adapters.openai_compat.ChatResult | Result of a chat completion: text, model, token counts, latency, tool calls, finish reason and raw response. |
HTTPHarness | re-export of opensmartroute.adapters.harness.HTTPHarness | POST the task as JSON to an agent endpoint. |
HarnessResult | re-export of opensmartroute.adapters.harness.HarnessResult | What an agent harness returns: text, success, token / cost / latency usage and optional self-graded quality. |
HttpMCPClient | re-export of opensmartroute.adapters.mcp.HttpMCPClient | Stdlib MCP client for the Streamable HTTP transport (POST <url> per JSON-RPC message). |
InMemoryQueue | re-export of opensmartroute.adapters.handlers.InMemoryQueue | Reference :class:Queue: FIFO in memory, resolves into :class:~opensmartroute.Outcome. |
Listing | re-export of opensmartroute.adapters.marketplace.Listing | A marketplace search hit (what GET /api/v1/registry returns per item). |
MarketplaceClient | re-export of opensmartroute.adapters.marketplace.MarketplaceClient | Search a marketplace and load its listings as routing targets. |
MarketplaceSync | re-export of opensmartroute.adapters.marketplace.MarketplaceSync | Keep a registry in step with the marketplace on a schedule (the osr serve side of the daily refresh). |
MockClient | re-export of opensmartroute.adapters.mock_client.MockClient | Deterministic in-process provider; see the module docstring for what it answers. |
ModelCard | re-export of opensmartroute.adapters.catalogue.ModelCard | What the catalogue knows about one model: identity, price, limits, evidence of quality, provenance. |
ModelCatalogue | re-export of opensmartroute.adapters.catalogue.ModelCatalogue | Merged, persisted model cards from every source; the SLM's view of the target universe. |
OpenAICompatClient | re-export of opensmartroute.adapters.openai_compat.OpenAICompatClient | Stdlib-only client for the OpenAI chat / embeddings API (OpenAI, Azure, vLLM, Ollama, LiteLLM) with retries. |
OpenTelemetrySink | re-export of opensmartroute.adapters.optional.OpenTelemetrySink | Live bridge from the tracer to OpenTelemetry: every OpenSmartRoute span becomes an OTel span. |
OpenTelemetryTelemetry | re-export of opensmartroute.adapters.optional.OpenTelemetryTelemetry | Emits one span per decision and counters/histograms via the OTel API. |
PendingResult | re-export of opensmartroute.adapters.handlers.PendingResult | Immediate answer of a queued target: the request was accepted and will be answered later. |
Queue | re-export of opensmartroute.adapters.handlers.Queue | Structural interface of an asynchronous queue target (ticketing, human tier, workflow run). |
QueuedItem | re-export of opensmartroute.adapters.handlers.QueuedItem | One request waiting in (or resolved from) a queue. |
SearchHit | re-export of opensmartroute.adapters.websearch.SearchHit | One search result: where it came from, what it says, and when it was seen. |
SemanticRouterImport | re-export of opensmartroute.adapters.semantic_router.SemanticRouterImport | Result of importing a vLLM semantic-router config: registry, rules, default model, categories, warnings. |
ServerCard | re-export of opensmartroute.adapters.mcp_servers.ServerCard | Description of an MCP server (tools, tags, auth, latency, cost, region, data boundary) for recommendation. |
ServerRecommendation | re-export of opensmartroute.adapters.mcp_servers.ServerRecommendation | A ranked server from recommend_servers with its fused score, rationale and matched tool names. |
StdioMCPClient | re-export of opensmartroute.adapters.mcp.StdioMCPClient | Tiny JSON-RPC-over-stdio MCP client (newline-delimited). Thread-safe, blocking. |
SubprocessHarness | re-export of opensmartroute.adapters.harness.SubprocessHarness | Run a CLI agent: task on stdin, answer on stdout, exit code 0 = success. |
SyncReport | re-export of opensmartroute.adapters.marketplace.SyncReport | What :meth:MarketplaceClient.sync did to a registry. |
WebKnowledge | re-export of opensmartroute.adapters.websearch.WebKnowledge | Fan a query out to search providers, de-duplicate by URL and cache the hits as JSON. |
a2a_handler | re-export of opensmartroute.adapters.a2a.a2a_handler | Return a handler that sends the request text to an A2A agent and returns its text. |
agent_from_card | re-export of opensmartroute.adapters.a2a.agent_from_card | Build an agent RouteTarget from an A2A agent card (name, skills, tags, input modes). |
attach_chat_handlers | re-export of opensmartroute.adapters.openai_compat.attach_chat_handlers | Give every LLM target a :func:chat_handler on client; returns the ids that got one. |
brave_search | re-export of opensmartroute.adapters.websearch.brave_search | Brave Search API web results; the key is read from BRAVE_API_KEY (or BRAVE_API_KEY_FILE). |
card_to_target | re-export of opensmartroute.adapters.catalogue.card_to_target | A :class:RouteTarget for a model card; risky third-party descriptions are replaced by the name. |
chat_handler | re-export of opensmartroute.adapters.openai_compat.chat_handler | Adapter for RouteTarget.handler: turns a RouteRequest into a chat call. |
connect_mcp | re-export of opensmartroute.adapters.mcp.connect_mcp | Spawn a stdio MCP server, list its tools (and optionally resources and prompts) and return. |
connect_mcp_http | re-export of opensmartroute.adapters.mcp.connect_mcp_http | Connect to a Streamable-HTTP MCP server, import its tools (and optionally resources and prompts) as. |
duckduckgo_search | re-export of opensmartroute.adapters.websearch.duckduckgo_search | DuckDuckGo instant-answer API (abstract + related topics). Keyless; shallow but good for definitions. |
embed_handler | re-export of opensmartroute.adapters.openai_compat.embed_handler | Adapter for an embeddings-capable RouteTarget.handler: embeds context["embeddings_input"] (or the text). |
embedder | re-export of opensmartroute.adapters.openai_compat.embedder | Adapter for SimilarityStrategy(embedder=...). |
enrich_description | re-export of opensmartroute.adapters.mcp.enrich_description | Return (routing_description, examples, capabilities) for a tool. |
fetch_agent_card | re-export of opensmartroute.adapters.a2a.fetch_agent_card | Download an agent card over HTTPS (plain HTTP is refused); raises TargetUnavailableError on failure. |
fetch_bytes | re-export of opensmartroute.adapters.websearch.fetch_bytes | GET url over https with a timeout and a body cap; transport errors become TargetUnavailableError. |
fetch_feed | re-export of opensmartroute.adapters.websearch.fetch_feed | Fetch an RSS / Atom feed over https and return its articles (see :func:parse_feed). |
fetch_huggingface_models | re-export of opensmartroute.adapters.catalogue.fetch_huggingface_models | Model cards from the Hugging Face Hub search (downloads, likes, tags, model-index benchmarks). |
fetch_json | re-export of opensmartroute.adapters.websearch.fetch_json | GET a JSON document (see :func:fetch_bytes); malformed bodies raise TargetUnavailableError. |
fetch_leaderboard_quality | re-export of opensmartroute.adapters.catalogue.fetch_leaderboard_quality | {hub model id: {benchmark: accuracy}} from the Open LLM Leaderboard table (official rows, unflagged). |
fetch_openrouter_models | re-export of opensmartroute.adapters.catalogue.fetch_openrouter_models | Model cards from OpenRouter's public listing (prices per token, context, modalities, tool support). |
fetch_page_text | re-export of opensmartroute.adapters.websearch.fetch_page_text | Fetch a page and return {url, title, text, risk}; risk is the injection/gadget risk of the text. |
harness_handler | re-export of opensmartroute.adapters.harness.harness_handler | Adapter for RouteTarget.handler: a RouteRequest becomes a harness task. |
html_to_text | re-export of opensmartroute.adapters.websearch.html_to_text | (title, text) of an HTML document with scripts/styles removed and whitespace collapsed. |
http_handler | re-export of opensmartroute.adapters.handlers.http_handler | RouteTarget.handler that POSTs the request to url and returns a :class:HarnessResult. |
huggingface_search | re-export of opensmartroute.adapters.websearch.huggingface_search | Search the Hugging Face Hub (what = models or datasets), ranked by downloads. No key needed. |
judge_fn | re-export of opensmartroute.adapters.openai_compat.judge_fn | Adapter for LLMJudgeStrategy(llm=...): prompt in, completion text out. |
langgraph_condition | re-export of opensmartroute.adapters.frameworks.langgraph_condition | Edge selector for add_conditional_edges: routes on target id (by='target') or kind. |
langgraph_node | re-export of opensmartroute.adapters.frameworks.langgraph_node | Return a LangGraph-compatible node state -> dict (partial state update). |
load_marketplace_targets | re-export of opensmartroute.adapters.marketplace.load_marketplace_targets | Shortcut: MarketplaceClient(base_url, api_key=api_key).targets(q, kind=kind, tag=tag, limit=limit). |
load_personas | re-export of opensmartroute.adapters.personas.load_personas | Load personas from a directory of markdown files or a JSON/JSONL/CSV catalogue. |
load_semantic_router_config | re-export of opensmartroute.adapters.semantic_router.load_semantic_router_config | Convert a vLLM semantic-router model_config / categories document into targets and rules. |
load_skill | re-export of opensmartroute.adapters.skills.load_skill | Load one skill directory (must contain SKILL.md). |
load_skills | re-export of opensmartroute.adapters.skills.load_skills | Load every */SKILL.md under root (one level deep, sorted by name). |
maf_router_executor | re-export of opensmartroute.adapters.frameworks.maf_router_executor | Agent Framework style: executor(message, ctx) -> target id | response; handoffs maps. |
manifest_from_targets | re-export of opensmartroute.adapters.mcp.manifest_from_targets | Reverse: dump MCP-shaped tool dicts (for signing / publishing a catalogue). |
mcp_server_handler | re-export of opensmartroute.adapters.mcp.mcp_server_handler | RouteTarget.handler for a target that stands for a whole remote MCP server (an mcp endpoint in an. |
mcp_tool_handler | re-export of opensmartroute.adapters.handlers.mcp_tool_handler | RouteTarget.handler that invokes one MCP tool via call(name, arguments). |
model_key | re-export of opensmartroute.adapters.catalogue.model_key | Vendor-agnostic key for matching model names across sources: lowercase, no vendor prefix, no punctuation. |
openai_tool_handler | re-export of opensmartroute.adapters.frameworks.openai_tool_handler | Callable behind openai_tool_spec: (text, objective?, kinds?) -> RouteDecision.to_dict(). |
openai_tool_spec | re-export of opensmartroute.adapters.frameworks.openai_tool_spec | OpenAI function-calling tool definition that lets a model ask the router for a target. |
parse_feed | re-export of opensmartroute.adapters.websearch.parse_feed | Articles of an RSS 2.0 / RDF / Atom document as kind="article" hits, newest first. |
persona_from_markdown | re-export of opensmartroute.adapters.personas.persona_from_markdown | Parse a *.agent.md / *.chatmode.md / front-matter markdown file into a persona target. |
persona_target | re-export of opensmartroute.adapters.personas.persona_target | Build a persona RouteTarget whose instructions is the system prompt (non-primary by default). |
personas_from_records | re-export of opensmartroute.adapters.personas.personas_from_records | Persona targets from JSON / CSV-style records (name + prompt/system keys); others skipped. |
prompts_from_mcp | re-export of opensmartroute.adapters.mcp.prompts_from_mcp | Convert prompts/list output into instructions-only skill targets (primary=False). |
quality_from_benchmarks | re-export of opensmartroute.adapters.catalogue.quality_from_benchmarks | Mean of normalised benchmark scores (percentages are divided by 100); None when there are none. |
quality_from_popularity | re-export of opensmartroute.adapters.catalogue.quality_from_popularity | Weak prior in [0.35, 0.75] from log-scaled downloads and likes (popularity is not quality; it is a hint). |
queue_handler | re-export of opensmartroute.adapters.handlers.queue_handler | RouteTarget.handler that enqueues the request and returns a :class:PendingResult. |
recommend_servers | re-export of opensmartroute.adapters.mcp_servers.recommend_servers | Rank MCP servers for a task; constraint violations are excluded, not down-weighted. |
resources_from_mcp | re-export of opensmartroute.adapters.mcp.resources_from_mcp | Convert resources/list output into read-only tool targets whose handler reads the resource. |
route_and_execute | re-export of opensmartroute.adapters.frameworks.route_and_execute | Route text and optionally execute the plan; returns (decision, ExecutionResult | None). |
searxng_search | re-export of opensmartroute.adapters.websearch.searxng_search | A self-hosted SearXNG instance (SEARXNG_URL or base_url; its JSON API must be enabled): real web. |
sentence_transformers_embedder | re-export of opensmartroute.adapters.optional.sentence_transformers_embedder | Semantic embedder for SimilarityStrategy. Requires opensmartroute[embeddings]. |
sign_manifest | re-export of opensmartroute.adapters.mcp.sign_manifest | Wrap a tool list in a signed manifest. algorithm = hmac-sha256 (key = shared. |
skill_from_markdown | re-export of opensmartroute.adapters.skills.skill_from_markdown | Parse one SKILL.md (Agent-Skills front matter + body) into a skill RouteTarget; strict validation. |
skills_from_card | re-export of opensmartroute.adapters.a2a.skills_from_card | One non-primary skill target per skill declared on an A2A agent card (<agent>/<skill>). |
tools_from_manifest | re-export of opensmartroute.adapters.mcp.tools_from_manifest | Import tools from a (signed) manifest; kw goes to :func:tools_from_mcp. |
tools_from_mcp | re-export of opensmartroute.adapters.mcp.tools_from_mcp | Convert tools/list output into targets. call(name, arguments) becomes the handler. |
verify_manifest | re-export of opensmartroute.adapters.mcp.verify_manifest | Constant-time verification. key = shared secret (HMAC) or 32-byte Ed25519 public key. |
wikipedia_search | re-export of opensmartroute.adapters.websearch.wikipedia_search | Wikipedia article search (MediaWiki API, no key): title, first snippet and the article URL. Encyclopaedic,. |
opensmartroute.adapters.a2a
Import A2A (Agent-to-Agent protocol) Agent Cards as TargetKind.AGENT targets.
| Name | Kind | Summary |
|---|---|---|
TERMINAL_TASK_STATES | constant | : A2A task states after which no more work happens (tasks/get polling stops). |
a2a_handler | function (url: str, token: str | None=None, timeout_s: float=60.0, method: str='message/send', poll_interval_s: float=1.0) | Return a handler that sends the request text to an A2A agent and returns its text. |
agent_from_card | function (card: dict[str, Any], *, call: Callable[[str, RouteRequest], Any] | None=None, cost_per_1k_tokens: float=0.0, latency_ms: float=2000.0, quality_prior: float=0.65, languages: list[str] | None=None) | Build an agent RouteTarget from an A2A agent card (name, skills, tags, input modes). |
fetch_agent_card | function (base_url: str, timeout_s: float=10.0, path: str='/.well-known/agent.json') | Download an agent card over HTTPS (plain HTTP is refused); raises TargetUnavailableError on failure. |
skills_from_card | function (card: dict[str, Any], agent_id: str | None=None) | One non-primary skill target per skill declared on an A2A agent card (<agent>/<skill>). |
opensmartroute.adapters.anthropic_client
Native Anthropic Messages API client - route TO Claude, not only accept Claude-dialect requests.
| Name | Kind | Summary |
|---|---|---|
ANTHROPIC_VERSION | constant | : The API version header every request carries (the newest stable revision the translation targets). |
CACHE_MAX_BREAKPOINTS | constant | : Breakpoints the Messages API accepts per request. |
CACHE_MIN_CHARS | constant | : cache breakpoint is worth placing on it; tools and the conversation prefix are marked whenever they exist. |
DEFAULT_MAX_TOKENS | constant | : The Messages API requires max_tokens; used when neither the caller nor the proxy set one. |
THINKING_BUDGETS | constant | : Extended-thinking budgets per reasoning_effort value. |
AnthropicClient | class | The Messages API behind the :class:OpenAICompatClient surface: chat / stream_chat take. |
cache_breakpoints | function (body: dict[str, Any]) | Place Anthropic prompt-cache breakpoints on a Messages body the caller sent without any: the last tool. |
to_messages_request | function (messages: list[dict[str, Any]], model: str, *, temperature: float=0.0, max_tokens: int | None=None, **kw: Any) | A chat-completions call as a Messages API body (see the module docstring for the mapping). |
opensmartroute.adapters.catalogue
Live model catalogue: collect model cards (price, context, modalities, benchmarks) from public sources.
| Name | Kind | Summary |
|---|---|---|
LEADERBOARD_DATASET | constant | Open LLM Leaderboard v2 results table on the Hub. |
OPENROUTER_MODELS | constant | public model + pricing listing (no key). |
ModelCard | class | What the catalogue knows about one model: identity, price, limits, evidence of quality, provenance. |
ModelCatalogue | class | Merged, persisted model cards from every source; the SLM's view of the target universe. |
card_to_target | function (card: ModelCard, *, default_latency_ms: float=1500.0, settings: Settings | None=None) | A :class:RouteTarget for a model card; risky third-party descriptions are replaced by the name. |
fetch_huggingface_models | function (query: str='', *, limit: int=50, pipeline: str='text-generation', timeout_s: float | None=None, settings: Settings | None=None) | Model cards from the Hugging Face Hub search (downloads, likes, tags, model-index benchmarks). |
fetch_leaderboard_quality | function (*, limit: int=5000, dataset: str=LEADERBOARD_DATASET, timeout_s: float | None=None, settings: Settings | None=None) | {hub model id: {benchmark: accuracy}} from the Open LLM Leaderboard table (official rows, unflagged). |
fetch_openrouter_models | function (*, url: str=OPENROUTER_MODELS, timeout_s: float | None=None, settings: Settings | None=None) | Model cards from OpenRouter's public listing (prices per token, context, modalities, tool support). |
model_key | function (model_id: str) | Vendor-agnostic key for matching model names across sources: lowercase, no vendor prefix, no punctuation. |
quality_from_benchmarks | function (benchmarks: dict[str, float]) | Mean of normalised benchmark scores (percentages are divided by 100); None when there are none. |
quality_from_popularity | function (downloads: int, likes: int) | Weak prior in [0.35, 0.75] from log-scaled downloads and likes (popularity is not quality; it is a hint). |
opensmartroute.adapters.frameworks
Drop-in nodes for agent frameworks.
| Name | Kind | Summary |
|---|---|---|
langgraph_condition | function (by: str='target', default: str='__end__') | Edge selector for add_conditional_edges: routes on target id (by='target') or kind. |
langgraph_node | function (router: Router, *, execute: bool=False, plan: bool=False, context_key: str='route_context', on_no_route: str='__no_route__') | Return a LangGraph-compatible node state -> dict (partial state update). |
last_user_text | function (state: dict[str, Any]) | (last user utterance, prior history as role/content dicts). |
maf_router_executor | function (router: Router, *, execute: bool=False) | Agent Framework style: executor(message, ctx) -> target id | response; handoffs maps. |
openai_tool_handler | function (router: Router) | Callable behind openai_tool_spec: (text, objective?, kinds?) -> RouteDecision.to_dict(). |
openai_tool_spec | function (name: str='route_request') | OpenAI function-calling tool definition that lets a model ask the router for a target. |
route_and_execute | function (router: Router, text: str, *, history: list[dict[str, str]] | None=None, context: dict[str, Any] | None=None, objective: Objective | None=None, execute: bool=False, plan: bool=False, learn: bool=True) | Route text and optionally execute the plan; returns (decision, ExecutionResult | None). |
opensmartroute.adapters.handlers
Executors for non-LLM targets: HTTP endpoints, MCP tools and asynchronous queues.
| Name | Kind | Summary |
|---|---|---|
InMemoryQueue | class | Reference :class:Queue: FIFO in memory, resolves into :class:~opensmartroute.Outcome. |
PendingResult | class | Immediate answer of a queued target: the request was accepted and will be answered later. |
Queue | class | Structural interface of an asynchronous queue target (ticketing, human tier, workflow run). |
QueuedItem | class | One request waiting in (or resolved from) a queue. |
http_handler | function (url: str, *, api_key: str | None=None, api_key_env: str | None=None, timeout_s: float=300.0, headers: Mapping[str, str] | None=None, payload: Callable[[str, Mapping[str, Any], list[dict[str, str]]], dict[str, Any]] | None=None, body: Mapping[str, Any] | None=None) | RouteTarget.handler that POSTs the request to url and returns a :class:HarnessResult. |
mcp_tool_handler | function (call: Callable[[str, dict[str, Any]], Any], tool: str, input_schema: dict[str, Any] | None=None, arguments: Callable[[RouteRequest], dict[str, Any]] | None=None) | RouteTarget.handler that invokes one MCP tool via call(name, arguments). |
queue_handler | function (queue: Queue, target_id: str | None=None) | RouteTarget.handler that enqueues the request and returns a :class:PendingResult. |
opensmartroute.adapters.harness
Agent-harness adapters: route to a runtime, not just a model.
| Name | Kind | Summary |
|---|---|---|
AgentHarness | class | Structural interface of an agent runtime: run(task, context=, history=) -> HarnessResult. |
CallableHarness | class | Wrap an in-process agent: fn(task, context, history) -> str | dict | HarnessResult. |
HTTPHarness | class | POST the task as JSON to an agent endpoint. |
HarnessResult | class | What an agent harness returns: text, success, token / cost / latency usage and optional self-graded quality. |
SubprocessHarness | class | Run a CLI agent: task on stdin, answer on stdout, exit code 0 = success. |
coerce_result | function (out: Any) | Normalise str | dict | HarnessResult | object-with-text into a HarnessResult. |
harness_handler | function (harness: AgentHarness) | Adapter for RouteTarget.handler: a RouteRequest becomes a harness task. |
opensmartroute.adapters.marketplace
Pull skills, agents, tools and templates from an OpenSmartRoute marketplace into a router.
| Name | Kind | Summary |
|---|---|---|
DEFAULT_MARKETPLACE | constant | the hosted marketplace API. |
LISTING_KINDS | constant | : Listing kinds the marketplace catalogue knows (search filter values). |
ROUTABLE_KINDS | constant | : Listing kinds whose manifest is an Open Capability Manifest the router can load as a target. |
Listing | class | A marketplace search hit (what GET /api/v1/registry returns per item). |
MarketplaceClient | class | Search a marketplace and load its listings as routing targets. |
MarketplaceSync | class | Keep a registry in step with the marketplace on a schedule (the osr serve side of the daily refresh). |
SyncReport | class | What :meth:MarketplaceClient.sync did to a registry. |
load_marketplace_targets | function (base_url: str=DEFAULT_MARKETPLACE, q: str='', *, kind: str | None=None, tag: str | None=None, limit: int=24, api_key: str | None=None) | Shortcut: MarketplaceClient(base_url, api_key=api_key).targets(q, kind=kind, tag=tag, limit=limit). |
opensmartroute.adapters.mcp
Import MCP (Model Context Protocol) tools as TargetKind.TOOL targets.
| Name | Kind | Summary |
|---|---|---|
HttpMCPClient | class | Stdlib MCP client for the Streamable HTTP transport (POST <url> per JSON-RPC message). |
MCPTool | class | A tool as listed by an MCP server: name, description, JSON input schema and annotations. |
StdioMCPClient | class | Tiny JSON-RPC-over-stdio MCP client (newline-delimited). Thread-safe, blocking. |
canonical_json | function (obj: Any) | Deterministic JSON encoding (sorted keys, no whitespace) used for manifest digests and signatures. |
connect_mcp | function (command: list[str], server: str='', *, resources: bool=False, prompts: bool=False, **kw: Any) | Spawn a stdio MCP server, list its tools (and optionally resources and prompts) and return. |
connect_mcp_http | function (url: str, api_key: str | None=None, server: str='', *, resources: bool=False, prompts: bool=False, timeout_s: float=60.0, **kw: Any) | Connect to a Streamable-HTTP MCP server, import its tools (and optionally resources and prompts) as. |
enrich_description | function (name: str, description: str, input_schema: dict[str, Any] | None, server: str='', enricher: Callable[[str], list[str]] | None=None) | Return (routing_description, examples, capabilities) for a tool. |
manifest_digest | function (tools: list[dict[str, Any]]) | SHA-256 hex digest of a tool list in canonical JSON. |
manifest_from_targets | function (targets: Iterable[RouteTarget]) | Reverse: dump MCP-shaped tool dicts (for signing / publishing a catalogue). |
prompts_from_mcp | function (payload: Any, server: str='', get: Callable[[str, dict[str, Any]], Any] | None=None, *, quality_prior: float=0.6) | Convert prompts/list output into instructions-only skill targets (primary=False). |
resources_from_mcp | function (payload: Any, server: str='', read: Callable[[str], Any] | None=None, *, latency_ms: float=200.0, quality_prior: float=0.6) | Convert resources/list output into read-only tool targets whose handler reads the resource. |
sign_manifest | function (tools: list[dict[str, Any]], key: bytes, *, server: str='', algorithm: str='hmac-sha256', key_id: str='') | Wrap a tool list in a signed manifest. algorithm = hmac-sha256 (key = shared. |
tools_from_manifest | function (manifest: dict[str, Any], key: bytes | None, *, require_signature: bool=True, max_age_s: float | None=None, **kw: Any) | Import tools from a (signed) manifest; kw goes to :func:tools_from_mcp. |
tools_from_mcp | function (payload: Any, server: str='', call: Callable[[str, dict[str, Any]], Any] | None=None, enricher: Callable[[str], list[str]] | None=None, cost_per_call_usd: float=0.0, latency_ms: float=300.0, quality_prior: float=0.6, max_description_risk: float=0.6, guard: InputGuard | None=None) | Convert tools/list output into targets. call(name, arguments) becomes the handler. |
verify_manifest | function (manifest: dict[str, Any], key: bytes, max_age_s: float | None=None) | Constant-time verification. key = shared secret (HMAC) or 32-byte Ed25519 public key. |
opensmartroute.adapters.mcp_servers
MCP server recommendation (MCP-Zero 2506.01056; ToolRet 2603.06467).
| Name | Kind | Summary |
|---|---|---|
ServerCard | class | Description of an MCP server (tools, tags, auth, latency, cost, region, data boundary) for recommendation. |
ServerRecommendation | class | A ranked server from recommend_servers with its fused score, rationale and matched tool names. |
recommend_servers | function (request: RouteRequest | str, servers: Iterable[ServerCard | dict[str, Any]], k: int=3, constraints: RequestConstraints | None=None, allowed_auth: Iterable[str] | None=None, min_score: float=0.0) | Rank MCP servers for a task; constraint violations are excluded, not down-weighted. |
opensmartroute.adapters.mock_client
A provider that answers deterministically without a network: the mock provider kind.
| Name | Kind | Summary |
|---|---|---|
MOCK_SCHEME | constant | a base URL that selects this client. |
MockClient | class | Deterministic in-process provider; see the module docstring for what it answers. |
is_mock | function (kind: str | None, base_url: str | None) | True when a provider spec selects the mock client (kind: mock or a mock:// base URL). |
opensmartroute.adapters.openai_compat
OpenAI-compatible HTTP client (stdlib only).
| Name | Kind | Summary |
|---|---|---|
PASSTHROUGH_FIELDS | constant | Chat-completion fields the proxy passes through to the upstream untouched (request.context["openai"]). |
UPSTREAM_REQUEST_ID_HEADERS | constant | : Response headers providers use for their own request id, in the order they are looked up. |
ChatResult | class | Result of a chat completion: text, model, token counts, latency, tool calls, finish reason and raw response. |
OpenAICompatClient | class | Stdlib-only client for the OpenAI chat / embeddings API (OpenAI, Azure, vLLM, Ollama, LiteLLM) with retries. |
attach_chat_handlers | function (targets: Iterable[Any], client: OpenAICompatClient, *, model_key: str='model', default_model: str | None=None, overwrite: bool=False) | Give every LLM target a :func:chat_handler on client; returns the ids that got one. |
chat_handler | function (client: OpenAICompatClient, model: str, system_prompt: str | None=None, **defaults: Any) | Adapter for RouteTarget.handler: turns a RouteRequest into a chat call. |
embed_handler | function (client: OpenAICompatClient, model: str) | Adapter for an embeddings-capable RouteTarget.handler: embeds context["embeddings_input"] (or the text). |
embedder | function (client: OpenAICompatClient, model: str, batch: int=64) | Adapter for SimilarityStrategy(embedder=...). |
judge_fn | function (client: OpenAICompatClient, model: str, max_tokens: int=400) | Adapter for LLMJudgeStrategy(llm=...): prompt in, completion text out. |
upstream_request_id | function (headers: Any) | The provider's request id from a response's headers (:data:UPSTREAM_REQUEST_ID_HEADERS), or None. |
opensmartroute.adapters.optional
Optional adapters that need extra dependencies. Everything is lazily imported so the.
| Name | Kind | Summary |
|---|---|---|
OpenTelemetrySink | class | Live bridge from the tracer to OpenTelemetry: every OpenSmartRoute span becomes an OTel span. |
OpenTelemetryTelemetry | class | Emits one span per decision and counters/histograms via the OTel API. |
sentence_transformers_embedder | function (model_name: str='sentence-transformers/all-MiniLM-L6-v2', device: str | None=None, normalize: bool=True) | Semantic embedder for SimilarityStrategy. Requires opensmartroute[embeddings]. |
opensmartroute.adapters.personas
Import persona catalogues as TargetKind.PERSONA targets.
| Name | Kind | Summary |
|---|---|---|
load_personas | function (path: str | Path, **kw: Any) | Load personas from a directory of markdown files or a JSON/JSONL/CSV catalogue. |
persona_from_markdown | function (text: str, *, path: Path | None=None, **kw: Any) | Parse a *.agent.md / *.chatmode.md / front-matter markdown file into a persona target. |
persona_target | function (name: str, prompt: str, description: str='', *, id_prefix: str='persona:', domains: list[str] | None=None, tags: list[str] | None=None, languages: list[str] | None=None, primary: bool=False, quality_prior: float=0.6, source: str='', extra: dict[str, Any] | None=None) | Build a persona RouteTarget whose instructions is the system prompt (non-primary by default). |
personas_from_records | function (records: Iterable[dict[str, Any]], **kw: Any) | Persona targets from JSON / CSV-style records (name + prompt/system keys); others skipped. |
opensmartroute.adapters.semantic_router
Import a vLLM semantic-router configuration (vllm-project/semantic-router).
| Name | Kind | Summary |
|---|---|---|
DEFAULT_DOMAIN_MAP | constant | semantic-router's MMLU-style categories -> OpenSmartRoute ontology domains. |
SemanticRouterImport | class | Result of importing a vLLM semantic-router config: registry, rules, default model, categories, warnings. |
load_semantic_router_config | function (source: str | Path | dict[str, Any], domain_map: dict[str, list[str]] | None=None, rule_weight: float=0.8) | Convert a vLLM semantic-router model_config / categories document into targets and rules. |
opensmartroute.adapters.skills
Load Agent-Skills SKILL.md packages as TargetKind.SKILL targets.
| Name | Kind | Summary |
|---|---|---|
load_skill | function (skill_dir: str | Path, **kw: Any) | Load one skill directory (must contain SKILL.md). |
load_skills | function (root: str | Path, **kw: Any) | Load every */SKILL.md under root (one level deep, sorted by name). |
parse_frontmatter | function (text: str) | Split --- frontmatter from the body. Returns (frontmatter, body). |
skill_from_markdown | function (text: str, *, path: Path | None=None, cost_per_1k_tokens: float=0.0) | Parse one SKILL.md (Agent-Skills front matter + body) into a skill RouteTarget; strict validation. |
opensmartroute.adapters.websearch
Web knowledge for the self-improving router: stdlib HTTP fetch, search providers, page text.
| Name | Kind | Summary |
|---|---|---|
BRAVE_API | constant | Brave web search (needs BRAVE_API_KEY). |
DATASETS_SERVER | constant | Hugging Face datasets-server REST root (/rows). |
DDG_API | constant | DuckDuckGo instant-answer JSON endpoint (no key). |
HF_API | constant | Hugging Face Hub REST root (models, datasets, search). |
SEARXNG_URL_ENV | constant | base URL of a self-hosted SearXNG instance (JSON API); registers the provider. |
WIKIPEDIA_API | constant | MediaWiki search API (no key; lang = edition). |
SearchHit | class | One search result: where it came from, what it says, and when it was seen. |
SearchProvider | constant | (query, limit) -> hits. |
WebKnowledge | class | Fan a query out to search providers, de-duplicate by URL and cache the hits as JSON. |
brave_search | function (query: str, limit: int=10, *, api_key_env: str='BRAVE_API_KEY', timeout_s: float | None=None, settings: Settings | None=None) | Brave Search API web results; the key is read from BRAVE_API_KEY (or BRAVE_API_KEY_FILE). |
duckduckgo_search | function (query: str, limit: int=10, *, timeout_s: float | None=None, settings: Settings | None=None) | DuckDuckGo instant-answer API (abstract + related topics). Keyless; shallow but good for definitions. |
fetch_bytes | function (url: str, *, timeout_s: float | None=None, max_bytes: int | None=None, headers: Mapping[str, str] | None=None, settings: Settings | None=None) | GET url over https with a timeout and a body cap; transport errors become TargetUnavailableError. |
fetch_feed | function (url: str, *, max_entries: int | None=None, settings: Settings | None=None) | Fetch an RSS / Atom feed over https and return its articles (see :func:parse_feed). |
fetch_json | function (url: str, *, timeout_s: float | None=None, headers: Mapping[str, str] | None=None, settings: Settings | None=None) | GET a JSON document (see :func:fetch_bytes); malformed bodies raise TargetUnavailableError. |
fetch_page_text | function (url: str, *, max_chars: int=20000, timeout_s: float | None=None, settings: Settings | None=None) | Fetch a page and return {url, title, text, risk}; risk is the injection/gadget risk of the text. |
html_to_text | function (html: str) | (title, text) of an HTML document with scripts/styles removed and whitespace collapsed. |
huggingface_search | function (query: str, limit: int=10, *, what: str='models', pipeline_tag: str | None='text-generation', timeout_s: float | None=None, settings: Settings | None=None) | Search the Hugging Face Hub (what = models or datasets), ranked by downloads. No key needed. |
parse_feed | function (data: bytes | str, *, source: str='feed', max_entries: int=50) | Articles of an RSS 2.0 / RDF / Atom document as kind="article" hits, newest first. |
searxng_search | function (query: str, limit: int=10, *, base_url: str | None=None, timeout_s: float | None=None, settings: Settings | None=None) | A self-hosted SearXNG instance (SEARXNG_URL or base_url; its JSON API must be enabled): real web. |
wikipedia_search | function (query: str, limit: int=10, *, lang: str='en', timeout_s: float | None=None, settings: Settings | None=None) | Wikipedia article search (MediaWiki API, no key): title, first snippet and the article URL. Encyclopaedic,. |
opensmartroute.agents
osr run <agent>: launch a coding agent or AI client with the router as its model endpoint.
| Name | Kind | Summary |
|---|---|---|
AGENTS | constant | the coding agents osr run knows how to launch, in menu order. |
Agent | class | One tool the router can sit behind, and how it is told where to go. |
agent_environment | function (agent: Agent, base_url: str, key: str, model: str='auto') | The variables to set for agent (without launching anything - what --print-env shows). |
find_agent | function (agent_id: str) | Return the agent with this id; ConfigurationError names the known ids when there is none. |
launch | function (agent: Agent, base_url: str, key: str, extra_args: list[str], *, model: str='auto', environ: dict[str, str] | None=None, execvpe: Any=None) | Replace this process with the agent's command, the router wired in through the environment. |
opensmartroute.aio
Async façade. Routing itself is CPU-bound and sub-millisecond, so we run it in.
| Name | Kind | Summary |
|---|---|---|
AsyncRouter | class | await-able wrapper around a Router or EnterpriseRouter: route / learn / execute / run off the event loop. |
opensmartroute.anthropic
Anthropic Messages API (POST /v1/messages) on top of the chat-completions proxy.
| Name | Kind | Summary |
|---|---|---|
ERROR_TYPES | constant | : HTTP status -> Anthropic error type. |
MESSAGE_ROLES | constant | : Messages role values (Anthropic has no system role - system is a top-level field). |
STOP_REASONS | constant | : finish_reason of a chat completion -> Messages stop_reason. |
MessageStreamTranslator | class | Push-based translation of chat.completion.chunk SSE bytes into Messages API streaming events. |
chat_to_message | function (completion: dict[str, Any], request: dict[str, Any] | None=None) | Shape a finished chat.completion as an Anthropic message object. |
count_tokens | function (body: dict[str, Any], estimator: Any=None) | POST /v1/messages/count_tokens: {"input_tokens": n} for system + messages + tools. |
error_body | function (status: int, message: str, *, kind: str | None=None) | The {"type": "error", "error": {"type", "message"}} envelope of the Messages API. |
message_events | function (events: Iterable[bytes], request: dict[str, Any] | None=None) | Translate a chat.completion.chunk SSE byte stream into Messages API streaming events. |
messages_to_chat | function (body: dict[str, Any], *, default_model: str='auto') | Translate an Anthropic Messages request body into a chat.completion request body. |
opensmartroute.branding
OpenSmartRoute naming conventions: one place for every brand-bound identifier.
| Name | Kind | Summary |
|---|---|---|
API_KEY_ENV | constant | OSR_API_KEY - access token the CLI sends (overrides the credentials file). |
API_URL_ENV | constant | OSR_API_URL - platform / server URL the CLI talks to. |
BRAND | constant | product name, one word. |
CLI | constant | console script name. |
CONFIG_DIR_ENV | constant | OSR_CONFIG_DIR - overrides the per-user config folder. |
CONFIG_DIR_NAME | constant | per-user config folder name (~/.config/opensmartroute, %APPDATA%\opensmartroute). |
ENTRY_POINT_GROUP | constant | importlib.metadata entry-point group for plugins. |
ENV_PREFIX | constant | OSR_ - every settings environment variable starts with this. |
ERROR_CODE_PREFIX | constant | OSR_ - machine-readable error codes (OSR_NO_ROUTE). |
INSTALL_SCRIPT_PS1 | constant | Windows installer: irm .../install.ps1 | iex. |
INSTALL_SCRIPT_SH | constant | Linux / macOS installer: curl -fsSL .../install.sh | sh. |
LOCAL_TOKEN_PREFIX | constant | self-hosted osr serve access tokens (osr_local_...). |
MARKETPLACE_URL | constant | hosted marketplace API (osr marketplace, MarketplaceClient). |
METADATA_PREFIX | constant | osr- - SKILL.md / persona front-matter keys (osr-domains). |
PACKAGE | constant | Python package / distribution / logger root. |
REPOSITORY | constant | public home of the release files (installers, bundles); the source repository is private. |
SHORT_NAME | constant | short form used for env-var and error-code prefixes. |
SKILLS_DIR | constant | : Default Agent-Skills root (*/SKILL.md); the location Claude Code discovers project skills in. |
STATE_DIR | constant | default learner-state directory. |
TOKEN_PREFIX | constant | hosted-platform API keys (osr_live_...). |
WEBSITE | constant | public website; also the default hosted-platform URL of osr login. |
env_key | function (*parts: str) | env_key("routing", "softmax_temperature") -> "OSR_ROUTING_SOFTMAX_TEMPERATURE". |
error_code | function (kind: str) | error_code("no_route") -> "OSR_NO_ROUTE". |
logger | function (component: str | None=None) | logger() -> "opensmartroute"; logger("enterprise") -> "opensmartroute.enterprise". |
metadata_key | function (field: str) | metadata_key("quality_prior") -> "osr-quality-prior" (SKILL.md / persona frontmatter). |
platform_url | function (environ: Mapping[str, str] | None=None) | The platform / server URL the CLI talks to: OSR_API_URL or the hosted platform (:data:WEBSITE). |
user_agent | function () | "opensmartroute/<version>" for outbound HTTP clients. |
version | function () | The package version (opensmartroute.__version__), resolved at call time. |
opensmartroute.cli
osr command-line interface.
| Name | Kind | Summary |
|---|---|---|
STARTER_COMMANDS | constant | work without --targets (starter catalogue). |
build_router | function (targets: str | None, rules: str | None=None, state: str | None=None, models: str | None=None, skills: str | None=None, slm: str | None=None, remember_requests: int=0) | Assemble the CLI's router from targets / rules / state / models / SKILL.md / SLM paths (every command). |
EXTRAS | constant | Optional extras -> the modules they install; osr doctor reports which are present without importing them. |
doctor_report | function (targets: str | None=None, rules: str | None=None, profile: str='default') | What osr doctor prints: interpreter, package, extras, bundled model, config dir, sign-in, catalogue. |
main | function (argv: list[str] | None=None) | Entry point of the osr console script; returns the process exit status. |
opensmartroute.client
Client for the hosted platform and a self-hosted osr serve: route, quote, report, chat - standard library only.
| Name | Kind | Summary |
|---|---|---|
AUTO_MODEL | constant | the model name that lets the router choose on the OpenAI-compatible endpoint. |
PLATFORM_API_PREFIX | constant | where the REST routes live on the platform; osr serve has them at the root. |
PRIVATE_HOST_SUFFIXES | constant | : Host-name suffixes that mean "inside the network": a key may travel to them over plain http. |
RETRY_STATUSES | constant | answers that are safe to retry (nothing was served). |
SERVER_API_PREFIX | constant | the prefix an osr_local_... token selects. |
HttpResponse | constant | : What the transport returns: status, response headers, raw body (or an iterator of lines when streaming). |
OpenSmartRoute | class | A client for the platform (https://opensmartroute.ai or your own deployment) and for osr serve. |
RemoteDecision | class | What route() returns: the decision as the server sent it (raw) with the fields people read first. |
Transport | constant | : iterator of raw lines when stream is true. Tests inject a fake; the default is urllib. |
is_private_host | function (host: str) | True for loopback and private addresses and for names that only resolve inside a network (no dot,. |
opensmartroute.compress
Prompt compaction: fewer tokens into the model without changing what it is asked.
| Name | Kind | Summary |
|---|---|---|
TOKENS_SAVED_KEY | constant | context key carrying the estimated saving (ExecutionResult.tokens_saved, proxy). |
compact_text | function (text: str, *, dedupe_lines: bool=True, max_blank_lines: int=1, min_dedupe_chars: int=24) | Whitespace- and repetition-compacted text; fenced code blocks are returned untouched. |
compress_request | function (request: RouteRequest, settings: Settings | None=None) | (request, tokens_saved): text, history and context["system"] compacted per CompressionSettings. |
trim_history | function (history: list[dict[str, Any]], budget_tokens: int, *, keep_last_turns: int=2) | history with the oldest non-system turns dropped until it fits budget_tokens (0 = unchanged). |
opensmartroute.config
Configuration loading: targets and rules from JSON or YAML.
| Name | Kind | Summary |
|---|---|---|
load_document | function (path: str | Path) | Read a JSON or YAML file (YAML needs the yaml extra); raises ConfigurationError on any problem. |
load_rules | function (path: str | Path) | Load a rules file (top-level list or rules: key) into a :class:RulesStrategy. |
load_targets | function (path: str | Path) | Load a catalogue file (top-level list or targets: key) into a :class:TargetRegistry. |
opensmartroute.core
| Name | Kind | Summary |
|---|---|---|
PLAN_MODES | re-export of opensmartroute.core.types.PLAN_MODES | : merges their outputs in slot order, and calls the tools of one round concurrently. |
Capabilities | re-export of opensmartroute.core.types.Capabilities | Declarative description of what a target is good at. |
Objective | re-export of opensmartroute.core.types.Objective | What the caller wants to optimise. Weights are relative. |
Outcome | re-export of opensmartroute.core.types.Outcome | Feedback about how a routed request actually went. |
PlanSlot | re-export of opensmartroute.core.types.PlanSlot | One filled slot of a multi-target plan (persona -> skill -> model). |
RankedTarget | re-export of opensmartroute.core.types.RankedTarget | A scored candidate: utility, ensemble quality estimate and the per-strategy breakdown. |
RequestConstraints | re-export of opensmartroute.core.types.RequestConstraints | Hard constraints on the request (never traded off). |
RouteDecision | re-export of opensmartroute.core.types.RouteDecision | The answer to route(): chosen target, confidence, alternatives, optional plan, trace and propensities. |
RoutePlan | re-export of opensmartroute.core.types.RoutePlan | A composed route (MasRouter-style): several targets working together, executed in stages. |
RouteRequest | re-export of opensmartroute.core.types.RouteRequest | The customer need. |
RouteTarget | re-export of opensmartroute.core.types.RouteTarget | A routable destination: an LLM, agent, skill, persona, tool, workflow or human. |
RouteTrace | re-export of opensmartroute.core.types.RouteTrace | Everything needed to explain a decision. |
Signals | re-export of opensmartroute.core.types.Signals | Cheap deterministic features extracted from a request. |
StrategyScore | re-export of opensmartroute.core.types.StrategyScore | One strategy's opinion about one target. |
TargetConstraints | re-export of opensmartroute.core.types.TargetConstraints | Where / for whom a target may be used. Checked by the policy layer. |
TargetKind | re-export of opensmartroute.core.types.TargetKind | Kinds of things a request can be routed to. |
TargetRegistry | re-export of opensmartroute.core.registry.TargetRegistry | In-memory catalogue of :class:RouteTarget by id: add / upsert / remove, filtered listing, (de)serialisation. |
opensmartroute.core.registry
Target registry: the catalogue of everything a request may be routed to.
| Name | Kind | Summary |
|---|---|---|
TargetRegistry | class | In-memory catalogue of :class:RouteTarget by id: add / upsert / remove, filtered listing, (de)serialisation. |
opensmartroute.core.types
Core data model for OpenSmartRoute.
| Name | Kind | Summary |
|---|---|---|
TargetKind | class | Kinds of things a request can be routed to. |
Capabilities | class | Declarative description of what a target is good at. |
TargetConstraints | class | Where / for whom a target may be used. Checked by the policy layer. |
RouteTarget | class | A routable destination: an LLM, agent, skill, persona, tool, workflow or human. |
EFFORT_LEVELS | constant | Named reasoning-effort levels -> numeric effort in [0, 1] (RouteTarget.effort). |
Objective | class | What the caller wants to optimise. Weights are relative. |
RequestConstraints | class | Hard constraints on the request (never traded off). |
RouteRequest | class | The customer need. |
Signals | class | Cheap deterministic features extracted from a request. |
StrategyScore | class | One strategy's opinion about one target. |
RankedTarget | class | A scored candidate: utility, ensemble quality estimate and the per-strategy breakdown. |
RouteTrace | class | Everything needed to explain a decision. |
PlanSlot | class | One filled slot of a multi-target plan (persona -> skill -> model). |
PLAN_MODES | constant | : merges their outputs in slot order, and calls the tools of one round concurrently. |
RoutePlan | class | A composed route (MasRouter-style): several targets working together, executed in stages. |
RouteDecision | class | The answer to route(): chosen target, confidence, alternatives, optional plan, trace and propensities. |
Outcome | class | Feedback about how a routed request actually went. |
opensmartroute.credentials
Credentials for the osr CLI: where the access token lives and how it is obtained.
| Name | Kind | Summary |
|---|---|---|
CREDENTIALS_FILE | constant | file name inside :func:config_dir. |
DEFAULT_PROFILE | constant | profile used when --profile is not given. |
DEVICE_CODE_PATH | constant | RFC 8628 device-authorization endpoint of the platform. |
DEVICE_TOKEN_PATH | constant | noqa: S105 # nosec B105 - RFC 8628 token endpoint (a URL path). |
ME_PATH | constant | platform: who am I (workspace, plan, edition). |
TOKEN_BYTES | constant | entropy of :func:generate_token. |
WHOAMI_PATH | constant | self-hosted osr serve: is this token accepted. |
Credential | class | One saved sign-in: where (url), what (token) and what the platform said about it. |
CredentialStore | class | Profiles in <config dir>/credentials.json (owner-only permissions on POSIX). |
PlatformClient | class | Minimal JSON client for the platform / server API used by the CLI (stdlib only, injectable transport). |
Transport | constant | : (method, url, headers, body, timeout) -> (status, json); tests inject a fake instead of urllib. |
apply_identity | function (cred: Credential, info: Mapping[str, Any]) | Copy what :func:whoami learned (kind, workspace, plan, edition) onto cred. |
config_dir | function (environ: Mapping[str, str] | None=None) | Per-user configuration directory (OSR_CONFIG_DIR > %APPDATA% > $XDG_CONFIG_HOME > ~/.config). |
device_login | function (url: str | None=None, *, client_name: str | None=None, open_browser: bool=True, out: Callable[[str], None]=print, transport: Transport | None=None, sleep: Callable[[float], None]=time.sleep, timeout_s: float | None=None) | Sign in to the hosted platform with the device authorization grant and return the credential. |
generate_token | function (prefix: str=LOCAL_TOKEN_PREFIX) | A fresh random access token (osr_local_<43 chars>) for a self-hosted osr serve. |
redact | function (token: str, keep: int=6) | osr_live_abc123... - the prefix plus a few characters, never the whole token. |
token_kind | function (token: str) | "platform" for osr_live_ keys, "server" for osr_local_ tokens, else "unknown". |
whoami | function (cred: Credential, *, transport: Transport | None=None, timeout: float=30.0) | Validate cred against its server and describe the identity behind it. |
opensmartroute.data
Data files shipped inside the package.
No public names.
opensmartroute.discovery
Tool discovery beyond text similarity.
| Name | Kind | Summary |
|---|---|---|
CachePreservingSelector | class | Keep the serialized tool list prefix-stable across turns of a session. |
SchemaAwareStrategy | class | Scores tools by how many of their input_schema parameters the request can fill (see schema_match). |
SkillGraph | class | Dependency / conflict / composition graph over skill targets. |
extract_entities | function (text: str) | Typed entity mentions found in text (kind -> values). |
schema_match | function (request: RouteRequest | str, target: RouteTarget) | Return (coverage, filled, missing) for the target's input schema. |
opensmartroute.enterprise
Enterprise integration layer: ports (hexagonal architecture), middleware and telemetry.
| Name | Kind | Summary |
|---|---|---|
AuditSink | class | Tamper-evident audit trail port (hash-chained). |
CacheMiddleware | class | LRU decision cache keyed on (text, constraints, objective, route options). TTL in seconds. |
EnterpriseRouter | class | Router + middleware chain + telemetry + auto-learning + audit. Thread-safe façade. |
FileAuditSink | class | Append-only JSONL, each line {prev, hash, record} with. |
FileStateStore | class | One JSON file per key under root; keys are hashed so they can't traverse paths. |
InMemoryStateStore | class | Thread-safe dict-backed :class:StateStore; values are deep-copied through JSON on read and write. |
LiveContext | re-export of opensmartroute.enterprise.grounding.LiveContext | What one grounding retrieved: the query, the hits (as dicts), when, how long, and the signal that asked. |
LoggingTelemetry | class | Structured JSON logs; never logs raw request text (only a hash + length). |
MetricsTelemetry | class | In-process counters, outcome tallies and a latency histogram. |
Middleware | class | Chain-of-responsibility hook around routing: __call__(request, next_) -> RouteDecision. |
RouteFn | constant | the "next" callable a middleware wraps. |
RouterBuilder | class | Fluent builder that validates configuration and wires all enterprise pieces. |
SavingsEntry | re-export of opensmartroute.enterprise.savings.SavingsEntry | One routed request in the ledger. |
SavingsLedger | re-export of opensmartroute.enterprise.savings.SavingsLedger | Telemetry sink that keeps a per-request baseline-vs-routed cost ledger (see module docs). |
SavingsReport | re-export of opensmartroute.enterprise.savings.SavingsReport | Aggregate savings and the quality they were bought at. |
StateStore | class | Key/value persistence port for learner state, caches, breaker state. |
Telemetry | class | Observer port with no-op defaults. Implement for OpenTelemetry, Prometheus, Datadog…. |
TenantMiddleware | class | Enforces that a tenant is present and applies per-tenant defaults/limits. |
TimeoutMiddleware | class | Soft deadline: raise if routing itself exceeded budget_ms (should never happen. |
WebGroundingMiddleware | re-export of opensmartroute.enterprise.grounding.WebGroundingMiddleware | Search the web for requests about current facts and put the hits in front of the model (module docstring). |
harden | function (router: Router, *, guard: bool=False, redact_pii: bool=False, learned_guard: bool=False, output_guard: str | Any='off', health: bool=False, latency_slo_ms: float | None=None, audit: str | Path | AuditSink | None=None, audit_outcomes: bool=False, origin_policy: Any=False, limits: Any=False, web_grounding: Any=False, knowledge: Any=False, state_store: StateStore | str | None=None, save_every: int=1, middleware: list[Middleware] | None=None, telemetry: list[Telemetry] | None=None) | Wrap an already built :class:Router in the production controls (what osr serve --guard ... does). |
search_query | re-export of opensmartroute.enterprise.grounding.search_query | The search query for a request: its first sentence or line, whitespace-normalised, filler words dropped. |
opensmartroute.enterprise.grounding
Live web context in front of the model: search the web for requests about now and hand the hits to the target.
| Name | Kind | Summary |
|---|---|---|
GROUNDING_HEADER | constant | : Opens the block appended to the system prompt; {when} is the retrieval time in UTC. |
LiveContext | class | What one grounding retrieved: the query, the hits (as dicts), when, how long, and the signal that asked. |
WebGroundingMiddleware | class | Search the web for requests about current facts and put the hits in front of the model (module docstring). |
search_query | function (text: str, max_chars: int=200) | The search query for a request: its first sentence or line, whitespace-normalised, filler words dropped. |
opensmartroute.enterprise.ops
Operational controls: shadow / A-B routing, tenant fairness and queue-aware latency.
| Name | Kind | Summary |
|---|---|---|
SPRT | class | Wald SPRT for two Bernoulli success rates: H0 p=p0 vs H1 p=p0+delta. |
ABTest | class | Traffic split + SPRT comparison of candidate vs control outcomes. |
FairShareMiddleware | class | Dominant Resource Fairness across tenants over a sliding window. |
InflightTracker | class | Per-target in-flight counters + arrival/service statistics for queueing estimates. |
QueueAwareStrategy | class | Scores targets by current time-to-first-token = catalogue latency + queueing wait vs. |
ShadowMiddleware | class | Run candidate beside production. mode='shadow': log only. mode='ab': serve. |
TenantUsage | class | Sliding-window ledger of one tenant's requests, cost and tokens for :class:FairShareMiddleware. |
opensmartroute.enterprise.savings
Savings ledger - the always-on savings report that backs the ROI story and the dashboard.
| Name | Kind | Summary |
|---|---|---|
SavingsEntry | class | One routed request in the ledger. |
SavingsLedger | class | Telemetry sink that keeps a per-request baseline-vs-routed cost ledger (see module docs). |
SavingsReport | class | Aggregate savings and the quality they were bought at. |
opensmartroute.enterprise.stores
Production state-store backends and wrappers.
| Name | Kind | Summary |
|---|---|---|
BatchedStateStore | class | Write-behind buffer. Reads are served from the pending map first. |
EncryptedStateStore | class | AES-256-GCM envelope encryption. key is 32 raw bytes, or read (base64/hex/raw). |
Migration | constant | state-document transform applied by VersionedStateStore. |
NamespacedStateStore | class | Prefix every key with <namespace>/ so several routers or tenants can share one backing store. |
RedisStateStore | class | StateStore on any redis-py-compatible client (get / set / delete), JSON values, optional TTL. |
SQLStateStore | class | DB-API 2.0 key/value store (PostgreSQL, SQLite, MySQL). |
VersionedStateStore | class | Schema-versioned envelope with forward migrations. |
open_state_store | function (url: str, *, encrypt_key_env: str | None=None) | Build a store from a URL (osr serve --state-store, OSR_SERVER_STATE_STORE). |
opensmartroute.errors
Exception hierarchy. Every error raised by the SDK derives from :class:OpenSmartRouteError.
| Name | Kind | Summary |
|---|---|---|
OpenSmartRouteError | class | Base class for all SDK errors. |
ConfigurationError | class | Invalid catalogue, rules, SKILL.md, settings or a missing optional dependency. |
ValidationError | class | A request, outcome or target failed validation. |
NoRouteError | class | No target satisfied the hard constraints. |
TargetUnavailableError | class | A remote target or catalogue source could not be reached. |
ExecutionError | class | A target handler failed while executing a plan. |
SecurityError | class | Request rejected by an input guard (prompt injection, oversize, etc.). |
StateStoreError | class | A learner-state store failed to load, save or migrate. |
AuthenticationError | class | The CLI has no valid access token for the platform / server, or a sign-in was denied or timed out. |
APIError | class | The platform or osr serve answered a call with an error status; status, detail and the. |
RateLimitError | class | 429: the rate limit, the monthly quota or a budget is exhausted; retry_after says when to try again. |
OpenSmartRouteDeprecationWarning | class | Emitted by :func:deprecated; filter with warnings.simplefilter on this class. |
deprecated | function (name: str, *, since: str, removal: str, replacement: str | None=None, stacklevel: int=3) | Announce a deprecation according to the stability policy in SDK.md. |
opensmartroute.estimate
Token, cost and latency estimates before a request is sent anywhere.
| Name | Kind | Summary |
|---|---|---|
DEFAULT_OUTPUT_TOKENS | constant | : Output length assumed when neither the caller nor the signals say (a short answer). |
MESSAGE_OVERHEAD_TOKENS | constant | : Tokens a chat API adds per message for role / separators (OpenAI-style framing). |
PriceHook | constant | : (usd_per_1k_input, usd_per_1k_output) for a target, or None to fall back to its declared cost. |
RequestEstimate | class | A quote for one request across every candidate, with named picks. |
TargetEstimate | class | The quote for one candidate target. |
build_token_counter | function (spec: str) | The counter a tokenizer spec names (EstimateSettings.tokenizer): tiktoken:<encoding> counts with. |
estimate | function (router: Router, request: RouteRequest | str, *, output_tokens: int | None=None, kinds: list[str] | None=None, prices: PriceHook | None=None, quality_tolerance: float=0.1, decision: RouteDecision | None=None) | Quote request against every candidate the router would consider - nothing is executed. |
estimate_messages_tokens | function (messages: list[dict[str, Any]]) | Token estimate for an OpenAI-style message list (content plus per-message framing). |
estimate_tokens | function (text: str) | Token count of text: the installed :data:token_counter when there is one (installed by. |
heuristic_tokens | function (text: str) | The dependency-free tokenizer approximation (what :func:estimate_tokens uses unless a counter is installed). |
set_token_counter | function (counter: Callable[[str], int] | None) | Install (or, with None, remove) the process-wide token counter behind :func:estimate_tokens; the. |
target_prices | function (target: RouteTarget) | (usd per 1k input tokens, usd per 1k output tokens) from the target's declared cost. |
token_counter | constant | : :class:~opensmartroute.learning.neural.TokenCountModel trained on billed counts (None = the heuristic). |
opensmartroute.eval
RouterBench-style evaluation harness.
| Name | Kind | Summary |
|---|---|---|
AuditReport | re-export of opensmartroute.eval.audit.AuditReport | Aggregate of a shadow replay; to_markdown renders the Routing Audit deliverable. |
AuditRow | re-export of opensmartroute.eval.audit.AuditRow | One logged request: what happened, and what the router would have done. |
DatasetCollector | re-export of opensmartroute.eval.collect.DatasetCollector | Cache-backed corpus builder: collect sources, add feedback / synthetic rows, dedupe, split. |
DatasetSource | re-export of opensmartroute.eval.collect.DatasetSource | One Hub dataset split to collect: repo id, config, split, the preset that parses it, an optional model map. |
EvalResult | class | Aggregate routing metrics over a dataset: accuracy, cost, latency, confidence, calibration, coverage. |
EvalRow | class | One labelled prompt: expected / acceptable targets or per-target quality scores (RouterBench style). |
area_under_frontier | function (points: list[dict[str, float]]) | Trapezoidal area under accuracy(cost) — analogous to RouterBench's AIQ. |
calibration_report | function (router: Router, rows: list[EvalRow], objective: Objective | None=None) | Confidence calibration of the router on labelled rows: ECE, Brier, reliability bins and. |
collect_dataset | re-export of opensmartroute.eval.collect.collect_dataset | Download source from the Hub and parse it into rows. |
cost_quality_frontier | function (router: Router, rows: list[EvalRow], cost_weights: list[float] | None=None) | Sweep the cost weight to trace the accuracy-vs-cost curve (RouterBench Fig. 1 style). |
evaluate | function (router: Router, rows: list[EvalRow], objective: Objective | None=None) | Route every row and score accuracy, realised quality, cost, latency, ECE / Brier and conformal coverage. |
fetch_hf_rows | re-export of opensmartroute.eval.collect.fetch_hf_rows | One page (max 100) of records from the datasets-server /rows endpoint, flattened to {column: value}. |
load_audit_log | re-export of opensmartroute.eval.audit.load_audit_log | Read a JSONL traffic log (text or prompt/messages per line). |
load_dataset | function (path: str | Path) | Read a JSONL evaluation dataset (text or prompt plus the optional EvalRow keys); a line that is. |
model_quality | re-export of opensmartroute.eval.collect.model_quality | Data-derived quality prior per model in [0, 1]: pairwise rows (two scored models) are fitted with. |
routing_audit | re-export of opensmartroute.eval.audit.routing_audit | Replay rows through router in shadow mode and aggregate an :class:AuditReport. |
rows_from_feedback | re-export of opensmartroute.eval.collect.rows_from_feedback | Rows from :class:Outcome records. texts maps request_id to the prompt (outcomes carry no text);. |
summarize_audit | re-export of opensmartroute.eval.audit.summarize_audit | Aggregate :class:AuditRow records into an :class:AuditReport. |
synthetic_followup_rows | re-export of opensmartroute.eval.collect.synthetic_followup_rows | Conversation rows built from labelled rows. |
synthetic_rows | re-export of opensmartroute.eval.collect.synthetic_rows | Ontology seed prompts (templates and, with natural, the everyday phrasings - see. |
synthetic_slot_rows | re-export of opensmartroute.eval.collect.synthetic_slot_rows | Ontology seed prompts scored for a plan slot: every role target of the catalogue (personas, skills,. |
opensmartroute.eval.agentic
tau-bench-style agentic task evaluation: does per-step routing beat the best single agent?.
| Name | Kind | Summary |
|---|---|---|
AgentTask | class | A multi-step task with the measured per-step success probability and latency of each agent. |
load_agentic_tasks | function (path: str | Path) | Read tasks from JSONL: {"task_id", "steps", "success", "latency_ms", "cost_usd"?, "domain"?}. |
synthetic_agentic_tasks | function (n: int=200, *, seed: int=0, hard_share: float=0.3) | Three agents (fast / balanced / strong) and n tasks of 3-5 steps whose steps are mostly. |
task_routing_frontier | function (registry: TargetRegistry, tasks: Sequence[AgentTask], *, retries: int=1, accuracy_tolerance: float=0.02, latency_ratio_target: float=0.9, objective: Objective | None=None, router_factory: Callable[[TargetRegistry], Router] | None=None, seed: int=0) | Replay tasks step by step through :class:ProgressRouter (each agent's handler draws the. |
opensmartroute.eval.audit
Routing Audit - shadow-mode replay of logged LLM traffic to quantify what the router would change.
| Name | Kind | Summary |
|---|---|---|
DEFAULT_COMPLETION_TOKENS | constant | : Default assumed output length when a log row carries no completion_tokens. |
AuditReport | class | Aggregate of a shadow replay; to_markdown renders the Routing Audit deliverable. |
AuditRow | class | One logged request: what happened, and what the router would have done. |
load_audit_log | function (path: str | Path) | Read a JSONL traffic log (text or prompt/messages per line). |
routing_audit | function (router: Router, rows: list[dict[str, Any]], *, baseline: str | None=None, monthly_requests: int | None=None, plan: bool=False, keep_rows: bool=True) | Replay rows through router in shadow mode and aggregate an :class:AuditReport. |
summarize_audit | function (rows: list[AuditRow], *, monthly_requests: int | None=None, keep_rows: bool=True) | Aggregate :class:AuditRow records into an :class:AuditReport. |
opensmartroute.eval.baselines
Baselines every router must beat, plus oracle ceilings and the sampling noise floor.
| Name | Kind | Summary |
|---|---|---|
Policy | constant | a baseline: (row, targets) -> chosen target id. |
PolicyResult | class | Metrics of one baseline policy on a dataset (same fields as the router's EvalResult headline). |
baseline_suite | function (rows: list[EvalRow], targets: Sequence[RouteTarget], train_rows: list[EvalRow] | None=None, quality_floor: float=0.7, seed: int=0) | Run every baseline and both oracles; train_rows fit the task table. |
best_prior_policy | function (row: EvalRow, targets: Sequence[RouteTarget]) | Always the target with the highest declared quality_prior. |
cheapest_policy | function (row: EvalRow, targets: Sequence[RouteTarget]) | Always the lowest unit cost (ties broken by latency). |
compare_policies | function (router_hits: Sequence[bool], baselines: Sequence[PolicyResult], *, seed: int=0, n_boot: int=2000, level: float=0.95) | The router against each baseline on the same rows: accuracy delta with a paired percentile-bootstrap. |
evaluate_policy | function (name: str, policy: Policy, rows: list[EvalRow], targets: Sequence[RouteTarget]) | Run a baseline :data:Policy over the rows and aggregate accuracy, quality, cost and latency. |
fit_task_table | function (rows: list[EvalRow], targets: Sequence[RouteTarget]) | task_type -> target with the highest mean quality on the training rows. |
held_out_split | function (rows: Sequence[EvalRow], seed: int=0, train_fraction: float=0.5) | A seeded shuffle split into (train, test): the task table (and anything else fitted) learns from. |
most_expensive_policy | function (row: EvalRow, targets: Sequence[RouteTarget]) | Always the highest unit cost - the "just use the frontier model" baseline. |
multi_sample_oracle | function (rows: list[EvalRow], targets: Sequence[RouteTarget]) | Mean quality of the oracle that picks by the mean over all samples per target. |
noise_floor | function (rows: list[EvalRow], targets: Sequence[RouteTarget], seed: int=0) | How much accuracy is lost to sampling noise alone. |
oracle_policy | function (quality_floor: float | None=None) | Per-row best target. With quality_floor -> cheapest target reaching the floor. |
random_policy | function (seed: int=0) | Uniformly random target (seeded). |
static_task_table_policy | function (table: dict[str, str]) | Look the row's task_type up in a table from :func:fit_task_table ("*" = default). |
opensmartroute.eval.collect
Collect routing datasets from the Hugging Face Hub, your own feedback log and synthetic seeds.
| Name | Kind | Summary |
|---|---|---|
ARENA_TIERS | constant | everything else in those datasets is a 7B-14B chat model -> "small". |
DATASETS_SERVER | re-export of opensmartroute.adapters.websearch.DATASETS_SERVER | Hugging Face datasets-server REST root (/rows). |
DEFAULT_SOURCES | constant | public ones. |
FOLLOWUP_PROMPTS | constant | : task-neutral: "translate it" or "summarise that" name a task of their own and belong to a different target. |
HISTORY_FILE | constant | the self-improver's report log; lives in the cache dir but is not a dataset. |
KNOWN_SOURCES | constant | pairwise human / judge preference battles - the winner is the label. |
PAIRWISE | constant | preset name for battle datasets: prompt / conversation, model_a, model_b, winner. |
PARSERS | constant | collector presets that are not wide / nested tables. |
REWARD_BENCH | constant | preset name for RewardBench: prompt, chosen_model, rejected_model, subset. |
ROUTELLM_GOOD_ENOUGH | constant | RouteLLM's threshold: a weak-model score >= 4 means the cheap model was good enough. |
ROUTELLM_GPT4 | constant | preset name for RouteLLM's gpt4_dataset: prompt + GPT-4-judged Mixtral score 1-5. |
ROUTELLM_STRONG | constant | the strong model of RouteLLM's gpt4_dataset (its answers are the reference). |
ROUTELLM_WEAK | constant | the weak model whose answer GPT-4 scores 1-5 against the reference. |
ULTRAFEEDBACK | constant | preset name for UltraFeedback: instruction + N completions with a model and score. |
DatasetCollector | class | Cache-backed corpus builder: collect sources, add feedback / synthetic rows, dedupe, split. |
DatasetSource | class | One Hub dataset split to collect: repo id, config, split, the preset that parses it, an optional model map. |
Parser | constant | record -> row (or None to skip). |
collect_dataset | function (source: DatasetSource, *, timeout_s: float | None=None, settings: Settings | None=None) | Download source from the Hub and parse it into rows. |
fetch_hf_rows | function (dataset: str, *, config: str='default', split: str='train', offset: int=0, length: int=100, timeout_s: float | None=None, settings: Settings | None=None) | One page (max 100) of records from the datasets-server /rows endpoint, flattened to {column: value}. |
from_pairwise_row | function (rec: dict[str, Any], model_map: dict[str, str] | None=None, source: DatasetSource | None=None) | A battle record -> row with scores 1 / 0 for winner / loser (0.5 each on a tie). Understands the. |
from_reward_bench_row | function (rec: dict[str, Any], source: DatasetSource | None=None) | A RewardBench record (prompt, chosen_model, rejected_model, subset) -> a pairwise row. |
from_routellm_gpt4_row | function (rec: dict[str, Any], source: DatasetSource | None=None) | A routellm/gpt4_dataset record (prompt + mixtral_score 1-5) -> the strong model scores 1.0 and. |
from_ultrafeedback_row | function (rec: dict[str, Any], source: DatasetSource | None=None) | An UltraFeedback record (instruction + completions[{model, overall_score}]) -> a scored row with. |
iter_hf_rows | function (source: DatasetSource, *, offset: int=0, timeout_s: float | None=None, settings: Settings | None=None) | Page through source from raw record offset until source.limit records or the split is exhausted. |
model_quality | function (rows: Iterable[EvalRow], *, min_n: int=20, epochs: int=5, seed: int=0) | Data-derived quality prior per model in [0, 1]: pairwise rows (two scored models) are fitted with. |
rows_from_feedback | function (outcomes: Iterable[Outcome] | FeedbackStore, texts: dict[str, str] | None=None, *, min_quality: float=0.5, role: str | None=None) | Rows from :class:Outcome records. texts maps request_id to the prompt (outcomes carry no text);. |
rows_from_records | function (records: Iterable[dict[str, Any]], source: DatasetSource) | Parse raw records with the source's preset (text_key is tried first when set). |
synthetic_followup_rows | function (rows: Sequence[EvalRow], *, per_row: int=1, switches: int=0, seed: int=0, assistant: str='(answer)') | Conversation rows built from labelled rows. |
synthetic_rows | function (targets: Sequence[RouteTarget], *, per_template: int=2, seed: int=0, router: Any | None=None, natural: bool | int=True, natural_phrases: Mapping[str, Sequence[str]] | None=None) | Ontology seed prompts (templates and, with natural, the everyday phrasings - see. |
synthetic_slot_rows | function (targets: Sequence[RouteTarget], role: str, *, per_template: int=2, seed: int=0) | Ontology seed prompts scored for a plan slot: every role target of the catalogue (personas, skills,. |
tier_model_map | function (tiers: Mapping[str, str], models: Iterable[str]=()) | model_map for a :class:DatasetSource: every known battle model (plus models) -> the target id. |
tier_of | function (model: str) | Tier of a battle-dataset model name: the :data:ARENA_TIERS entry, else the name rules, else the parameter. |
opensmartroute.eval.criteria
Offline realisations of the release exit criteria.
| Name | Kind | Summary |
|---|---|---|
CriterionResult | class | One measured exit criterion. |
bootstrap_ci | function (values: Sequence[float], *, n_boot: int=1000, level: float=0.95, seed: int=0) | Percentile bootstrap confidence interval for the mean of values. |
cold_start_ratio | function (n_outcomes: int=200, *, domain: str='legal', n_eval: int=200, seed: int=0, target_ratio: float=0.9, generalist_quality: float=0.6, explore_rate: float=0.1, max_requests: int=20000) | Accuracy on domain prompts of a target declared with only id / kind / cost. |
conformal_coverage | function (alpha: float=0.1, *, n_cal: int=1000, n_test: int=1000, label_noise: float=0.5, seed: int=0, tolerance: float=0.02) | Fit :class:ConformalCalibrator on the real router's propensities over labelled prompts and. |
domain_expert_registry | function (domains: Sequence[str]=_DOMAINS, *, strip: str | None=None, generalist: bool=False) | One hand-configured expert per domain. strip=<domain> replaces that expert with a. |
effort_token_savings | function (registry: TargetRegistry, rows: Sequence[EvalRow], *, quality_tolerance: float=0.02, token_ratio_target: float=0.7, objective: Objective | None=None, router_factory: Callable[[TargetRegistry], Router] | None=None) | Route rows that carry per-target scores and tokens and compare the tokens spent. |
knapsack_never_exceeds_cap | function (steps: int=1000000, *, window: int=1000, drift_every: int=100000, seed: int=0) | Drive :class:MultiKnapsackBandit (on_capped="abstain") for steps pulls with. |
match_at_1 | function (router: Router | EnterpriseRouter, prompts: Sequence[tuple[str, str]]) | Fraction of (text, expected_target_id) pairs the router gets right at rank 1. |
match_at_1_at_scale | function (small: int=50, large: int=5000, *, n_prompts: int=200, seed: int=0, max_drop: float=0.05, narrow_above: int=32, narrow_to: int=24) | Match@1 on a small catalogue versus a large one with retrieve-then-rank narrowing. |
multi_round_vs_best_single | function (registry: TargetRegistry, rows: Sequence[EvalRow], *, threshold: float=0.8, max_rounds: int=3, failures_before_switch: int=1, objective: Objective | None=None, cost_ratio_target: float=0.6, router_factory: Callable[[TargetRegistry], Router] | None=None) | Run :class:MultiRoundExecutor over rows that carry per-target scores (RouterBench. |
ope_within_live_ci | function (n_log: int=2000, *, seed: int=0, logging_objective: Objective | None=None, target_objective: Objective | None=None, logging_temperature: float=0.3) | Log decisions from a cost-seeking router (actions sampled from its propensities), estimate. |
run_all | function (*, quick: bool=True, seed: int=0) | Every offline criterion. quick shrinks the expensive simulations (10^5 steps, 1 000 tools,. |
synthetic_effort_rows | function (n: int=400, *, seed: int=0) | One reasoning model exposed as two effort siblings (reasoner@fast with effort="low". |
synthetic_scored_rows | function (n: int=300, *, seed: int=0) | A three-tier catalogue (small / medium / large) and RouterBench-style rows with a quality. |
synthetic_tool_catalogue | function (n: int, *, seed: int=0) | n distinct tools (verb x object x qualifier, up to 5 000 unique combinations) and one. |
opensmartroute.eval.datasets
Adapters from public routing benchmarks to :class:EvalRow.
| Name | Kind | Summary |
|---|---|---|
PRESETS | constant | Named layouts accepted by load_benchmark / osr eval --preset. |
NestedPreset | class | Layout of a "nested" benchmark: a per-model mapping under container_keys holding score / cost / samples. |
WidePreset | class | Column layout of a "wide" benchmark: one row per prompt, <model><suffix> columns for scores / costs. |
from_nested_row | function (row: dict[str, Any], preset: NestedPreset, model_map: dict[str, str] | None=None) | Convert one nested-format record to an :class:EvalRow, keeping repeated samples when present. |
from_wide_row | function (row: dict[str, Any], preset: WidePreset, model_map: dict[str, str] | None=None) | Convert one wide-format record to an :class:EvalRow (None when it has no prompt or scores). |
load_benchmark | function (path: str | Path, preset: str | WidePreset | NestedPreset='routerbench', model_map: dict[str, str] | None=None, limit: int | None=None) | Load a benchmark file (.jsonl / .json / .csv) into :class:EvalRow objects. |
models_in | function (rows: Iterable[EvalRow]) | Distinct target ids that carry scores in the rows, in first-seen order. |
opensmartroute.eval.frontier
Three-objective frontier and ablations.
| Name | Kind | Summary |
|---|---|---|
ablation_report | function (router: Router, rows: list[EvalRow], objective: Objective | None=None) | Leave-one-out over strategies (and extractors, when explicitly set on the router). |
frontier3 | function (router: Router, rows: list[EvalRow], cost_weights: list[float] | None=None, latency_weights: list[float] | None=None) | Sweep cost / latency objective weights and return the Pareto-optimal (quality, cost, latency) points. |
hypervolume | function (points: list[dict[str, float]], ref: tuple[float, float, float] | None=None) | Dominated hypervolume of the Pareto points in normalised (quality, cost, latency) space. |
opensmartroute.eval.headroom
Routing headroom: when does routing pay, and how much catalogue does it need?.
| Name | Kind | Summary |
|---|---|---|
DiversityReport | class | How differently the targets score rows: pairwise disagreement, winner entropy and winner share. |
HeadroomReport | class | Oracle vs best-single quality on a dataset, with the label-noise floor that says whether the gap is real. |
learnability_by_difficulty | function (rows: Sequence[EvalRow], targets: Sequence[RouteTarget], buckets: int=4) | Routing gain (oracle - best single) per difficulty bucket. Difficulty of a row is. |
min_catalogue | function (rows: Sequence[EvalRow], targets: Sequence[RouteTarget], fraction: float=0.95) | Greedy forward selection: the smallest ordered subset whose oracle reaches fraction of the. |
routing_headroom | function (rows: Sequence[EvalRow], targets: Sequence[RouteTarget], seed: int=0) | Oracle minus best-single quality with the label-noise floor for context. |
scaling_curve | function (rows: Sequence[EvalRow], targets: Sequence[RouteTarget], sizes: Sequence[int] | None=None, *, trials: int=20, seed: int=0) | Mean oracle / best-single quality and headroom on random subsets of each size. |
target_diversity | function (rows: Sequence[EvalRow], targets: Sequence[RouteTarget]) | How different the targets are on this data: pairwise score disagreement and winner spread. |
opensmartroute.eval.ope
Off-policy evaluation from logged routing decisions.
| Name | Kind | Summary |
|---|---|---|
LoggedDecision | class | One logged routing event for off-policy evaluation: text, action taken, its propensity and observed reward. |
OPEResult | class | IPS, self-normalised IPS and doubly-robust value estimates with effective sample size and clip count. |
ips_confidence_interval | function (logs: list[LoggedDecision], weights: list[float], z: float=1.96) | Normal-approximation CI for the IPS estimate given per-sample weights. |
mean_reward_model | function (logs: list[LoggedDecision]) | Simplest DR reward model: mean logged reward per action, global mean for unseen actions. |
off_policy_evaluate | function (router: Router, logs: list[LoggedDecision], objective: Objective | None=None, max_weight: float=20.0, reward_model: Callable[[LoggedDecision, str], float] | None=None, deterministic: bool=False) | Estimate the value of router on logged traffic. |
target_propensities | function (router: Router, lg: LoggedDecision, objective: Objective | None=None) | The evaluated router's P(target | x) for a logged context (empty when it has no route). |
opensmartroute.eval.robustness
Robustness and fairness checks for a router.
| Name | Kind | Summary |
|---|---|---|
coreset | function (rows: list[EvalRow], k: int, embedder: Callable[[list[str]], list[list[float]]] | None=None, seed: int=0) | Greedy k-center (farthest-first) subset of rows for a diverse evaluation set. |
diversity | function (rows: list[EvalRow], embedder: Callable[[list[str]], list[list[float]]] | None=None, sample: int=300) | Mean pairwise cosine distance of the row texts (sampled), 0 = all identical. |
paraphrase_robustness | function (router: Router, rows: list[EvalRow], n: int=4, objective: Objective | None=None, seed: int=0) | Share of rule-based paraphrases that route to the same target as the original (robustness). |
paraphrases | function (text: str, n: int=4, seed: int=0) | n deterministic surface-level paraphrases of text (never returns the original). |
profile_swap_fairness | function (router: Router, rows: list[EvalRow], profiles: Sequence[dict[str, Any]] | None=None, objective: Objective | None=None) | Decision agreement across user profiles. dependence = fraction of rows whose. |
repeat_flip_rate | function (router: Router, rows: list[EvalRow], k: int=5, objective: Objective | None=None) | Route each row k times; flip_rate = share of rows whose decision is not identical every time. |
opensmartroute.execution
Plan-aware execution: turn a :class:RouteDecision into a real answer.
| Name | Kind | Summary |
|---|---|---|
ON_DELTA_KEY | constant | Handler keyword that receives streamed text deltas (also mirrored into request.context). |
PRELUDE_ROLES | constant | Roles executed before the primary target, in this order. |
SSE_DONE | constant | the terminal event of an OpenAI chat stream. |
SSE_KEEPALIVE | constant | an SSE comment: keeps proxies and clients on the line while a model is silent. |
TOOL_ROLE | constant | Plan role whose targets are offered to the model as callable functions. |
ChatStream | class | Relay one chat completion as OpenAI chat.completion.chunk events while the handler is still generating. |
ExecutionResult | class | What happened when a decision was executed. |
ExecutionStep | class | One executed plan slot: role, target, latency and whether it succeeded. stage orders the steps. |
aexecute | async function (decision: RouteDecision, request: RouteRequest, learn: LearnFn | None=None, *, min_slot_confidence: float=0.0, task_id: str | None=None, **kw: Any) | Async twin of :func:execute; awaits coroutine handlers. |
completion_chunks | function (completion: dict[str, Any], chunk_chars: int | None=None) | Serve a finished OpenAI chat.completion as chat.completion.chunk events. |
cost_tokens | function (result: ExecutionResult) | (total tokens, USD) of an execution: the handler's token count and the sum of every outcome's cost. |
execute | function (decision: RouteDecision, request: RouteRequest, learn: LearnFn | None=None, *, min_slot_confidence: float=0.0, task_id: str | None=None, preferred_over: str | None=None, **kw: Any) | Run the plan (persona -> skill -> primary) and record outcomes via learn. |
execute_with_fallback | function (decision: RouteDecision, request: RouteRequest, candidates: list[RouteTarget] | None=None, fallbacks: bool=True, learn: LearnFn | None=None, *, router: Any=None, committed: Callable[[], bool] | None=None, on_attempt: Callable[[RouteDecision], None] | None=None, max_fallbacks: int | None=None, settings: Settings | None=None, **handler_kw: Any) | Run the decision; when its handler fails, re-route among the remaining executable targets and retry. |
repair_completion | function (completion: dict[str, Any]) | Repair the assistant text of a finished chat completion in place when it is almost JSON. |
sse_event | function (payload: dict[str, Any]) | One server-sent event carrying payload as JSON (data: {...}\n\n). |
tool_name | function (target: RouteTarget) | The function name a tool target is offered under (OpenAI: ^[A-Za-z0-9_-]{1,64}$). |
tool_spec | function (target: RouteTarget) | OpenAI function-calling spec of a tool target: its MCP input_schema when it has one, else a single input. |
opensmartroute.feedback
Feedback store: append-only outcome log that closes the learning loop.
| Name | Kind | Summary |
|---|---|---|
FeedbackStore | class | Append-only :class:Outcome log (in memory or JSONL file) with per-target statistics. |
opensmartroute.gemini
Google Gemini API dialect: generateContent / streamGenerateContent over the routed chat path.
| Name | Kind | Summary |
|---|---|---|
FINISH_REASONS | constant | : Gemini finishReason for an OpenAI finish_reason. |
STATUS_NAMES | constant | : gRPC-style status names Google error envelopes carry, per HTTP status. |
GenerateStreamTranslator | class | Push-based translation of chat.completion.chunk SSE bytes into streamGenerateContent?alt=sse. |
chat_to_generate | function (completion: dict[str, Any], request: dict[str, Any] | None=None) | Shape a finished chat.completion as a GenerateContentResponse. |
count_tokens | function (body: dict[str, Any], model: str, estimator: Any=None) | :countTokens - {"totalTokens": n} from the router's own token estimate (no provider call). |
decode_inline | function (inline: dict[str, Any]) | The bytes of an inlineData part (helper for callers that store or inspect uploads). |
error_body | function (status: int, message: str) | Google's {"error": {"code", "message", "status"}} envelope. |
generate_events | function (events: Iterable[bytes], request: dict[str, Any] | None=None, model: str='auto') | Translate a chat.completion.chunk SSE byte stream into streamGenerateContent SSE frames. |
generate_to_chat | function (body: dict[str, Any], model: str, *, default_model: str='auto') | Translate a generateContent request into a chat.completion request body. |
opensmartroute.inference
Run open-weight models on the CPU and RAM you have: footprint arithmetic, host planning, Ollama control.
| Name | Kind | Summary |
|---|---|---|
DEFAULT_URL | re-export of opensmartroute.inference.ollama.DEFAULT_URL | where ollama serve listens by default. |
GIB | re-export of opensmartroute.inference.footprint.GIB | bytes in a GiB (container memory limits are written as 28Gi). |
KNOWN_TAGS | re-export of opensmartroute.inference.footprint.KNOWN_TAGS | Only a fallback for planning without a server; /api/show gives the exact figures. |
KV_FALLBACKS | re-export of opensmartroute.inference.planner.KV_FALLBACKS | The order the planner tries KV precisions when a model does not fit at the requested one. |
KV_TYPE_BYTES | re-export of opensmartroute.inference.footprint.KV_TYPE_BYTES | Bytes per KV cache element by OLLAMA_KV_CACHE_TYPE (the quantised types carry block scales). |
QUANT_BITS | re-export of opensmartroute.inference.footprint.QUANT_BITS | Bits per weight of GGUF file types: measured file size x 8 / parameter count (llama.cpp quantize output). |
Footprint | re-export of opensmartroute.inference.footprint.Footprint | Memory one loaded model takes at a given context, parallelism and KV precision. |
Host | re-export of opensmartroute.inference.footprint.Host | A machine (or container) that serves models: its memory, cores and, when known, bandwidth and store speed. |
ModelSpec | re-export of opensmartroute.inference.footprint.ModelSpec | An open-weight model as the planner sees it: size, quantisation and the attention shape behind its KV cache. |
OllamaClient | re-export of opensmartroute.inference.ollama.OllamaClient | Control-plane client for one Ollama server: tags, show, ps, load, unload, exact :class:ModelSpec rows. |
Placement | re-export of opensmartroute.inference.planner.Placement | The models one host keeps resident, what they use and the server environment that pins them. |
Plan | re-export of opensmartroute.inference.planner.Plan | Placements per host plus the models that fit nowhere (with the reason). |
ResidentModel | re-export of opensmartroute.inference.ollama.ResidentModel | One row of /api/ps: a model currently loaded, where it sits and when it expires. |
Throughput | re-export of opensmartroute.inference.footprint.Throughput | Tokens per second a host gives a model, and how long a cold load takes. |
api_root | re-export of opensmartroute.inference.ollama.api_root | http://host:11434/v1 or http://host:11434/ -> http://host:11434 (validated http/https). |
footprint | re-export of opensmartroute.inference.footprint.footprint | Memory spec needs when loaded with context tokens per slot in parallel slots (defaults: settings). |
format_bytes | re-export of opensmartroute.inference.footprint.format_bytes | Human size in binary units (2.4 GiB), the way ollama ps and container limits read. |
kv_type_bytes | re-export of opensmartroute.inference.footprint.kv_type_bytes | Bytes per KV cache element for an OLLAMA_KV_CACHE_TYPE value. |
ollama_env | re-export of opensmartroute.inference.planner.ollama_env | OLLAMA_* variables that make a server hold exactly these models with these slots. |
parse_memory | re-export of opensmartroute.inference.footprint.parse_memory | "28Gi" / "8 GiB" / "16GB" / "512Mi" / a number of bytes -> bytes (Kubernetes and SI units). |
plan | re-export of opensmartroute.inference.planner.plan | First-fit-decreasing packing of models onto hosts at the requested context and parallelism. |
quant_bits | re-export of opensmartroute.inference.footprint.quant_bits | Bits per weight of a GGUF quantisation name (q4_k_m, Q8_0, F16, MXFP4); unknown Qn -> n.5. |
recommend | re-export of opensmartroute.inference.planner.recommend | The largest configuration of spec that fits budget bytes, or None when even the weights do not. |
render | re-export of opensmartroute.inference.planner.render | A plain-text report of a plan: per host the resident models, memory used / free and the OLLAMA_* lines. |
throughput | re-export of opensmartroute.inference.footprint.throughput | Bandwidth-bound decode, compute-bound prefill and cold-load time of spec on host. |
opensmartroute.inference.footprint
What an open-weight model needs from a CPU host: memory for weights and KV cache, and the tokens per second.
| Name | Kind | Summary |
|---|---|---|
GIB | constant | bytes in a GiB (container memory limits are written as 28Gi). |
KNOWN_TAGS | constant | Only a fallback for planning without a server; /api/show gives the exact figures. |
KV_TYPE_BYTES | constant | Bytes per KV cache element by OLLAMA_KV_CACHE_TYPE (the quantised types carry block scales). |
QUANT_BITS | constant | Bits per weight of GGUF file types: measured file size x 8 / parameter count (llama.cpp quantize output). |
Footprint | class | Memory one loaded model takes at a given context, parallelism and KV precision. |
Host | class | A machine (or container) that serves models: its memory, cores and, when known, bandwidth and store speed. |
ModelSpec | class | An open-weight model as the planner sees it: size, quantisation and the attention shape behind its KV cache. |
Throughput | class | Tokens per second a host gives a model, and how long a cold load takes. |
footprint | function (spec: ModelSpec, *, context: int | None=None, parallel: int | None=None, kv_type: str | None=None, settings: Settings | None=None) | Memory spec needs when loaded with context tokens per slot in parallel slots (defaults: settings). |
format_bytes | function (n: int | float) | Human size in binary units (2.4 GiB), the way ollama ps and container limits read. |
kv_type_bytes | function (kv_type: str) | Bytes per KV cache element for an OLLAMA_KV_CACHE_TYPE value. |
parse_memory | function (text: str | int | float) | "28Gi" / "8 GiB" / "16GB" / "512Mi" / a number of bytes -> bytes (Kubernetes and SI units). |
quant_bits | function (quant: str) | Bits per weight of a GGUF quantisation name (q4_k_m, Q8_0, F16, MXFP4); unknown Qn -> n.5. |
throughput | function (spec: ModelSpec, host: Host, *, context_tokens: int=0, kv_type: str | None=None, settings: Settings | None=None) | Bandwidth-bound decode, compute-bound prefill and cold-load time of spec on host. |
opensmartroute.inference.ollama
Talk to an Ollama server's control API: which models it has, their exact shape, which are resident, load and unload.
| Name | Kind | Summary |
|---|---|---|
DEFAULT_URL | constant | where ollama serve listens by default. |
OllamaClient | class | Control-plane client for one Ollama server: tags, show, ps, load, unload, exact :class:ModelSpec rows. |
ResidentModel | class | One row of /api/ps: a model currently loaded, where it sits and when it expires. |
api_root | function (base_url: str) | http://host:11434/v1 or http://host:11434/ -> http://host:11434 (validated http/https). |
opensmartroute.inference.planner
Place models on hosts and write the server settings that make them fit and stay warm.
| Name | Kind | Summary |
|---|---|---|
KV_FALLBACKS | constant | The order the planner tries KV precisions when a model does not fit at the requested one. |
Placement | class | The models one host keeps resident, what they use and the server environment that pins them. |
Plan | class | Placements per host plus the models that fit nowhere (with the reason). |
ollama_env | function (footprints: Sequence[Footprint], *, keep_alive: str | None=None, settings: Settings | None=None) | OLLAMA_* variables that make a server hold exactly these models with these slots. |
plan | function (models: Iterable[ModelSpec], hosts: Sequence[Host], *, context: int | None=None, parallel: int | None=None, kv_type: str | None=None, shrink: bool=False, settings: Settings | None=None) | First-fit-decreasing packing of models onto hosts at the requested context and parallelism. |
recommend | function (spec: ModelSpec, budget: int, *, context: int | None=None, parallel: int | None=None, kv_type: str | None=None, settings: Settings | None=None) | The largest configuration of spec that fits budget bytes, or None when even the weights do not. |
render | function (p: Plan, *, settings: Settings | None=None) | A plain-text report of a plan: per host the resident models, memory used / free and the OLLAMA_* lines. |
opensmartroute.jsonrepair
Repair the JSON a model almost produced.
| Name | Kind | Summary |
|---|---|---|
completion_tail | function (streamed: str) | For a stream whose content so far is streamed: the suffix that completes it into valid JSON when the. |
repair_json | function (text: str) | (repaired, changed) - repaired parses with :func:json.loads when any repair was possible; when the. |
wants_json | function (response_format: Any) | True when an OpenAI response_format asks for JSON (json_object or json_schema). |
opensmartroute.knowledge
Knowledge management and context engineering: a knowledge graph the router learns into and reads from.
| Name | Kind | Summary |
|---|---|---|
CONTEXT_HEADER | re-export of opensmartroute.knowledge.context.CONTEXT_HEADER | : Opens the engineered block; the sections follow as ## <title> with one line per fact. |
FACT_RULES | re-export of opensmartroute.knowledge.ingest.FACT_RULES | : (cue words match case-insensitively; proper-noun objects are then trimmed to their title-cased words). |
GRAPH_FORMAT | re-export of opensmartroute.knowledge.graph.GRAPH_FORMAT | on-disk format of :meth:KnowledgeGraph.save. |
PERSONAL_PREDICATES | re-export of opensmartroute.knowledge.graph.PERSONAL_PREDICATES | : Predicates whose subject is a person; they are placed under About the user and never exported to a shared graph. |
PREDICATES | re-export of opensmartroute.knowledge.graph.PREDICATES | : The predicates the platform and the SDK ingest with, and what each connects (subject -> object). |
ContextEngineer | re-export of opensmartroute.knowledge.context.ContextEngineer | Builds the engineered context (module docstring). budget_tokens / max_facts / max_web_hits. |
ContextLine | re-export of opensmartroute.knowledge.context.ContextLine | One admitted or dropped line of context: its section, text, score, token cost and provenance. |
ContextMiddleware | re-export of opensmartroute.knowledge.context.ContextMiddleware | Run the :class:ContextEngineer in front of every routed request and teach the graph from the traffic. |
EngineeredContext | re-export of opensmartroute.knowledge.context.EngineeredContext | The block placed in front of a request and the accounting behind it. |
KnowledgeGraph | re-export of opensmartroute.knowledge.graph.KnowledgeGraph | Facts indexed three ways, upserted on their key, persisted as JSONL (see the module docstring). |
KnowledgeStrategy | re-export of opensmartroute.knowledge.context.KnowledgeStrategy | Scores candidates by what the graph knows worked on this kind of task: the performed_on facts of each. |
Triple | re-export of opensmartroute.knowledge.graph.Triple | One fact with its provenance. |
entity_id | re-export of opensmartroute.knowledge.graph.entity_id | The graph's spelling of a typed entity: kind:name with the name trimmed and single-spaced. |
extract_facts | re-export of opensmartroute.knowledge.ingest.extract_facts | (predicate, object) pairs a person stated about themselves in text (:data:FACT_RULES plus the name. |
ingest_decision | re-export of opensmartroute.knowledge.ingest.ingest_decision | A routing decision as facts: the task type and domains of the request point at the chosen target. |
ingest_outcome | re-export of opensmartroute.knowledge.ingest.ingest_outcome | An outcome as evidence: target performed_on task with the running mean quality and the count in the. |
ingest_targets | re-export of opensmartroute.knowledge.ingest.ingest_targets | The catalogue as facts: kind, domains, actions, tags, provider / upstream model, price. |
ingest_turn | re-export of opensmartroute.knowledge.ingest.ingest_turn | What a person's message states about them (:func:extract_facts) and names (:func:mentions), as facts of. |
ingest_web_context | re-export of opensmartroute.knowledge.ingest.ingest_web_context | The hits of a :class:~opensmartroute.enterprise.LiveContext (its to_dict()) as topic cites url facts. |
mentions | re-export of opensmartroute.knowledge.ingest.mentions | Entities a message names: URLs, known technologies and capitalised phrases that do not start a sentence. |
tokens | re-export of opensmartroute.knowledge.graph.tokens | Lower-cased content words of text (stop words dropped) - what :meth:KnowledgeGraph.search matches on. |
opensmartroute.knowledge.context
Context engineering: what the model should know for this request, chosen and trimmed to a token budget.
| Name | Kind | Summary |
|---|---|---|
CONTEXT_HEADER | constant | : Opens the engineered block; the sections follow as ## <title> with one line per fact. |
ContextEngineer | class | Builds the engineered context (module docstring). budget_tokens / max_facts / max_web_hits. |
ContextLine | class | One admitted or dropped line of context: its section, text, score, token cost and provenance. |
ContextMiddleware | class | Run the :class:ContextEngineer in front of every routed request and teach the graph from the traffic. |
EngineeredContext | class | The block placed in front of a request and the accounting behind it. |
KnowledgeStrategy | class | Scores candidates by what the graph knows worked on this kind of task: the performed_on facts of each. |
opensmartroute.knowledge.graph
The knowledge graph: typed facts with provenance, in memory, in one JSONL file, exportable to the open formats.
| Name | Kind | Summary |
|---|---|---|
GRAPH_FORMAT | constant | on-disk format of :meth:KnowledgeGraph.save. |
PERSONAL_PREDICATES | constant | : Predicates whose subject is a person; they are placed under About the user and never exported to a shared graph. |
PREDICATES | constant | : The predicates the platform and the SDK ingest with, and what each connects (subject -> object). |
KnowledgeGraph | class | Facts indexed three ways, upserted on their key, persisted as JSONL (see the module docstring). |
Triple | class | One fact with its provenance. |
entity_id | function (kind: str, name: str) | The graph's spelling of a typed entity: kind:name with the name trimmed and single-spaced. |
tokens | function (text: str) | Lower-cased content words of text (stop words dropped) - what :meth:KnowledgeGraph.search matches on. |
opensmartroute.knowledge.ingest
Turning what the router sees into facts: catalogue, conversations, decisions, outcomes and live web hits.
| Name | Kind | Summary |
|---|---|---|
FACT_RULES | constant | : (cue words match case-insensitively; proper-noun objects are then trimmed to their title-cased words). |
extract_facts | function (text: str) | (predicate, object) pairs a person stated about themselves in text (:data:FACT_RULES plus the name. |
ingest_decision | function (graph: KnowledgeGraph, request: RouteRequest, decision: RouteDecision, *, subject: str | None=None) | A routing decision as facts: the task type and domains of the request point at the chosen target. |
ingest_outcome | function (graph: KnowledgeGraph, outcome: Outcome, *, task_type: str | None=None, domains: Sequence[str]=(), ttl_s: float | None=None) | An outcome as evidence: target performed_on task with the running mean quality and the count in the. |
ingest_targets | function (graph: KnowledgeGraph, targets: Iterable[RouteTarget]) | The catalogue as facts: kind, domains, actions, tags, provider / upstream model, price. |
ingest_turn | function (graph: KnowledgeGraph, subject: str, text: str, *, conversation_id: str | None=None, confidence: float=0.9) | What a person's message states about them (:func:extract_facts) and names (:func:mentions), as facts of. |
ingest_web_context | function (graph: KnowledgeGraph, web: Mapping[str, Any], *, subject: str | None=None, ttl_s: float | None=None) | The hits of a :class:~opensmartroute.enterprise.LiveContext (its to_dict()) as topic cites url facts. |
mentions | function (text: str, *, limit: int=8) | Entities a message names: URLs, known technologies and capitalised phrases that do not start a sentence. |
opensmartroute.learning
Auto-learning strategies built on :mod:opensmartroute.math.
| Name | Kind | Summary |
|---|---|---|
DEFAULT_DOMAINS | constant | Domain one-hot block of the LinUCB context vector (ontology domains + the "general" fallback). |
AttentionEncoder | re-export of opensmartroute.learning.attention.AttentionEncoder | One self-attention block with attention pooling; encodes text into a dim-vector (unnormalised). |
AutoLearner | class | Single entry point for closing the loop. |
Autopilot | re-export of opensmartroute.learning.autopilot.Autopilot | Runs a :class:SelfImprover on a schedule and on drift, inside a live process. |
ContrastiveRouter | re-export of opensmartroute.learning.contrastive.ContrastiveRouter | Dual-encoder router trained with a contrastive or a distillation objective. |
ContrastiveStrategy | re-export of opensmartroute.learning.contrastive.ContrastiveStrategy | Scores candidates with a trained :class:ContrastiveRouter. |
DriftMonitor | re-export of opensmartroute.learning.autopilot.DriftMonitor | Page-Hinkley over outcomes: alarms when the served success rate (or quality) drops for real. |
EmbeddingFeaturizer | re-export of opensmartroute.learning.embed.EmbeddingFeaturizer | Hashed features plus a frozen dense embedding, indexed above the hashed space (dim + i). |
ExampleMiner | re-export of opensmartroute.learning.coldstart.ExampleMiner | Promote prompts a target handled well into that target's examples. |
HandoffPolicy | re-export of opensmartroute.learning.handoff.HandoffPolicy | Permanent handoff of a task to fallback_target once the failure risk is too high. |
HistoryTargetModel | re-export of opensmartroute.learning.multiturn.HistoryTargetModel | Logistic model over h * e_t with a shared weight vector and per-target biases. |
HistoryTargetStrategy | re-export of opensmartroute.learning.multiturn.HistoryTargetStrategy | Scores each target by the learned success probability given the conversation so far. |
IRTStrategy | class | 2PL Item Response Theory: target ability vs (domain, complexity-bucket) item difficulty, learned online. |
ImprovementReport | re-export of opensmartroute.learning.self_improve.ImprovementReport | What one cycle did: evidence gathered, catalogue changes, champion vs challenger, and the verdict. |
InputDriftMonitor | re-export of opensmartroute.learning.slm.InputDriftMonitor | Label-free drift detection on what the SLM sees: Page-Hinkley over its top probability and over the share. |
KnowledgeEmbedding | re-export of opensmartroute.learning.kge.KnowledgeEmbedding | TransE entity / relation embeddings over a graph's triples (module docstring). |
LabelledCheck | re-export of opensmartroute.learning.slm.LabelledCheck | An SLM's score on the hand-labelled routing set (:meth:RouterSLM.labelled_check). |
LinUCBStrategy | class | Contextual bandit (LinUCB) on the signal vector; keeps the last context per request for the update. |
MarkovStrategy | class | Prefers targets that do well on the predicted next conversation state too. |
MixtureCureModel | re-export of opensmartroute.learning.handoff.MixtureCureModel | Weibull mixture-cure model on cumulative risk with censoring. |
NeuralRoutingHead | re-export of opensmartroute.learning.neural.NeuralRoutingHead | Dense classifier over hashed prompt features that picks a target - and a learned prompt representation. |
PolicyGradientStrategy | re-export of opensmartroute.learning.policy_gradient.PolicyGradientStrategy | REINFORCE-trained softmax routing policy over hashed request features. |
PreferenceStrategy | class | Bradley-Terry strengths per domain, fed by Outcome.preferred_over pairwise comparisons. |
ReactionLearner | re-export of opensmartroute.learning.implicit.ReactionLearner | Turns the next turn of a session into feedback on the previous one. |
ReadingWindow | re-export of opensmartroute.learning.window.ReadingWindow | How a token budget is spent on a prompt longer than it: head and tail shares of the budget go to the. |
RegretReport | re-export of opensmartroute.learning.policy_gradient.RegretReport | Decision regret versus prediction error on a scored dataset. |
ReplayMemory | re-export of opensmartroute.learning.neural.ReplayMemory | Bounded experience replay for the routing head: (text, history, target, reward, ts) per observed outcome,. |
RequestMemory | re-export of opensmartroute.learning.coldstart.RequestMemory | Bounded LRU of request texts keyed by request id - and, when the router tells it, the decision it took. |
ResponseAssessment | re-export of opensmartroute.learning.implicit.ResponseAssessment | What the answer itself says about its quality: a score, the signals that fired and the outcome source. |
RouterSLM | re-export of opensmartroute.learning.slm.RouterSLM | Small routing model: dual encoder + target catalogue snapshot + calibration, in one JSON file. |
SLMReport | re-export of opensmartroute.learning.slm.SLMReport | How an SLM did on a set of rows: accuracy, realised quality, cost, calibration and the training loss. |
SLMStrategy | re-export of opensmartroute.learning.slm.SLMStrategy | Ensemble member backed by a :class:RouterSLM: scores are its probabilities, it keeps learning online. |
SelfImprover | re-export of opensmartroute.learning.self_improve.SelfImprover | Closed loop that keeps a :class:RouterSLM current with the model market and its own traffic. |
SimilarityFallback | re-export of opensmartroute.learning.coldstart.SimilarityFallback | For targets with no observations yet, rank by request<->description similarity. |
SkillAffinity | re-export of opensmartroute.learning.personal.SkillAffinity | Profile-conditioned skill relevance: Beta posterior per (profile bucket, skill). |
TaskCredit | re-export of opensmartroute.learning.credit.TaskCredit | Buffers per-step outcomes of a task and redistributes the final reward (uniform / discounted / last / blend). |
TaskPins | re-export of opensmartroute.learning.credit.TaskPins | Admission-time pinning: task_id -> target_id while the target keeps succeeding. |
TokenCountModel | re-export of opensmartroute.learning.neural.TokenCountModel | Learns billed token counts from text: tokens ~ heuristic * exp(f(stats)) with f a small Keras MLP. |
UserAdaptiveStrategy | re-export of opensmartroute.learning.personal.UserAdaptiveStrategy | Per-user Beta posteriors per target, shrunk toward similar users and the global posterior. |
acceptable_set | re-export of opensmartroute.learning.contrastive.acceptable_set | Targets that are 'fine' for a row: expected + acceptable when labelled, otherwise every. |
assess_response | re-export of opensmartroute.learning.implicit.assess_response | Estimate the quality of response to request from the answer alone; None when the response. |
configured_encoder | re-export of opensmartroute.learning.slm.configured_encoder | The query encoder :class:RouterSLM builds from settings (OSR_SLM_ENCODER / OSR_SLM_EMBEDDER), in. |
decision_regret | re-export of opensmartroute.learning.policy_gradient.decision_regret | Mean decision regret of choose against the per-row oracle, next to the prediction error of. |
decision_reward | re-export of opensmartroute.learning.policy_gradient.decision_reward | Scalar decision reward of an outcome under objective (quality minus normalised cost/latency). |
dequantize_rows | re-export of opensmartroute.learning.quant.dequantize_rows | Inverse of :func:quantize_rows: key -> list of floats (q * scale per row). |
distill_router | re-export of opensmartroute.learning.slm.distill_router | Compress the full router into an SLM: route every text, take the ensemble's ranked utilities as soft. |
encoder_name | re-export of opensmartroute.learning.slm.encoder_name | The query encoder a model was trained with: hashed or attention, plus +embed(<name>) when a. |
history_vector | re-export of opensmartroute.learning.multiturn.history_vector | Recency-weighted joint embedding of the last turns messages and the current text. |
is_followup | re-export of opensmartroute.learning.slm.is_followup | Whether text only continues a conversation: at most max_words words (SLMSettings.context_max_words;. |
keras_embedder | re-export of opensmartroute.learning.neural.keras_embedder | Embedder from a saved :class:NeuralRoutingHead (keras:<path> in OSR_SLM_EMBEDDER). |
load_embedder | re-export of opensmartroute.learning.embed.load_embedder | Build the embedder a model file names (see the module docstring for the schemes). Raises. |
merge_learners | function (local: Iterable[Strategy], remote: Iterable[Strategy]) | Federated merge: fold the evidence of remote strategies into the same-named local. |
nearest_targets | re-export of opensmartroute.learning.coldstart.nearest_targets | The k most similar existing targets (cosine + same-kind and domain-overlap bonuses) for warm starts. |
negative_only | re-export of opensmartroute.learning.contrastive.negative_only | The one target a row says was bad (no labels, exactly one score, below threshold), else None. |
outcome_counts | re-export of opensmartroute.learning.coldstart.outcome_counts | Number of recorded outcomes per target id. |
paired_test | re-export of opensmartroute.learning.self_improve.paired_test | (wins, losses, p) of the challenger over the champion on the same rows: the discordant pairs and the. |
profile_bucket | re-export of opensmartroute.learning.personal.profile_bucket | Coarse profile bucket used to pool users with the same declared attributes. |
profile_vector | re-export of opensmartroute.learning.personal.profile_vector | Hashed one-hot encoding of key=value pairs (lists expand to one pair per element). |
quantization_report | re-export of opensmartroute.learning.quant.quantization_report | How far the quantised block is from rows: max / RMS absolute error, the error relative to the RMS. |
quantize_rows | re-export of opensmartroute.learning.quant.quantize_rows | Quantise rows (key -> vector, all of one length) to bits per weight with one scale per row. |
routing_text | re-export of opensmartroute.learning.slm.routing_text | The text the SLM encodes for a message inside a conversation. |
rows_with_context | re-export of opensmartroute.learning.slm.rows_with_context | Copies of rows whose text is :func:routing_text of the row and its history (rows without a. |
select_window | re-export of opensmartroute.learning.window.select_window | The window view of :func:read: tokens cut to at most cap. |
signal_vector | function (signals: Signals, domains: list[str] | None=None) | Fixed-length numeric context for contextual bandits (dim = 8 + len(domains)). |
soft_labels | re-export of opensmartroute.learning.contrastive.soft_labels | Zooter soft labels: softmax(score / temperature) over the scored targets. |
target_document | re-export of opensmartroute.learning.coldstart.target_document | Text used to embed a target: name, description, domains, actions, tags and up to 12 examples. |
target_embedding | re-export of opensmartroute.learning.coldstart.target_embedding | Unit-norm centroid of the target document and its examples (hashing embedder by default). |
tensorflow_available | re-export of opensmartroute.learning.neural.tensorflow_available | True when TensorFlow (and Keras 3) import; never raises. |
text_stats | re-export of opensmartroute.learning.neural.text_stats | Fixed-length, dependency-free description of text (see :data:TEXT_STATS): logs of the raw sizes and the. |
warm_start | re-export of opensmartroute.learning.coldstart.warm_start | Seed every learner with shrunk knowledge from the new target's nearest neighbours. |
warm_start_from_matrix | re-export of opensmartroute.learning.coldstart.warm_start_from_matrix | Offline full-information reward-matrix warm start (OrcaRouter 2605.30736). |
opensmartroute.learning.attention
A pure-Python transformer block for the routing SLM's query encoder.
| Name | Kind | Summary |
|---|---|---|
AttentionContext | class | Everything :meth:AttentionEncoder.backward needs from one forward pass (lists in pure Python, arrays. |
AttentionEncoder | class | One self-attention block with attention pooling; encodes text into a dim-vector (unnormalised). |
opensmartroute.learning.autopilot
Self-operation: the routing SLM runs its own improvement loop inside the live process.
| Name | Kind | Summary |
|---|---|---|
Autopilot | class | Runs a :class:SelfImprover on a schedule and on drift, inside a live process. |
DriftMonitor | class | Page-Hinkley over outcomes: alarms when the served success rate (or quality) drops for real. |
opensmartroute.learning.coldstart
Cold start for new targets and self-improving target descriptions.
| Name | Kind | Summary |
|---|---|---|
ExampleMiner | class | Promote prompts a target handled well into that target's examples. |
RequestMemory | class | Bounded LRU of request texts keyed by request id - and, when the router tells it, the decision it took. |
SimilarityFallback | class | For targets with no observations yet, rank by request<->description similarity. |
nearest_targets | function (new: RouteTarget, pool: Iterable[RouteTarget], k: int=3, embedder: Embedder | None=None) | The k most similar existing targets (cosine + same-kind and domain-overlap bonuses) for warm starts. |
outcome_counts | function (feedback: FeedbackStore) | Number of recorded outcomes per target id. |
target_document | function (t: RouteTarget) | Text used to embed a target: name, description, domains, actions, tags and up to 12 examples. |
target_embedding | function (t: RouteTarget, embedder: Embedder | None=None) | Unit-norm centroid of the target document and its examples (hashing embedder by default). |
warm_start | function (new: RouteTarget, registry: TargetRegistry, strategies: list[Strategy], k: int=3, shrink: float=0.5, embedder: Embedder | None=None) | Seed every learner with shrunk knowledge from the new target's nearest neighbours. |
opensmartroute.learning.contrastive
Contrastive and reward-distilled router training (RouterDC, NeurIPS 2024; Zooter 2311.08692).
| Name | Kind | Summary |
|---|---|---|
ContrastiveRouter | class | Dual-encoder router trained with a contrastive or a distillation objective. |
ContrastiveStrategy | class | Scores candidates with a trained :class:ContrastiveRouter. |
acceptable_set | function (row: EvalRow, slack: float=0.05) | Targets that are 'fine' for a row: expected + acceptable when labelled, otherwise every. |
negative_only | function (row: EvalRow, threshold: float=0.5) | The one target a row says was bad (no labels, exactly one score, below threshold), else None. |
soft_labels | function (scores: dict[str, float], temperature: float=0.1) | Zooter soft labels: softmax(score / temperature) over the scored targets. |
opensmartroute.learning.credit
Delayed, task-level credit assignment for agentic trajectories.
| Name | Kind | Summary |
|---|---|---|
TaskCredit | class | Buffers per-step outcomes of a task and redistributes the final reward (uniform / discounted / last / blend). |
TaskPins | class | Admission-time pinning: task_id -> target_id while the target keeps succeeding. |
opensmartroute.learning.embed
Pretrained transformer embeddings as frozen features for the routing SLM.
| Name | Kind | Summary |
|---|---|---|
EmbeddingFeaturizer | class | Hashed features plus a frozen dense embedding, indexed above the hashed space (dim + i). |
load_embedder | function (name: str, *, api_key_env: str='OSR_LLM_API_KEY', timeout_s: float=20.0, dims: int=0) | Build the embedder a model file names (see the module docstring for the schemes). Raises. |
openai_embedder | function (spec: str, *, api_key_env: str='OSR_LLM_API_KEY', timeout_s: float=20.0, batch: int=64, dims: int=0) | Embedder over an OpenAI-compatible /embeddings endpoint. spec is <model>[@<base_url>]; without. |
opensmartroute.learning.handoff
Permanent-handoff policy from censored teacher signals (TACIT-Switch 2608.27911).
| Name | Kind | Summary |
|---|---|---|
HandoffPolicy | class | Permanent handoff of a task to fallback_target once the failure risk is too high. |
MixtureCureModel | class | Weibull mixture-cure model on cumulative risk with censoring. |
Trajectory | class | Per-task state tracked by :class:HandoffPolicy: cumulative risk, steps, failure and hand-off flags. |
opensmartroute.learning.implicit
Implicit feedback: outcomes inferred from the answer itself and from what the user does next.
| Name | Kind | Summary |
|---|---|---|
NEGATIVE_REACTIONS | constant | A complaining next turn: the previous answer was wrong, unhelpful or off-target. |
POSITIVE_REACTIONS | constant | A satisfied next turn. |
ReactionLearner | class | Turns the next turn of a session into feedback on the previous one. |
ResponseAssessment | class | What the answer itself says about its quality: a score, the signals that fired and the outcome source. |
assess_response | function (request: RouteRequest, response: Any, target: RouteTarget | None=None, *, signals: Signals | None=None, latency_ms: float | None=None, settings: Settings | None=None) | Estimate the quality of response to request from the answer alone; None when the response. |
opensmartroute.learning.kge
A learned link predictor for the knowledge graph (optional extra tensorflow to train; numpy to use).
| Name | Kind | Summary |
|---|---|---|
KnowledgeEmbedding | class | TransE entity / relation embeddings over a graph's triples (module docstring). |
opensmartroute.learning.multiturn
Multi-turn routing with history-target joint embeddings (MTRouter 2604.23530).
| Name | Kind | Summary |
|---|---|---|
HistoryTargetModel | class | Logistic model over h * e_t with a shared weight vector and per-target biases. |
HistoryTargetStrategy | class | Scores each target by the learned success probability given the conversation so far. |
history_vector | function (request: RouteRequest, embedder: Embedder, turns: int=6, decay: float=0.7) | Recency-weighted joint embedding of the last turns messages and the current text. |
opensmartroute.learning.neural
TensorFlow / Keras models that sharpen two things the router does on every request (optional extra tensorflow).
| Name | Kind | Summary |
|---|---|---|
NeuralRoutingHead | class | Dense classifier over hashed prompt features that picks a target - and a learned prompt representation. |
ReplayMemory | class | Bounded experience replay for the routing head: (text, history, target, reward, ts) per observed outcome,. |
TEXT_STATS | constant | : Names of the :func:text_stats features, in order (the model's input layer). |
TokenCountModel | class | Learns billed token counts from text: tokens ~ heuristic * exp(f(stats)) with f a small Keras MLP. |
keras_embedder | function (path: str | Path) | Embedder from a saved :class:NeuralRoutingHead (keras:<path> in OSR_SLM_EMBEDDER). |
tensorflow_available | function () | True when TensorFlow (and Keras 3) import; never raises. |
text_stats | function (text: str) | Fixed-length, dependency-free description of text (see :data:TEXT_STATS): logs of the raw sizes and the. |
opensmartroute.learning.personal
Few-shot personalisation (GMTRouter 2511.08590; SkillFeed 2608.28241).
| Name | Kind | Summary |
|---|---|---|
SkillAffinity | class | Profile-conditioned skill relevance: Beta posterior per (profile bucket, skill). |
UserAdaptiveStrategy | class | Per-user Beta posteriors per target, shrunk toward similar users and the global posterior. |
profile_bucket | function (profile: dict[str, Any], keys: tuple[str, ...]=('tier', 'expertise', 'role', 'language')) | Coarse profile bucket used to pool users with the same declared attributes. |
profile_vector | function (profile: dict[str, Any], dim: int=_PROFILE_DIM) | Hashed one-hot encoding of key=value pairs (lists expand to one pair per element). |
opensmartroute.learning.policy_gradient
End-to-end policy-gradient routing (Router-R1 2506.09033; RLCascadeRouter 2608.15817).
| Name | Kind | Summary |
|---|---|---|
PolicyGradientStrategy | class | REINFORCE-trained softmax routing policy over hashed request features. |
RegretReport | class | Decision regret versus prediction error on a scored dataset. |
decision_regret | function (rows: Sequence[EvalRow], targets: Sequence[RouteTarget], choose: Callable[[EvalRow, Sequence[RouteTarget]], str], predict: Callable[[EvalRow, RouteTarget], float] | None=None) | Mean decision regret of choose against the per-row oracle, next to the prediction error of. |
decision_reward | function (outcome: Outcome, target: RouteTarget | None, objective: Objective, *, cost_scale: float=0.01, latency_scale: float=2000.0) | Scalar decision reward of an outcome under objective (quality minus normalised cost/latency). |
opensmartroute.learning.quant
Weight quantisation for the routing SLM's model file.
| Name | Kind | Summary |
|---|---|---|
QUANT_BITS | constant | supported weight widths; 0 in settings means "floats, no quantisation". |
dequantize_rows | function (blob: Mapping[str, Any]) | Inverse of :func:quantize_rows: key -> list of floats (q * scale per row). |
is_quantized | function (blob: Any) | True for a mapping written by :func:quantize_rows. |
quantization_report | function (rows: Mapping[str, Sequence[float]], blob: Mapping[str, Any]) | How far the quantised block is from rows: max / RMS absolute error, the error relative to the RMS. |
quantize_rows | function (rows: Mapping[str, Sequence[float]], bits: int=8) | Quantise rows (key -> vector, all of one length) to bits per weight with one scale per row. |
opensmartroute.learning.self_improve
Self-improvement loop: refresh the catalogue, gather evidence, train a challenger, promote it only if better.
| Name | Kind | Summary |
|---|---|---|
ImprovementReport | class | What one cycle did: evidence gathered, catalogue changes, champion vs challenger, and the verdict. |
SelfImprover | class | Closed loop that keeps a :class:RouterSLM current with the model market and its own traffic. |
paired_test | function (champion: Sequence[bool], challenger: Sequence[bool]) | (wins, losses, p) of the challenger over the champion on the same rows: the discordant pairs and the. |
opensmartroute.learning.slm
The OpenSmartRoute routing SLM: a small, self-contained model that picks the target for a prompt.
| Name | Kind | Summary |
|---|---|---|
BUNDLED | constant | model path that names the SLM shipped inside the package (RouterSLM.bundled()). |
CONTEXT_SEPARATOR | constant | : follows it under its own ctx: namespace (:data:~opensmartroute.signals.models.CONTEXT_MARK). |
FOLLOWUP_RE | constant | : does not match and routes on its own words - the demonstratives alone ("this", "it") are not a cue. |
SLM_FORMAT | constant | on-disk format version of RouterSLM.state() (2 = quantised weight blocks; 1 = float rows). |
SLM_FORMATS | constant | formats :meth:RouterSLM.load reads. |
InputDriftMonitor | class | Label-free drift detection on what the SLM sees: Page-Hinkley over its top probability and over the share. |
LabelledCheck | class | An SLM's score on the hand-labelled routing set (:meth:RouterSLM.labelled_check). |
RouterSLM | class | Small routing model: dual encoder + target catalogue snapshot + calibration, in one JSON file. |
SLMReport | class | How an SLM did on a set of rows: accuracy, realised quality, cost, calibration and the training loss. |
SLMStrategy | class | Ensemble member backed by a :class:RouterSLM: scores are its probabilities, it keeps learning online. |
configured_encoder | function (settings: Settings | None=None, champion: RouterSLM | None=None) | The query encoder :class:RouterSLM builds from settings (OSR_SLM_ENCODER / OSR_SLM_EMBEDDER), in. |
distill_router | function (router: Router, texts: Iterable[str], *, targets: Sequence[RouteTarget] | None=None, settings: Settings | None=None, seed: int=0) | Compress the full router into an SLM: route every text, take the ensemble's ranked utilities as soft. |
encoder_name | function (slm: RouterSLM) | The query encoder a model was trained with: hashed or attention, plus +embed(<name>) when a. |
is_followup | function (text: str, *, max_words: int | None=None, max_chars: int | None=None, settings: Settings | None=None) | Whether text only continues a conversation: at most max_words words (SLMSettings.context_max_words;. |
routing_text | function (text: str, history: Sequence[Mapping[str, Any]] | None=None, *, turns: int | None=None, chars: int | None=None, max_text_chars: int | None=None, settings: Settings | None=None) | The text the SLM encodes for a message inside a conversation. |
rows_with_context | function (rows: Iterable[EvalRow], settings: Settings | None=None) | Copies of rows whose text is :func:routing_text of the row and its history (rows without a. |
opensmartroute.learning.window
The reading window of the routing SLM over a long prompt.
| Name | Kind | Summary |
|---|---|---|
ReadingWindow | class | How a token budget is spent on a prompt longer than it: head and tail shares of the budget go to the. |
instruction_cues | function () | Words a request opens with: the first word of every task template of the ontology (less a few that are not. |
read | function (tokens: Sequence[str], cap: int, window: ReadingWindow | None=None) | (window, ask) of tokens under a budget of cap: the window is at most cap tokens - the salient. |
segment_salience | function (tokens: Sequence[str], cues: frozenset[str] | None=None, *, counts: Mapping[str, int] | None=None, novelty: float=0.0) | Instruction salience of one segment: cue words (an opening cue counts double) per square root of the. |
select_asks | function (tokens: Sequence[str], cap: int, window: ReadingWindow | None=None) | The ask view of :func:read: the sentences of a prompt over cap that ask for something (empty within it). |
select_window | function (tokens: Sequence[str], cap: int, window: ReadingWindow | None=None) | The window view of :func:read: tokens cut to at most cap. |
opensmartroute.math
Mathematical toolkit behind OpenSmartRoute's decisions.
| Name | Kind | Summary |
|---|---|---|
EWMA | re-export of opensmartroute.math.estimators.EWMA | Exponentially weighted moving mean and variance with a z-score helper. |
Bandit | re-export of opensmartroute.math.bandits.Bandit | Common interface. context is optional; non-contextual learners ignore it. |
BradleyTerry | re-export of opensmartroute.math.preference.BradleyTerry | Online Bradley-Terry: per-context target strengths from pairwise wins, with L2 and forgetting. |
ConformalCalibrator | re-export of opensmartroute.math.calibration.ConformalCalibrator | Split conformal prediction over routing candidates. |
CostAwareBandit | re-export of opensmartroute.math.bandits.CostAwareBandit | Lagrangian budget wrapper (C2MAB-V flavour). |
DelayedFeedback | re-export of opensmartroute.math.bandits.DelayedFeedback | Delayed-feedback wrapper (Joulani, György & Szepesvári, 2013). |
DirichletProbe | re-export of opensmartroute.math.dirichlet.DirichletProbe | Linear Dirichlet head over a fixed target list. |
Elo | re-export of opensmartroute.math.preference.Elo | Elo rating — a fixed-step Bradley–Terry with K-factor; handy for fast warm-up. |
EnergyModel | re-export of opensmartroute.math.energy.EnergyModel | Per-target linear energy model wh = e0 + e_in * prompt + e_out * output fit by ridge. |
EpsilonGreedy | re-export of opensmartroute.math.bandits.EpsilonGreedy | Explore uniformly with probability epsilon, otherwise exploit the empirical means. |
HardwareProfile | re-export of opensmartroute.math.energy.HardwareProfile | Static device characterisation used before measurements exist. |
IRTModel | re-export of opensmartroute.math.irt.IRTModel | Online 2PL IRT: target ability, item difficulty / discrimination via SGD, with forgetting and merge support. |
IsotonicCalibrator | re-export of opensmartroute.math.calibration.IsotonicCalibrator | Monotone non-decreasing map score -> P(correct), fitted with PAV. |
LinUCB | re-export of opensmartroute.math.bandits.LinUCB | Disjoint LinUCB (Li et al., WWW 2010) with Sherman–Morrison updates and optional. |
MarkovChain | re-export of opensmartroute.math.markov.MarkovChain | Dirichlet-smoothed transition counts. decay < 1 multiplies a row's counts by decay. |
MultiKnapsackBandit | re-export of opensmartroute.math.bandits.MultiKnapsackBandit | Bandits with several knapsack constraints (Badanidiyuru et al., 2013) with the. |
PageHinkley | re-export of opensmartroute.math.estimators.PageHinkley | Detects a decrease in the monitored mean (e.g. quality dropping). |
RoutingMDP | re-export of opensmartroute.math.markov.RoutingMDP | Finite-horizon / discounted MDP over conversation states and route actions. |
TemperatureScaler | re-export of opensmartroute.math.calibration.TemperatureScaler | Fits for confidence = softmax(u/\tau)[argmax] by 1-D golden-section. |
ThompsonBeta | re-export of opensmartroute.math.bandits.ThompsonBeta | Beta–Bernoulli Thompson sampling. |
UCB1 | re-export of opensmartroute.math.bandits.UCB1 | UCB1: ; untried arms get +inf. |
Welford | re-export of opensmartroute.math.estimators.Welford | Numerically stable running mean / variance (Welford's algorithm). |
WindowDrift | re-export of opensmartroute.math.estimators.WindowDrift | ADWIN-lite: compare the first and second half of a sliding window with a. |
bayesian_average | re-export of opensmartroute.math.estimators.bayesian_average | Shrink a small-sample mean toward a prior: (n·m + k·μ₀)/(n + k). |
brier_score | re-export of opensmartroute.math.calibration.brier_score | Mean squared error between confidence and the 0/1 correctness label. |
conformal_quantile | re-export of opensmartroute.math.calibration.conformal_quantile | Finite-sample corrected empirical quantile. |
digamma | re-export of opensmartroute.math.dirichlet.digamma | Digamma for x > 0 via recurrence to x >= 6 and the asymptotic series. |
dominates | re-export of opensmartroute.math.decision.dominates | a dominates b if it is ≥ quality, ≤ cost, ≤ latency and strictly better in one. |
entropy | re-export of opensmartroute.math.estimators.entropy | Shannon entropy (nats) of a probability vector. |
erlang_c | re-export of opensmartroute.math.decision.erlang_c | P(an arriving request must wait) for M/M/c. Returns 1.0 if unstable. |
expected_calibration_error | re-export of opensmartroute.math.estimators.expected_calibration_error | ECE: how well does router confidence predict routing correctness?. |
expected_wait | re-export of opensmartroute.math.decision.expected_wait | Mean time in queue (Wq) for M/M/c, in the same time unit as the rates. |
gini | re-export of opensmartroute.math.estimators.gini | Gini impurity 1 - sum(p^2); 0 = certain. |
hardware_profile | re-export of opensmartroute.math.energy.hardware_profile | Built-in profile by name (a100-80gb, h100-sxm, l4, rtx-4090, cpu-16c, npu-edge). |
item_key | re-export of opensmartroute.math.irt.item_key | Default item id: domain × difficulty bucket, e.g. legal/3. |
kingman_wait | re-export of opensmartroute.math.decision.kingman_wait | Kingman's G/G/1 approximation. |
littles_law | re-export of opensmartroute.math.decision.littles_law | L = λ·W — average number of in-flight requests. |
normalized_entropy | re-export of opensmartroute.math.estimators.normalized_entropy | 0 = certain, 1 = uniform. Useful as an 'ask the LLM judge' trigger. |
pareto_front | re-export of opensmartroute.math.decision.pareto_front | Keys of the non-dominated (quality, cost, latency) points. |
reliability_diagram | re-export of opensmartroute.math.calibration.reliability_diagram | Per-bin (mean confidence, empirical accuracy, count) — plot or print it. |
servers_for_sla | re-export of opensmartroute.math.decision.servers_for_sla | Smallest c such that E[Wq] ≤ max_wait and P(wait) ≤ max_p_wait. |
sigmoid | re-export of opensmartroute.math.irt.sigmoid | Overflow-safe logistic function. |
softmax | re-export of opensmartroute.math.estimators.softmax | Numerically stable softmax; lower temperature sharpens the distribution. |
topsis | re-export of opensmartroute.math.decision.topsis | TOPSIS closeness coefficient in [0,1]; quality is a benefit, cost/latency are costs. |
weighted_sum | re-export of opensmartroute.math.decision.weighted_sum | Scalarise w_q * quality - w_c * norm(cost) - w_l * norm(latency) with min-max normalised cost / latency. |
wilson_interval | re-export of opensmartroute.math.estimators.wilson_interval | Wilson score interval for a binomial proportion (robust at small n). |
opensmartroute.math.bandits
Multi-armed and contextual bandits for online routing decisions.
| Name | Kind | Summary |
|---|---|---|
Bandit | class | Common interface. context is optional; non-contextual learners ignore it. |
ThompsonBeta | class | Beta–Bernoulli Thompson sampling. |
UCB1 | class | UCB1: ; untried arms get +inf. |
LinUCB | class | Disjoint LinUCB (Li et al., WWW 2010) with Sherman–Morrison updates and optional. |
EpsilonGreedy | class | Explore uniformly with probability epsilon, otherwise exploit the empirical means. |
CostAwareBandit | class | Lagrangian budget wrapper (C2MAB-V flavour). |
MultiKnapsackBandit | class | Bandits with several knapsack constraints (Badanidiyuru et al., 2013) with the. |
DelayedFeedback | class | Delayed-feedback wrapper (Joulani, György & Szepesvári, 2013). |
opensmartroute.math.calibration
Calibration and distribution-free risk control for routing confidence.
| Name | Kind | Summary |
|---|---|---|
ConformalCalibrator | class | Split conformal prediction over routing candidates. |
IsotonicCalibrator | class | Monotone non-decreasing map score -> P(correct), fitted with PAV. |
TemperatureScaler | class | Fits for confidence = softmax(u/\tau)[argmax] by 1-D golden-section. |
brier_score | function (confidences: list[float], hits: list[bool]) | Mean squared error between confidence and the 0/1 correctness label. |
conformal_quantile | function (scores: list[float], alpha: float) | Finite-sample corrected empirical quantile. |
reliability_diagram | function (confidences: list[float], hits: list[bool], bins: int=10) | Per-bin (mean confidence, empirical accuracy, count) — plot or print it. |
opensmartroute.math.decision
Multi-objective decision helpers and queueing theory for real-time routing.
| Name | Kind | Summary |
|---|---|---|
dominates | function (a: Point, b: Point) | a dominates b if it is ≥ quality, ≤ cost, ≤ latency and strictly better in one. |
pareto_front | function (points: dict[str, Point]) | Keys of the non-dominated (quality, cost, latency) points. |
weighted_sum | function (points: dict[str, Point], w_q: float, w_c: float, w_l: float) | Scalarise w_q * quality - w_c * norm(cost) - w_l * norm(latency) with min-max normalised cost / latency. |
topsis | function (points: dict[str, Point], weights: Sequence[float]=(0.6, 0.25, 0.15)) | TOPSIS closeness coefficient in [0,1]; quality is a benefit, cost/latency are costs. |
erlang_c | function (arrival_rate: float, service_rate: float, servers: int) | P(an arriving request must wait) for M/M/c. Returns 1.0 if unstable. |
expected_wait | function (arrival_rate: float, service_rate: float, servers: int) | Mean time in queue (Wq) for M/M/c, in the same time unit as the rates. |
servers_for_sla | function (arrival_rate: float, service_rate: float, max_wait: float, max_p_wait: float=0.2) | Smallest c such that E[Wq] ≤ max_wait and P(wait) ≤ max_p_wait. |
littles_law | function (arrival_rate: float, mean_time_in_system: float) | L = λ·W — average number of in-flight requests. |
kingman_wait | function (utilization: float, ca2: float, cs2: float, mean_service: float) | Kingman's G/G/1 approximation. |
opensmartroute.math.dirichlet
Dirichlet probe over host hidden states (ProbeDirichlet, RouterXBench 2602.11877).
| Name | Kind | Summary |
|---|---|---|
DirichletProbe | class | Linear Dirichlet head over a fixed target list. |
digamma | function (x: float) | Digamma for x > 0 via recurrence to x >= 6 and the asymptotic series. |
opensmartroute.math.energy
Hardware-aware energy characterisation (HW-Router 2608.14575; 2608.28044).
| Name | Kind | Summary |
|---|---|---|
EnergyModel | class | Per-target linear energy model wh = e0 + e_in * prompt + e_out * output fit by ridge. |
HardwareProfile | class | Static device characterisation used before measurements exist. |
hardware_profile | function (name: str) | Built-in profile by name (a100-80gb, h100-sxm, l4, rtx-4090, cpu-16c, npu-edge). |
opensmartroute.math.estimators
Streaming estimators, drift detection and calibration.
| Name | Kind | Summary |
|---|---|---|
EWMA | class | Exponentially weighted moving mean and variance with a z-score helper. |
Welford | class | Numerically stable running mean / variance (Welford's algorithm). |
PageHinkley | class | Detects a decrease in the monitored mean (e.g. quality dropping). |
WindowDrift | class | ADWIN-lite: compare the first and second half of a sliding window with a. |
wilson_interval | function (successes: float, n: int, z: float=1.96) | Wilson score interval for a binomial proportion (robust at small n). |
bayesian_average | function (mean: float, n: int, prior_mean: float, prior_n: float=5.0) | Shrink a small-sample mean toward a prior: (n·m + k·μ₀)/(n + k). |
softmax | function (xs: list[float], temperature: float=1.0) | Numerically stable softmax; lower temperature sharpens the distribution. |
entropy | function (ps: list[float]) | Shannon entropy (nats) of a probability vector. |
normalized_entropy | function (ps: list[float]) | 0 = certain, 1 = uniform. Useful as an 'ask the LLM judge' trigger. |
gini | function (ps: list[float]) | Gini impurity 1 - sum(p^2); 0 = certain. |
expected_calibration_error | function (confidences: list[float], hits: list[bool], bins: int=10) | ECE: how well does router confidence predict routing correctness?. |
opensmartroute.math.irt
Item Response Theory for routing (IRT-Router, ACL 2025).
| Name | Kind | Summary |
|---|---|---|
sigmoid | function (z: float) | Overflow-safe logistic function. |
IRTModel | class | Online 2PL IRT: target ability, item difficulty / discrimination via SGD, with forgetting and merge support. |
item_key | function (domain: str, complexity: float, buckets: int=4) | Default item id: domain × difficulty bucket, e.g. legal/3. |
opensmartroute.math.markov
Markov chains and MDPs for conversational / multi-step routing.
| Name | Kind | Summary |
|---|---|---|
MarkovChain | class | Dirichlet-smoothed transition counts. decay < 1 multiplies a row's counts by decay. |
RoutingMDP | class | Finite-horizon / discounted MDP over conversation states and route actions. |
opensmartroute.math.preference
Bradley–Terry pairwise preference model (RouteLLM, Prompt-to-Leaderboard).
| Name | Kind | Summary |
|---|---|---|
BradleyTerry | class | Online Bradley-Terry: per-context target strengths from pairwise wins, with L2 and forgetting. |
Elo | class | Elo rating — a fixed-step Bradley–Terry with K-factor; handy for fast warm-up. |
opensmartroute.mcp_server
Model Context Protocol server: the router as a set of tools for any IDE or agent.
| Name | Kind | Summary |
|---|---|---|
PROTOCOL_VERSION | constant | : Protocol revision this server speaks by default. |
SESSION_TTL_S | constant | : How long an Mcp-Session-Id issued by :class:SessionIds stays valid. |
SUPPORTED_PROTOCOL_VERSIONS | constant | : Revisions accepted from clients (the client's choice is echoed when it is one of these). |
MCPServer | class | Serve a :class:Router (or an enterprise router wrapping one) over MCP. |
RemoteMCP | class | Forward JSON-RPC messages to an HTTP MCP endpoint (POST /mcp) - the bridge's counterpart of. |
SessionIds | class | Signed Mcp-Session-Id values for a Streamable HTTP server: <subject>.<expiry>.<nonce>.<mac>, checkable. |
ToolError | class | Raised inside a tool: reported to the client as a tool result with isError (not a protocol error). |
bridge_stdio | function (url: str, api_key: str | None=None) | Expose a remote HTTP MCP endpoint as a local stdio server (for clients that only spawn processes). |
catalogue_fingerprint | function (router: Any, tool_names: Iterable[str]=()) | A short digest of what tools/list / resources/list would show right now - the enabled targets of the. |
decision_dict | function (d: RouteDecision) | RouteDecision.to_dict() plus signals and the ranked candidates - what IDE clients want to show. |
log_message | function (level: str, data: Any, logger: str | None=None, *, minimum: str='info') | Send a notifications/message (MCP logging) at level when the transport can push and level is at. |
origin_allowed | function (origin: str | None, allowed: Iterable[str]=()) | The Streamable HTTP DNS-rebinding guard: a browser Origin must be loopback or one of allowed. |
report_progress | function (progress: float, total: float | None=None, message: str | None=None) | Send a notifications/progress for the tool call being served - a no-op when the client gave no. |
serve_stdio | function (server: Any, stdin: IO[bytes] | None=None, stdout: IO[str] | None=None) | Run server (anything with handle_json) over newline-delimited JSON on stdin/stdout until EOF. |
sse_frame | function (message: Any, event_id: str | None=None) | One message event of a server-sent-events reply (id: first when the stream is resumable). |
opensmartroute.media
Speech and image adapters for the OpenAI-compatible proxy (osr serve and the hosted platform).
| Name | Kind | Summary |
|---|---|---|
AUDIO_EXTENSIONS | constant | : File extensions /v1/audio/transcriptions accepts (what speech-to-text providers decode). |
AUDIO_TYPES | constant | : response_format -> media type of the audio /v1/audio/speech returns. |
MAX_AUDIO_BYTES | constant | : Largest audio upload accepted by /v1/audio/transcriptions (OpenAI's own limit). |
MAX_SPEECH_CHARS | constant | : Longest text /v1/audio/speech reads aloud in one call (OpenAI's own limit). |
MAX_UPSTREAM_BYTES | constant | : Largest body accepted back from a media provider (audio, image JSON, transcript) before the call is failed. |
SPEECH_TAG | constant | : Capability tag or metadata key that makes a target a /v1/audio/speech target. |
TRANSCRIPTION_TAG | constant | : Capability tag (capabilities.tags) or metadata key that makes a target a /v1/audio/transcriptions target. |
AudioInput | class | The uploaded audio of a transcription request, carried in request.context["audio"] (the bytes stay. |
audio_extension | function (filename: str) | The lower-cased extension of an upload when it is one speech-to-text providers decode, else None. |
image_handler | function (client: OpenAICompatClient, model: str, **defaults: Any) | RouteTarget.handler for text-to-image targets mapped to an OpenAI-compatible provider. |
images_response | function (decision: RouteDecision, result: Any, request: RouteRequest | None, fallback_from: list[str] | None, response_format: str) | The OpenAI images object (created, data[].url or b64_json, revised_prompt) from an. |
is_image_target | function (target: RouteTarget) | A tool whose capabilities say it produces images (actions: [image] or an image modality). |
media_only | function (target: RouteTarget) | A target that answers a non-chat endpoint only (embeddings, transcription, speech) and must never be. |
post_bytes | function (url: str, data: bytes, headers: dict[str, str], timeout_s: float, *, what: str, model: str) | POST to a provider and return (body, content type). |
speech_capable | function (target: RouteTarget) | True when a target serves /v1/audio/speech. |
speech_handler | function (client: OpenAICompatClient, model: str, **defaults: Any) | RouteTarget.handler for text-to-speech targets: POST {base_url}/audio/speech -> audio bytes. |
speech_result | function (decision: RouteDecision, result: Any) | (audio bytes, media type) of a speech handler result. |
transcription_capable | function (target: RouteTarget) | True when a target serves /v1/audio/transcriptions. |
transcription_handler | function (client: OpenAICompatClient, model: str, **defaults: Any) | RouteTarget.handler for speech-to-text targets: POST {base_url}/audio/transcriptions (multipart). |
transcription_response | function (decision: RouteDecision, result: Any, request: RouteRequest | None, fallback_from: list[str] | None) | The OpenAI transcription object (text, plus language / duration / segments when the. |
opensmartroute.migrate
Import another gateway's configuration as a routing catalogue.
| Name | Kind | Summary |
|---|---|---|
LITELLM_PROVIDERS | constant | : URL and credential variable each one resolves to when the config names none. |
Migration | class | What the import produced: the catalogue, the providers map, the aliases and the report. |
migrate_file | function (path: str | Path, out_dir: str | Path | None=None) | Read a LiteLLM config and, when out_dir is given, write the router's files. |
migrate_litellm | function (doc: Any) | Translate a parsed LiteLLM config.yaml into a :class:Migration. |
target_id | function (name: str) | A catalogue id from a deployment name: lower case, / and spaces become -. |
write_migration | function (m: Migration, out_dir: str | Path) | Write targets, providers and policy (aliases) files under out_dir; returns the paths written. |
opensmartroute.observability
Tracing and observability: every step of routing, execution and learning as a structured event.
| Name | Kind | Summary |
|---|---|---|
EVENT_NAMES | constant | Router.route. |
METRIC_PREFIX | constant | Prometheus metric name prefix (osr_). |
SPAN_NAMES | constant | : Every span name the SDK opens (an :class:Event with kind="span"). |
TRACEPARENT_KEY | constant | request.context key (and HTTP header) carrying an inbound W3C trace context. |
TRACE_ID_HEADER | constant | response header osr serve sets to the trace id of the request. |
Event | class | One captured span or event: flat, JSON-friendly, never carries request text. |
EventSink | class | Receiver port: override :meth:emit; live bridges may also implement :meth:span_start / :meth:span_end. |
FileSink | class | Append-only JSONL file, one event per line. |
LoggingSink | class | One JSON line per event on the opensmartroute.events logger (level follows the event). |
MemorySink | class | Thread-safe ring buffer of the newest max_events events; queryable by request, trace, name or level. |
MetricsSink | class | Counters and latency percentiles derived from events; :meth:prometheus renders the exposition text. |
Span | class | An open unit of work; a context manager that records duration, status and nested events. |
Tracer | class | Opens spans, records events and fans them out to sinks; sample_rate < 1 traces a share of requests. |
configure_tracing | function (*sinks: EventSink, sample_rate: float | None=None, settings: Settings | None=None) | Install sinks on the process-wide tracer. With no sinks, use the ones named by settings. |
current_tracer | function () | The tracer of the innermost open span, else the one bound with :func:use_tracer, else the global one. |
get_tracer | function () | The process-wide tracer (disabled until :func:configure_tracing adds sinks). |
render_trace | function (events: list[dict[str, Any]], *, width: int=100) | Render the events of one request (as MemorySink.trace / GET /trace/{id} return them) as a text tree:. |
text_digest | function (text: str) | Loggable stand-in for request text: {"text_sha256": <16 hex>, "text_len": n}. |
untraced | class | with untraced(): records nothing for the spans and events opened inside - whichever tracer they use. |
use_tracer | class | with use_tracer(t): makes t the tracer that :func:current_tracer returns in this context. |
opensmartroute.ocm
Open Capability Manifest (OCM) - a vendor-neutral description of any routable capability.
| Name | Kind | Summary |
|---|---|---|
OCM_KINDS | constant | : Manifest kinds (identical to :class:~opensmartroute.TargetKind values). |
OCM_PROTOCOLS | constant | : Endpoint protocols a manifest may declare; http and a2a can be bound to executors directly. |
OCM_VERSION | constant | : Current manifest version (the ocm field). |
bind_endpoint | function (target: RouteTarget, region: str | None=None, **kw: Any) | Attach an executor for the selected endpoint (http -> :func:~opensmartroute.adapters.http_handler,. |
capability_from_target | function (target: RouteTarget) | Reverse mapping: publish a target as an OCM v1 manifest (dict; dump as YAML or JSON). |
dump_capability | function (doc: dict[str, Any]) | Serialise a manifest to YAML when PyYAML is available, else to pretty JSON (both are valid OCM). |
is_capability | function (doc: Any) | True when doc looks like an OCM manifest (has an ocm version field). |
load_capabilities | function (paths: Iterable[str | Path] | str | Path, *, strict: bool=True) | Load manifests from files and/or directories (**/capability.{yaml,yml,json}). |
load_capability | function (path: str | Path, *, strict: bool=True) | Load one capability.yaml / .json manifest as a target. |
select_endpoint | function (target: RouteTarget, region: str | None=None) | The manifest endpoint to use: a region-matching one first, then the first region-less one. |
target_from_capability | function (doc: dict[str, Any], *, strict: bool=True) | Convert a manifest into a :class:~opensmartroute.RouteTarget (validating first when strict). |
validate_capability | function (doc: Any) | Validate a manifest; returns a list of human-readable problems (empty = valid). |
opensmartroute.policy
Policy layer: hard constraints that are never traded off against utility.
| Name | Kind | Summary |
|---|---|---|
DataBoundaryRule | class | The target's boundary must be at least as strict as the request's (public < private < on_prem). |
JailbreakRule | class | Risky prompts may only reach humans or targets tagged as safe. |
LanguageRule | class | The detected language must be declared by the target, unless it declares the wildcard language. |
Policy | class | Ordered chain of :data:PolicyRule; returns the first rejection reason or None. |
PolicyRule | constant | A hard-constraint check: return a rejection reason, or None to let the target through. |
allow_list | function (target: RouteTarget, request: RouteRequest, signals: Signals) | When the request names allow_targets, reject everything else. |
allowed_kinds | function (target: RouteTarget, request: RouteRequest, signals: Signals) | Reject kinds outside the request's allowed_kinds. |
context_window | function (target: RouteTarget, request: RouteRequest, signals: Signals) | Reject when the estimated input exceeds the target's context_window. |
cost_budget | function (target: RouteTarget, request: RouteRequest, signals: Signals) | Reject targets whose unit cost exceeds the request's max_cost_per_1k. |
default_rules | function (settings: PolicySettings | None=None) | The built-in chain, in evaluation order (cheap identity checks first). |
deny_list | function (target: RouteTarget, request: RouteRequest, signals: Signals) | Reject targets listed in the request's deny_targets. |
enabled | function (target: RouteTarget, request: RouteRequest, signals: Signals) | Reject disabled targets. |
input_tokens | function (target: RouteTarget, request: RouteRequest, signals: Signals) | Reject when the estimated input exceeds the target's max_tokens_in. |
latency_slo | function (target: RouteTarget, request: RouteRequest, signals: Signals) | Reject targets whose expected latency for this request's answer length exceeds max_latency_ms. |
modalities | function (target: RouteTarget, request: RouteRequest, signals: Signals) | Every modality detected in the request must be supported by the target. |
pii | function (target: RouteTarget, request: RouteRequest, signals: Signals) | Requests flagged as containing PII may only reach targets with pii_allowed. |
region | function (target: RouteTarget, request: RouteRequest, signals: Signals) | The request's region must be one the target serves (targets with no regions serve all). |
rule_name | function (rule: PolicyRule) | Display name of a rule: its name attribute, else __name__, else the class name. |
tenant | function (target: RouteTarget, request: RouteRequest, signals: Signals) | The request's tenant must be permitted by targets that restrict tenants; a tenant permission covers its. |
tools | function (target: RouteTarget, request: RouteRequest, signals: Signals) | When tools are required (constraint or context['tools']), LLM targets must supports_tools. |
opensmartroute.realtime
Real-time operational controls: health, circuit breaking, rate & budget limits.
| Name | Kind | Summary |
|---|---|---|
LIMIT_KEYS | constant | : metadata keys of a :class:RouteTarget that :meth:HealthRegistry.apply_limits reads. |
BUDGET_WINDOWS | constant | : Budget window names accepted under metadata.budget.per -> seconds. |
BreakerState | class | Circuit-breaker states: closed (healthy), open (tripped), half_open (probing recovery). |
CircuitBreaker | class | Classic three-state breaker with a sliding failure window. |
TokenBucket | class | Rate limiter: rate tokens/sec, burst up to capacity. Thread-safe. |
Budget | class | Rolling spend cap (e.g. USD per hour) per target or tenant. |
LatencyWindow | class | Rolling window of the last size latencies with nearest-rank percentiles (p50 / p90 / p99). |
TargetHealth | class | Live health of one target: breaker, latency EWMA + percentiles, success counts, optional rate limit / budget. |
HealthRegistry | class | Tracks health per target id. Shared by policy + strategy + executor. |
HealthPolicy | class | Policy that additionally rejects targets whose breaker is open, whose rate. |
HealthStrategy | class | Soft signal: observed reliability x latency-SLO fit from live health data. |
opensmartroute.responses
OpenAI Responses API (POST /v1/responses) on top of the chat-completions proxy.
| Name | Kind | Summary |
|---|---|---|
BUILTIN_TOOL_TYPES | constant | : Responses tools[].type values the chat path cannot execute (refused, never dropped). |
INPUT_ROLES | constant | : Responses input item roles that map onto chat messages. |
ResponseStore | class | Conversation state behind previous_response_id: the chat messages of each remembered response (its. |
ResponseStreamTranslator | class | Push-based translation of chat.completion.chunk SSE bytes into Responses API streaming events. |
chat_to_response | function (completion: dict[str, Any], request: dict[str, Any] | None=None, *, store: ResponseStore | None=None, scope: str | None=None, messages: list[dict[str, Any]] | None=None) | Shape a finished chat.completion as a Responses API response object. With store and the chat. |
response_events | function (events: Iterable[bytes], request: dict[str, Any] | None=None) | Translate a chat.completion.chunk SSE byte stream into Responses API streaming events. |
responses_to_chat | function (body: dict[str, Any], *, default_model: str='auto', store: ResponseStore | None=None, scope: str | None=None) | Translate a Responses API request body into a chat.completion request body. |
opensmartroute.retrieval
Retrieval-based candidate narrowing for very large target pools (ToolRet / Skill-RAG).
| Name | Kind | Summary |
|---|---|---|
BM25Index | class | In-memory BM25 (Okapi) index over target documents. |
DenseIndex | class | Cosine index. Default = sparse signed-hashing features with an inverted index (pure. |
NarrowingStats | class | Counters kept by the retrieval middleware: calls, how often it narrowed, last pool and kept sizes. |
RetrievalResult | class | Narrowed candidate ids with fused scores and how many came from the lexical / dense legs. |
Retriever | class | Hybrid lexical + dense narrowing that tracks a registry (or an explicit pool). |
execute_tool_target | function (registry: TargetRegistry, allow: Callable[[RouteTarget, dict[str, Any]], bool] | None=None, target_id: str='execute_tool') | A tool that runs a tool by id (with an optional allow-policy hook). |
narrow_signals_hint | function (signals: Signals) | Extra lexical hints from signals (domains / actions) appended to the retrieval query. |
rrf | function (rankings: list[list[tuple[str, float]]], k: int=60, weights: list[float] | None=None) | Reciprocal Rank Fusion over several ranked lists of (id, score). |
select_skill_set | function (request: RouteRequest | str, pool: list[RouteTarget], k: int=3, embedder: Embedder | None=None, redundancy: float=0.7, min_gain: float=0.02, relevance: dict[str, float] | None=None) | Greedy facility-location selection of complementary targets. |
target_text | function (t: RouteTarget) | Lexical document for a target: id, name, description, capabilities and up to 8 examples. |
tokenize | function (text: str) | Lower-case alphanumeric tokens. |
tool_search_target | function (retriever: Retriever, registry: TargetRegistry, kinds: tuple[str, ...]=('tool', 'skill'), k: int=8, target_id: str='tool_search') | A tool that finds tools: returns compact descriptors for the k best matches. |
opensmartroute.router
The Router: signals -> policy -> strategies -> ensemble -> decision (+plan).
| Name | Kind | Summary |
|---|---|---|
Router | class | Signals -> policy -> strategies -> ensemble -> decision (+ optional plan). |
NoRouteError | re-export of opensmartroute.errors.NoRouteError | No target satisfied the hard constraints. |
DEFAULT_WEIGHTS | constant | : Library-default ensemble weights (Settings().weights); kept for backwards compatibility. |
opensmartroute.sdk
OpenSmartRoute SDK: decorator-driven registration of routing components.
| Name | Kind | Summary |
|---|---|---|
RULE_CONDITIONS | constant | : Every key a rule's when mapping understands (:class:~opensmartroute.strategies.rules.Rule). |
ComponentKind | class | The component families a :class:ComponentRegistry can hold. |
ComponentRegistry | class | Blueprints for every routing component, with decorators that register into it. |
FunctionGuard | class | Adapts fn(request) -> None | str | False | RouteRequest into a middleware that runs before routing. |
FunctionMiddleware | class | Adapts fn(request, next_) -> RouteDecision. |
FunctionRule | class | A :class:~opensmartroute.strategies.rules.Rule whose when conditions may be completed by a. |
FunctionSignal | class | Adapts fn(request, signals) -> None | {field: value} | value. |
FunctionStrategy | class | Adapts fn(request, signals, candidates) -> {target_id: score | StrategyScore}. |
FunctionTelemetry | class | A telemetry sink made of plain callables: any of on_decision(request, decision),. |
Registration | class | A registered blueprint. factory() returns a fresh component instance. |
agent | constant | @agent(id, ...): shorthand for an agent target. |
aroute | constant | await aroute(text): the async form of route(). |
arun | constant | await arun(text): the async form of run(); coroutine handlers are awaited. |
components | constant | : The process-wide registry that the top-level decorators (opensmartroute.strategy ...) bind to. |
feedback | constant | feedback(decision, success=, quality=): learn from a decision in one call. |
guard | constant | @guard: fn(request) -> reason | RouteRequest | None runs before routing. |
handler | constant | @handler(*target_ids): bind code to targets declared in a catalogue. |
human | constant | @human(id, ...): shorthand for a human target. |
llm | constant | @llm(id, ...): shorthand for an llm target. |
middleware | constant | @middleware: register a Middleware class or fn(request, next_route). |
on_decision | constant | @on_decision: fn(request, decision) after every route. |
on_error | constant | @on_error: fn(request, error) when a route fails. |
on_outcome | constant | @on_outcome: fn(outcome) for every outcome learned. |
persona | constant | @persona(id, ...): shorthand for a slot-only persona target. |
policy_rule | constant | @policy_rule: register fn(target, request, signals) -> reason | None. |
route | constant | route(text): one request through the process-wide registry's router. |
rule | constant | rule(name, prefer=, avoid=, pin=, **when) or @rule(...) over a predicate. |
run | constant | run(text): route + execute + learn through the process-wide registry. |
signal | constant | @signal: register a SignalExtractor class or fn(request, signals) -> mapping | value. |
skill | constant | @skill(id, ...): shorthand for a skill target. |
strategy | constant | @strategy(weight=, name=): register a Strategy class or fn(request, signals, candidates). |
target | constant | @target(id, kind, ...): the decorated callable becomes a RouteTarget handler. |
telemetry | constant | @telemetry: register a Telemetry sink class or factory. |
tool | constant | @tool(id, ...): shorthand for a tool target. |
opensmartroute.security
Security controls for the routing control plane.
| Name | Kind | Summary |
|---|---|---|
GadgetDetector | re-export of opensmartroute.security.gadget.GadgetDetector | Learned tail classifier. score(text) in [0, 1]; split(text) finds the gadget tail. |
GuardMiddleware | class | Applies :class:InputGuard (+ optional redaction) before routing. |
GuardReport | class | Outcome of :meth:InputGuard.inspect: pass / fail, reasons, gadget suspicion score and the cleaned text. |
InputGuard | class | Validates and normalises request text. Cheap: O(len(text)). |
ModerationResult | re-export of opensmartroute.security.moderation.ModerationResult | One input's verdict: flagged plus per-category booleans, scores and the guard's reasons. |
OriginPolicy | re-export of opensmartroute.security.provenance.OriginPolicy | Decides which tool arguments must be user-originated and verifies them. |
OriginRule | re-export of opensmartroute.security.provenance.OriginRule | Per-target override. sensitive=None = infer from parameter names. |
OriginViolation | re-export of opensmartroute.security.provenance.OriginViolation | Raised by :class:OriginPolicy when a sensitive argument of a state-changing tool comes from untrusted text. |
OutputGuard | re-export of opensmartroute.security.output.OutputGuard | Screen a handler's answer for secrets, PII and instruction injection (see the module docstring). |
OutputReport | re-export of opensmartroute.security.output.OutputReport | Findings of :meth:OutputGuard.inspect: the (possibly rewritten) text plus what was found. |
Redactor | class | Replace PII with typed placeholders, e.g. <EMAIL_1>. Reversible per-request. |
ResourceLimitExceeded | re-export of opensmartroute.security.limits.ResourceLimitExceeded | A task went over one of its :class:ResourceLimits (steps, tool calls, depth, tokens, cost, wall time). |
ResourceLimitMiddleware | re-export of opensmartroute.security.limits.ResourceLimitMiddleware | Charge one step (+ the request's token estimate) per route() call. |
ResourceLimiter | re-export of opensmartroute.security.limits.ResourceLimiter | Thread-safe per-task accounting against :class:ResourceLimits. |
ResourceLimits | re-export of opensmartroute.security.limits.ResourceLimits | Per-task ceilings that stop runaway agents; enforced by :class:ResourceLimiter. |
SafetyCase | re-export of opensmartroute.security.safety.SafetyCase | One red-team scenario: an adversarial request, its clean baseline and the routing invariants to check. |
apply_limits | re-export of opensmartroute.security.limits.apply_limits | Wrap handlers of the given kinds. Returns the number wrapped. |
apply_origin_policy | re-export of opensmartroute.security.provenance.apply_origin_policy | Wrap every state-changing target in registry. Returns the number wrapped. |
description_risk | re-export of opensmartroute.security.injection.description_risk | Risk of a tool/agent description: max of injection lexicon and learned gadget score. |
expand_entities | function (names: list[str] | tuple[str, ...]) | Entity names with the groups of :data:~opensmartroute.signals.PII_GROUPS expanded; unknown names raise. |
guard_handler | re-export of opensmartroute.security.provenance.guard_handler | Return a copy of target whose handler enforces policy before invoking the tool. |
injection_risk | re-export of opensmartroute.security.injection.injection_risk | Shortcut for inspect_injection(text).score. |
inspect_injection | re-export of opensmartroute.security.injection.inspect_injection | Score instruction-injection likelihood with the matched lexicon entries for the trace. |
limit_handler | re-export of opensmartroute.security.limits.limit_handler | Copy of target whose handler charges one tool call (and nesting depth) per invocation. |
load_secret | function (name: str, *, file_env_suffix: str='_FILE', default: str | None=None) | 12-factor secret loading: NAME env var, else the file at NAME_FILE (k8s/Docker secrets). |
mark_untrusted | re-export of opensmartroute.security.provenance.mark_untrusted | Record content that entered the request from a non-user source. |
moderate | re-export of opensmartroute.security.moderation.moderate | The OpenAI moderation object for one string or a list of strings / {"type": "text", "text": ...}. |
moderate_text | re-export of opensmartroute.security.moderation.moderate_text | Classify one text with the input guard, the injection lexicon and the PII redactor. |
run_safety_suite | re-export of opensmartroute.security.safety.run_safety_suite | Run every case through route and return pass/fail details grouped by category. |
sanitize_for_prompt | function (text: str, max_len: int=4000) | Make user text safe to embed in an LLM-judge prompt. |
shannon_entropy | function (s: str) | Character-level Shannon entropy in bits (high values flag encoded / random payloads). |
strip_steering | re-export of opensmartroute.security.injection.strip_steering | Remove sentences that instruct the router (self-declared complexity, "use the best. |
synthesize_gadget_corpus | re-export of opensmartroute.security.gadget.synthesize_gadget_corpus | Labelled (text, label) rows: clean prompts + prompts with an appended gadget. |
opensmartroute.security.gadget
Learned confounder-gadget detector (Rerouting LLM Routers, Shafran et al. 2025).
| Name | Kind | Summary |
|---|---|---|
CLEAN | constant | class labels used by the detector and the synthetic corpus. |
GADGET | constant | class labels used by the detector and the synthetic corpus. |
GadgetDetector | class | Learned tail classifier. score(text) in [0, 1]; split(text) finds the gadget tail. |
synthesize_gadget_corpus | function (per_template: int=2, n_gadgets: int=400, seed: int=0) | Labelled (text, label) rows: clean prompts + prompts with an appended gadget. |
synthesize_gadgets | function (n: int, seed: int=0) | Adversarial suffixes drawn from the gadget families described in the paper. |
tail_features | function (tokens: Sequence[str]) | Hand-crafted statistics of a token window (all in [0, 1]) – complements hashed n-grams. |
opensmartroute.security.injection
Instruction-injection detection for text that is not the user's request.
| Name | Kind | Summary |
|---|---|---|
InjectionReport | class | Instruction-injection score in [0, 1] plus the lexicon hits that produced it. |
description_risk | function (text: str, gadget_score: float | None=None) | Risk of a tool/agent description: max of injection lexicon and learned gadget score. |
injection_risk | function (text: str) | Shortcut for inspect_injection(text).score. |
inspect_injection | function (text: str) | Score instruction-injection likelihood with the matched lexicon entries for the trace. |
opensmartroute.security.limits
Resource-amplification limits ("Beyond Max Tokens").
| Name | Kind | Summary |
|---|---|---|
ResourceLimitExceeded | class | A task went over one of its :class:ResourceLimits (steps, tool calls, depth, tokens, cost, wall time). |
ResourceLimitMiddleware | class | Charge one step (+ the request's token estimate) per route() call. |
ResourceLimiter | class | Thread-safe per-task accounting against :class:ResourceLimits. |
ResourceLimits | class | Per-task ceilings that stop runaway agents; enforced by :class:ResourceLimiter. |
TaskUsage | class | Running consumption of one task (steps, tool calls, depth, tokens, cost, timestamps). |
apply_limits | function (registry: TargetRegistry, limiter: ResourceLimiter, kinds: tuple[str, ...]=('tool', 'agent', 'workflow')) | Wrap handlers of the given kinds. Returns the number wrapped. |
limit_handler | function (target: RouteTarget, limiter: ResourceLimiter) | Copy of target whose handler charges one tool call (and nesting depth) per invocation. |
task_id_of | function (request: RouteRequest, key: str='task_id') | context[key] when present, otherwise the request id (each request is its own task). |
opensmartroute.security.moderation
POST /v1/moderations over the router's own guards.
| Name | Kind | Summary |
|---|---|---|
MODERATION_CATEGORIES | constant | : Category names of a moderation result (each has a boolean and a score in [0, 1]). |
MODERATION_MODEL | constant | : model reported by :func:moderate. |
ModerationResult | class | One input's verdict: flagged plus per-category booleans, scores and the guard's reasons. |
moderate | function (inputs: str | Iterable[Any], *, guard: Any | None=None, redactor: Any | None=None, flag_pii: bool=False, model: str=MODERATION_MODEL) | The OpenAI moderation object for one string or a list of strings / {"type": "text", "text": ...}. |
moderate_text | function (text: str, *, guard: Any | None=None, redactor: Any | None=None, flag_pii: bool=False) | Classify one text with the input guard, the injection lexicon and the PII redactor. |
opensmartroute.security.output
Response-side guard: what a target answered is screened before it leaves the router.
| Name | Kind | Summary |
|---|---|---|
OUTPUT_GUARD_MODES | constant | : Guard modes, weakest first. |
SECRET_PATTERNS | constant | : (name, pattern) of credential shapes an answer must not carry verbatim. |
STREAM_HOLD_CHARS | constant | : whole by :data:_OPEN_BLOCKS until its end arrives). |
STREAM_MAX_PENDING_CHARS | constant | : first-output delay stay bounded - a finding longer than this may reach the consumer in part. |
STREAM_MAX_RETAINED_CHARS | constant | : it the oldest text is dropped and :attr:StreamScreen.truncated is set. |
OutputGuard | class | Screen a handler's answer for secrets, PII and instruction injection (see the module docstring). |
OutputReport | class | Findings of :meth:OutputGuard.inspect: the (possibly rewritten) text plus what was found. |
StreamScreen | class | Pre-emission filter for one streamed answer: call it with every delta in place of the consumer's. |
opensmartroute.security.provenance
Origin (provenance) policy for tool parameters – ROPE-style control-flow integrity.
| Name | Kind | Summary |
|---|---|---|
OriginFinding | class | Where one tool argument's value came from (user, context, untrusted content or unknown). |
OriginPolicy | class | Decides which tool arguments must be user-originated and verifies them. |
OriginReport | class | Provenance check of a tool call: all findings plus the sensitive parameters with a disallowed origin. |
OriginRule | class | Per-target override. sensitive=None = infer from parameter names. |
OriginViolation | class | Raised by :class:OriginPolicy when a sensitive argument of a state-changing tool comes from untrusted text. |
SENSITIVE_PARAM_HINTS | constant | Parameter-name fragments treated as sensitive when a target has no explicit OriginRule. |
STATE_CHANGING_ACTIONS | constant | Verbs in a tool's id / description / actions that mark it as state-changing (side effects). |
apply_origin_policy | function (registry: TargetRegistry, policy: OriginPolicy) | Wrap every state-changing target in registry. Returns the number wrapped. |
guard_handler | function (target: RouteTarget, policy: OriginPolicy, arguments_key: str='tool_arguments') | Return a copy of target whose handler enforces policy before invoking the tool. |
mark_untrusted | function (request: RouteRequest, text: str, source: str='retrieved') | Record content that entered the request from a non-user source. |
untrusted_texts | function (request: RouteRequest) | (source, text) pairs recorded by :func:mark_untrusted on this request. |
user_texts | function (request: RouteRequest) | Everything the user actually typed: current text, prior user turns and the pre-guard original text. |
opensmartroute.security.safety
Safety-routing regression suite ("When Safety Routing Breaks").
| Name | Kind | Summary |
|---|---|---|
SafetyCase | class | One red-team scenario: an adversarial request, its clean baseline and the routing invariants to check. |
SafetyResult | class | Verdict for one :class:SafetyCase: chosen vs baseline target and the invariants that failed. |
default_cases | function (seed: int=0) | Deployment-agnostic red-team cases; extend with catalogue-specific ones. |
run_safety_suite | function (route: RouteCall, cases: Sequence[SafetyCase] | None=None, *, seed: int=0) | Run every case through route and return pass/fail details grouped by category. |
opensmartroute.server
Optional FastAPI server exposing the router over HTTP.
| Name | Kind | Summary |
|---|---|---|
APP_HEADER | constant | : Request header naming the calling application (OpenRouter-style attribution); echoed in metadata. |
ATTACHMENT_TYPES | constant | : Content-part types of a multi-part user message that are attachments (kept in context["attachments"]). |
AUTO_SLUG | constant | : Slug prefix of the router's own pseudo-models on the OpenAI-compatible proxy (osr/auto). |
AUTO_VARIANTS | constant | : osr/auto:<variant> presets: objective weights, hard constraints and allowed kinds. |
DEFAULT_PROXY_ALIASES | constant | : Model names that mean "let the router choose" on the OpenAI-compatible proxy. |
EMBEDDINGS_TAG | constant | : Capability tag / metadata key marking a target whose handler answers /v1/embeddings. |
EXECUTE_PATHS | constant | : ServerSettings.readonly_executes says otherwise. /mcp counts only for tools/call. |
OPEN_PATHS | constant | : Paths that never require a token when access control is on (probes, metrics, token check, OpenAPI pages). |
REQUEST_ID_HEADER | constant | : Response headers carrying the decision (target id, request id) beside the OpenAI-shaped body. |
TARGET_HEADER | constant | : Response headers carrying the decision (target id, request id) beside the OpenAI-shaped body. |
UNTRACED_PATHS | constant | : Paths that never open an http.request span (probes and the observability endpoints themselves). |
WRITE_PATHS | constant | : Paths a read-only token (<token>:ro) may not call: they change learner state or trigger work. |
AccessToken | class | One configured access token: the secret, whether it is read-only and an optional expiry (unix seconds). |
bearer_token | function (headers: Any) | The access token of a request: X-API-Key first, else Authorization: Bearer <token>. |
create_app | function (router: Any, proxy_aliases: frozenset[str]=DEFAULT_PROXY_ALIASES, autopilot: Any=None, auth_tokens: Iterable[str]=(), marketplace_sync: Any=None) | FastAPI app: /route, /feedback, /targets, /stats, /healthz and the OpenAI-compatible /v1. |
embeddings_capable | function (target: RouteTarget) | True when a target serves /v1/embeddings: tagged :data:EMBEDDINGS_TAG or metadata["embeddings"] set. |
embeddings_response | function (decision: RouteDecision, result: Any, request: RouteRequest | None=None, fallback_from: list[str] | None=None) | Shape an embeddings handler result ({"embeddings": [[...]], "model": ..., "prompt_tokens": n}) as an. |
find_token | function (token: str | None, tokens: Iterable[str]) | The configured :class:AccessToken the presented token matches (expired entries included), else None. |
proxy_request | function (body: dict[str, Any], aliases: frozenset[str]=frozenset({'auto'}), app: str | None=None) | Turn an OpenAI chat-completion body into a :class:RouteRequest. |
proxy_response | function (decision: RouteDecision, result: Any, request: RouteRequest | None=None, fallback_from: list[str] | None=None) | Shape an execution result as an OpenAI chat.completion object (model = chosen target id). |
rerank_response | function (embeddings: dict[str, Any], documents: list[str], *, top_n: int | None=None, return_documents: bool=False) | Shape an embeddings list object whose first vector is the query and the rest the documents as a. |
resolve_model | function (model: str, aliases: frozenset[str]=DEFAULT_PROXY_ALIASES) | Split a proxy model into (pinned target id | None, route options). |
token_accepted | function (token: str | None, tokens: Iterable[str]) | Constant-time membership test of token in the configured access tokens (scoped entries match too). |
opensmartroute.settings
Typed, environment-overridable settings: the only home for OpenSmartRoute's tunable constants.
| Name | Kind | Summary |
|---|---|---|
BanditSettings | class | Thompson-sampling strategy (:class:~opensmartroute.BanditStrategy). |
CapabilitySettings | class | Capability-fit strategy (:class:~opensmartroute.CapabilityStrategy). |
ClientSettings | class | The platform / osr serve client (:class:opensmartroute.client.OpenSmartRoute): timeouts and retries. |
CompressionSettings | class | Prompt compaction before an LLM / agent handler runs (:mod:opensmartroute.compress). |
EstimateSettings | class | Token counting behind :func:opensmartroute.estimate.estimate_tokens (signals, admission bound, quotes). |
ImplicitSettings | class | Implicit feedback (:mod:opensmartroute.learning.implicit): outcomes inferred from the response itself and. |
InferenceSettings | class | Sizing self-hosted model servers (:mod:opensmartroute.inference): what a model needs, what a host gives. |
KnowledgeSettings | class | Knowledge graph and context engineering (:mod:opensmartroute.knowledge). |
LearningSettings | class | Closing the loop (:class:~opensmartroute.learning.AutoLearner) against a shared state store. |
MarketplaceSettings | class | Following the marketplace (:class:~opensmartroute.adapters.marketplace.MarketplaceSync): osr serve keeps. |
ObservabilitySettings | class | Tracing and event capture (:mod:opensmartroute.observability); read by Tracer.from_settings. |
PolicySettings | class | Hard-constraint thresholds (read by :class:~opensmartroute.Policy). |
RoutingSettings | class | Ensemble, confidence and plan composition (read by :class:~opensmartroute.Router). |
RulesSettings | class | Declarative rules strategy (:class:~opensmartroute.RulesStrategy). |
SLMSettings | class | Routing SLM, dataset collection and the self-improvement loop (:mod:opensmartroute.learning.slm). |
ServerSettings | class | osr serve (:mod:opensmartroute.server): access control of the self-hosted HTTP API. |
Settings | class | All tunables, grouped by consumer. Immutable; derive variants with :meth:replace. |
WeightSettings | class | Ensemble weight per strategy name (looked up as weights[strategy.name]). |
configure | function (settings: Settings | None=None, **groups: Any) | Install process-wide settings. configure() with no arguments re-reads the environment;. |
get_settings | function () | The process-wide :class:Settings (environment overlay applied once, lazily). |
resolve | function (settings: Settings | None) | settings if given, else the process-wide settings (component constructors use this). |
opensmartroute.signals
Signal extraction: cheap, deterministic features computed from the request.
| Name | Kind | Summary |
|---|---|---|
ACTION_LEXICON | constant | Action label -> trigger phrases; the keys are the ontology action names (summarize, translate, ... escalate). |
DEFAULT_EXTRACTORS | constant | a caller that knows the task type corrects the lexicon before anything reads the actions. |
DEFAULT_ONTOLOGY | re-export of opensmartroute.signals.ontology.DEFAULT_ONTOLOGY | the built-in TASK_TYPES ontology used by TaskTypeSignal. |
DOMAIN_LEXICON | constant | Domain label -> trigger phrases; the keys are the ontology domain names targets and skills may declare. |
EVENT_LEXICON | re-export of opensmartroute.signals.events.EVENT_LEXICON | Event name -> (domains, actions). Keys are matched exactly, then by subject.* prefix. |
EVENT_SUBJECTS | re-export of opensmartroute.signals.events.EVENT_SUBJECTS | Generic fallbacks when the exact event / prefix is unknown: subject -> domain, verb -> action. |
EVENT_VERBS | re-export of opensmartroute.signals.events.EVENT_VERBS | event verb -> action when the exact event / prefix is unknown. |
FRESHNESS_CUES | constant | : Phrases that make an answer depend on the state of the world right now (weighted; see :func:freshness_need). |
STALE_CUES | constant | : Phrases that pin a request to the past or to timeless knowledge; they pull the freshness need down. |
TASK_PRIORS | re-export of opensmartroute.signals.models.TASK_PRIORS | name: (difficulty, reasoning_need, expected_output_tokens). |
TASK_TYPES | re-export of opensmartroute.signals.ontology.TASK_TYPES | ---------------------------------------------------------------- transformation. |
ComplexitySignal | class | Hybrid-LLM-style difficulty estimate in [0, 1]. |
DomainActionSignal | class | Arch-Router-style domain / action detection via lexicon matching. |
DraftResponseSignal | re-export of opensmartroute.signals.uncertainty.DraftResponseSignal | Query-response mixed representation: run a cheap drafter and expose draft features. |
EventInfo | re-export of opensmartroute.signals.events.EventInfo | Parsed event: raw name, subject, verb and the domains / actions it implies. |
EventSignal | re-export of opensmartroute.signals.events.EventSignal | Domains / actions from context["event"] and context["intent"] (event-driven requests). |
EventTrigger | re-export of opensmartroute.signals.uncertainty.EventTrigger | Event-triggered invocation: evaluate uncertainty features against rules and return the. |
FreshnessSignal | class | signals.freshness_need - whether the request is about the world now (:func:freshness_need). A high. |
HashedClassifier | re-export of opensmartroute.signals.models.HashedClassifier | Multinomial logistic regression over hashed features (sparse weights per class). |
HashedFeaturizer | re-export of opensmartroute.signals.models.HashedFeaturizer | Hashing-trick sparse features: words, bigrams, character n-grams and a few numeric text statistics. A text. |
HashedRegressor | re-export of opensmartroute.signals.models.HashedRegressor | Squared-loss linear regressor on hashed features; output clipped to [lo, hi]. |
HistorySignal | class | Conversation-state features from request.history (RCRouter-style):. |
LanguageSignal | class | language from script / stop-word hints (LANGUAGE_HINTS); defaults to en. |
LearnedDifficultySignal | class | Blend the heuristic complexity with a trained regressor (Hybrid-LLM style difficulty). |
LengthSignal | class | token_estimate from text + history length (about 4 characters per token). |
ModalitySignal | class | modalities from context keys (images / image_url, audio, files) on top of text. |
OutputLengthSignal | class | Expected output tokens (drives cost estimates and effort/max_tokens choices). |
ProfileSignal | class | User-profile features (request.profile): tier, expertise, preferences. |
ReasoningNeedSignal | class | How much a request benefits from extended thinking (ThinkSwitcher / Sketch-of-Thought). |
SensitivitySignal | class | PII and prompt-injection / jailbreak heuristics (vLLM-semantic-router-style). |
SignalExtractor | class | Fills in part of a :class:Signals object. |
SignalModelBundle | re-export of opensmartroute.signals.models.SignalModelBundle | All learned signal models together, persisted as one JSON document. |
TaskHintSignal | class | context["task_type"] from the caller (a form that knows it collects a translation, the synthetic corpus. |
TaskOntology | re-export of opensmartroute.signals.ontology.TaskOntology | Lookup helpers over :data:TASK_TYPES. |
TaskType | re-export of opensmartroute.signals.ontology.TaskType | One leaf of the task ontology: family, description, the actions it maps to and template phrasings. |
TaskTypeSignal | class | Ontology task type. Uses the learned classifier when one is loaded, else maps the. |
TriggerRule | re-export of opensmartroute.signals.uncertainty.TriggerRule | feature >= threshold (or <= when below=True) fires action. |
UncertaintyGate | re-export of opensmartroute.signals.uncertainty.UncertaintyGate | A cascade quality gate built from response uncertainty. |
VerbalisedDifficultySignal | re-export of opensmartroute.signals.uncertainty.VerbalisedDifficultySignal | Blend a verbalised difficulty into complexity and reasoning_need. |
WorkflowSignal | re-export of opensmartroute.signals.events.WorkflowSignal | Detect a workflow trigger (context["workflow"] or "run the |
apply_task_hint | function (signals: Signals, task_type: str, ontology: TaskOntology=DEFAULT_ONTOLOGY) | Trust a known task type over the lexicon: when task_type names an ontology type, its declared actions. |
extract_signals | function (request: RouteRequest, extractors: list[SignalExtractor] | None=None) | Run the extractor chain (DEFAULT_EXTRACTORS unless given) and return the populated :class:Signals. |
freshness_need | function (text: str, *, now: float | None=None) | How much an answer to text depends on facts that change - 0 for timeless or historical asks, towards 1. |
learned_extractors | function (bundle: SignalModelBundle) | Extractor pipeline with the trained :class:SignalModelBundle plugged in. |
load_training_rows | re-export of opensmartroute.signals.models.load_training_rows | Read JSONL training rows. Accepts eval-dataset rows too (prompt/text,. |
parse_difficulty | re-export of opensmartroute.signals.uncertainty.parse_difficulty | Map a verbalised difficulty (number, "7/10", "hard") to [0, 1]; None if unparseable. |
parse_event | re-export of opensmartroute.signals.events.parse_event | Map an event name (subject.verb, subject:verb or subject_verb) onto domains / actions. |
response_uncertainty | re-export of opensmartroute.signals.uncertainty.response_uncertainty | Post-hoc uncertainty features for a set of sampled answers. |
semantic_entropy | re-export of opensmartroute.signals.uncertainty.semantic_entropy | Entropy (nats) over meaning clusters of sampled answers; 0 when every sample agrees. |
synthesize_dataset | re-export of opensmartroute.signals.models.synthesize_dataset | Generate labelled prompts from ontology templates x topics with light noise. |
opensmartroute.signals.corpus
Natural-language prompts per task type: how people actually ask, not how the ontology templates phrase it.
| Name | Kind | Summary |
|---|---|---|
NATURAL_PROMPTS | constant | : Phrasings per ontology task type (TASK_TYPES names). Every entry is labelled with its key. |
opensmartroute.signals.events
Event- and workflow-driven signals for agentic inputs.
| Name | Kind | Summary |
|---|---|---|
EVENT_LEXICON | constant | Event name -> (domains, actions). Keys are matched exactly, then by subject.* prefix. |
EVENT_SUBJECTS | constant | Generic fallbacks when the exact event / prefix is unknown: subject -> domain, verb -> action. |
EVENT_VERBS | constant | event verb -> action when the exact event / prefix is unknown. |
EventInfo | class | Parsed event: raw name, subject, verb and the domains / actions it implies. |
EventSignal | class | Domains / actions from context["event"] and context["intent"] (event-driven requests). |
WorkflowSignal | class | Detect a workflow trigger (context["workflow"] or "run the |
parse_event | function (name: str) | Map an event name (subject.verb, subject:verb or subject_verb) onto domains / actions. |
opensmartroute.signals.models
Learned signal models: hashed n-gram linear models with no dependencies.
| Name | Kind | Summary |
|---|---|---|
TASK_PRIORS | constant | name: (difficulty, reasoning_need, expected_output_tokens). |
HashedClassifier | class | Multinomial logistic regression over hashed features (sparse weights per class). |
HashedFeaturizer | class | Hashing-trick sparse features: words, bigrams, character n-grams and a few numeric text statistics. A text. |
HashedRegressor | class | Squared-loss linear regressor on hashed features; output clipped to [lo, hi]. |
SignalModelBundle | class | All learned signal models together, persisted as one JSON document. |
load_training_rows | function (path: str | Path) | Read JSONL training rows. Accepts eval-dataset rows too (prompt/text,. |
synthesize_dataset | function (ontology: TaskOntology=DEFAULT_ONTOLOGY, topics: Sequence[str] | None=None, per_template: int=6, seed: int=0, natural: bool | int=True, natural_phrases: Mapping[str, Sequence[str]] | None=None) | Generate labelled prompts from ontology templates x topics with light noise. |
opensmartroute.signals.ontology
Task ontology: families -> types -> subtypes, with an orthogonal domain axis.
| Name | Kind | Summary |
|---|---|---|
DEFAULT_ONTOLOGY | constant | the built-in TASK_TYPES ontology used by TaskTypeSignal. |
TASK_TYPES | constant | ---------------------------------------------------------------- transformation. |
TaskOntology | class | Lookup helpers over :data:TASK_TYPES. |
TaskType | class | One leaf of the task ontology: family, description, the actions it maps to and template phrasings. |
opensmartroute.signals.uncertainty
Uncertainty signals that come from outside the query text.
| Name | Kind | Summary |
|---|---|---|
HEDGES | constant | Hedging phrases counted in a draft response (uncertainty evidence). |
SELF_CORRECTIONS | constant | Self-correction markers counted in a draft response. |
DraftResponseSignal | class | Query-response mixed representation: run a cheap drafter and expose draft features. |
EventTrigger | class | Event-triggered invocation: evaluate uncertainty features against rules and return the. |
TriggerRule | class | feature >= threshold (or <= when below=True) fires action. |
UncertaintyGate | class | A cascade quality gate built from response uncertainty. |
VerbalisedDifficultySignal | class | Blend a verbalised difficulty into complexity and reasoning_need. |
draft_features | function (text: str, draft: str, expected_tokens: int=0) | Features of a cheap draft answer relative to the query: hedging, refusal, self-correction,. |
parse_difficulty | function (value: Any) | Map a verbalised difficulty (number, "7/10", "hard") to [0, 1]; None if unparseable. |
response_uncertainty | function (samples: list[str], embedder: Embedder | None=None, threshold: float=0.85, p_true: float | None=None) | Post-hoc uncertainty features for a set of sampled answers. |
semantic_clusters | function (samples: Iterable[str], embedder: Embedder | None=None, threshold: float=0.85) | Greedy single-link clustering of answers into meaning classes; returns a cluster id per sample. |
semantic_entropy | function (samples: Iterable[str], embedder: Embedder | None=None, threshold: float=0.85) | Entropy (nats) over meaning clusters of sampled answers; 0 when every sample agrees. |
opensmartroute.stack
Declarative stacks: one document that describes a whole routing setup.
| Name | Kind | Summary |
|---|---|---|
REGISTRY_SCHEME | constant | : Scheme of marketplace references inside imports (registry://<slug>[@<version>]). |
STACK_VERSION | constant | : Current stack document version (the osr field). |
Resolver | constant | : Resolver for registry:// imports: takes the reference (without the scheme) and returns the stack document. |
Stack | class | A resolved stack: every import merged, ready to build a router. |
StackChange | class | One line of a plan: add / change / remove of a target, rule, setting or objective weight. |
StackPlan | class | What applying desired would change compared with current (osr stack plan). |
dump_stack | function (doc: dict[str, Any], fmt: str | None=None) | Serialise a stack document: fmt = "yaml" | "json"; default YAML when PyYAML is installed. |
is_stack | function (doc: Any) | True when doc looks like a stack document (kind: stack or an osr version with stack sections). |
load_stack | function (source: str | Path | dict[str, Any], *, resolver: Resolver | None=None, settings: Settings | None=None, _seen: frozenset[str]=frozenset()) | Load and resolve a stack (file path, registry:// reference or inline mapping), imports first. |
plan_stack | function (desired: Stack, current: Stack | None=None) | Diff desired against current (None = nothing deployed: everything is an add). |
registry_resolver | function (base_url: str) | Resolver for registry://slug[@version] imports against a marketplace. |
starter_stack | function (name: str='starter', description: str='') | A minimal, valid stack document to start from (what the marketplace publish wizard pre-fills). |
validate_stack | function (doc: Any) | Validate a stack document; returns human-readable problems (empty list = valid). Imports are not resolved. |
opensmartroute.strategies
| Name | Kind | Summary |
|---|---|---|
DEFAULT_RULES | re-export of opensmartroute.strategies.protocol.DEFAULT_RULES | Built-in risk / budget ladder: handoff > debate > aggregate > cascade > single. |
AggregateResult | re-export of opensmartroute.strategies.aggregate.AggregateResult | Outcome of :class:MixtureOfAgents: the final response, participants, winner and agreement ratio. |
AnnotatorPool | re-export of opensmartroute.strategies.human.AnnotatorPool | Skill estimation from agreement (Dawid-Skene EM) and quorum selection. Labels usually arrive from. |
AnnotatorSkill | re-export of opensmartroute.strategies.human.AnnotatorSkill | Per-domain Beta accuracy estimate, cost and latency of one human annotator. |
AuctionResult | re-export of opensmartroute.strategies.auction.AuctionResult | Winner, second-price payment and the per-bidder surplus / corrected claims of one auction. |
AuctionStrategy | re-export of opensmartroute.strategies.auction.AuctionStrategy | Error-aware reverse auction: bias-corrected bids, highest surplus wins, second-price payment. |
BanditStrategy | re-export of opensmartroute.strategies.bandit.BanditStrategy | Thompson-sampling Beta bandit per (context, target); context = dominant domain (+ plan role). |
BeliefTracker | re-export of opensmartroute.strategies.cascade.BeliefTracker | AutoMix-style POMDP belief over the hidden state "current answer is correct". |
BudgetVariant | re-export of opensmartroute.strategies.elastic.BudgetVariant | One budget of an elastic model. quality and cost_scale are relative to the parent. |
CacheEntry | re-export of opensmartroute.strategies.semantic_cache.CacheEntry | A cached response keyed by the embedding of its prompt, with source target, quality, timestamp and hits. |
CacheHit | re-export of opensmartroute.strategies.semantic_cache.CacheHit | The matched :class:CacheEntry and its similarity to the query. |
CapabilityStrategy | re-export of opensmartroute.strategies.capability.CapabilityStrategy | Declarative fit: domain / action overlap, complexity band, language, modality and quality prior. |
Cascade | re-export of opensmartroute.strategies.cascade.Cascade | Execute ranked targets in planner order (cheapest / MDP / POMDP), stopping when the quality gate passes. |
CascadePlanner | re-export of opensmartroute.strategies.cascade.CascadePlanner | Finite-horizon MDP over an ordered cascade with a stop action after each step. |
CascadeResult | re-export of opensmartroute.strategies.cascade.CascadeResult | Final response of a cascade with every step, the planned order and the planner's expected value. |
CascadeStep | re-export of opensmartroute.strategies.cascade.CascadeStep | One executed rung of a cascade: gate quality, latency, cost, acceptance and POMDP belief. |
DeferStrategy | re-export of opensmartroute.strategies.defer.DeferStrategy | Learning-to-defer: scores human targets by risk, PII, escalation intent, frustration and model uncertainty. |
EdgeCloudStrategy | re-export of opensmartroute.strategies.edge.EdgeCloudStrategy | Edge vs cloud tier choice: learned edge competence per complexity bucket vs upload / decode penalties. |
EffortStrategy | re-export of opensmartroute.strategies.defer.EffortStrategy | Match a target's reasoning effort_level to signals.reasoning_need; penalise over- and under-thinking. |
EscalationDecision | re-export of opensmartroute.strategies.escalation.EscalationDecision | Verdict after a streamed chunk: continue / escalate / done with the competence estimate and reason. |
EscalationResult | re-export of opensmartroute.strategies.modality.EscalationResult | Outcome of :class:ModalityEscalation: which target answered, whether it escalated, confidence, cost. |
HiddenStateStrategy | re-export of opensmartroute.strategies.probe.HiddenStateStrategy | Dirichlet probe over a dense request representation; confidence drops with epistemic uncertainty. |
HumanRoutingStrategy | re-export of opensmartroute.strategies.human.HumanRoutingStrategy | Scores HUMAN candidates by estimated accuracy in the request's domain. |
ImportanceGate | re-export of opensmartroute.strategies.memory.ImportanceGate | Hashed logistic gate: P(item will be used later | text, hint). |
LLMJudgeStrategy | re-export of opensmartroute.strategies.llm_judge.LLMJudgeStrategy | LLM-as-router with optional score calibration. |
MemoryItem | re-export of opensmartroute.strategies.memory.MemoryItem | One stored memory: text, size, turn written, learned importance gate, tier and usage counters. |
MemoryRouter | re-export of opensmartroute.strategies.memory.MemoryRouter | Routes memory writes to tiers under budgets and recalls the most valuable items per token. |
MemoryTier | re-export of opensmartroute.strategies.memory.MemoryTier | A storage tier: token capacity, read / write cost per token, latency and the minimum item value it accepts. |
MixtureOfAgents | re-export of opensmartroute.strategies.aggregate.MixtureOfAgents | Route-or-aggregate switch: below a confidence threshold call the top-k alternatives and aggregate. |
ModalityEscalation | re-export of opensmartroute.strategies.modality.ModalityEscalation | Try the text-only target on the surrogate first; escalate to the multimodal target on low confidence. |
ModalityStrategy | re-export of opensmartroute.strategies.modality.ModalityStrategy | Coverage of the request's modalities by each candidate, with surrogate discounts. |
MultiRoundExecutor | re-export of opensmartroute.strategies.progress.MultiRoundExecutor | Router-R1 style: keep routing/executing until the judge accepts or rounds run out. |
ProgressRouter | re-export of opensmartroute.strategies.progress.ProgressRouter | Route each step of a task with trajectory context. |
ProtocolChoice | re-export of opensmartroute.strategies.protocol.ProtocolChoice | The protocol picked for a request, the risk that drove it, the reason and the matching rule. |
ProtocolPolicy | re-export of opensmartroute.strategies.protocol.ProtocolPolicy | Ordered rule table from (risk, budget, task type) to a protocol, with per-protocol ledgers. |
ProtocolRule | re-export of opensmartroute.strategies.protocol.ProtocolRule | First matching rule wins. None bounds are open. |
QuorumPlan | re-export of opensmartroute.strategies.human.QuorumPlan | A chosen set of annotators with the quorum's majority accuracy, total cost and latency. |
RecallResult | re-export of opensmartroute.strategies.memory.RecallResult | Items recalled for a turn with their total tokens, read cost and latency. |
Round | re-export of opensmartroute.strategies.progress.Round | One route -> execute -> judge iteration of :class:MultiRoundExecutor. |
RoundResult | re-export of opensmartroute.strategies.progress.RoundResult | Final response of a multi-round run with every round and the shared task id. |
Rule | re-export of opensmartroute.strategies.rules.Rule | If all when conditions match, boost prefer targets and penalise avoid. |
RulesStrategy | re-export of opensmartroute.strategies.rules.RulesStrategy | Applies declarative :class:Rule preferences (prefer / avoid / pin) when their when conditions match. |
SelfEscalation | re-export of opensmartroute.strategies.escalation.SelfEscalation | Streaming competence monitor with Bayesian optimal stopping. |
SemanticCache | re-export of opensmartroute.strategies.semantic_cache.SemanticCache | Embedding-keyed LRU cache with TTL and a similarity threshold. Safe to share across threads:. |
SemanticCacheStrategy | re-export of opensmartroute.strategies.semantic_cache.SemanticCacheStrategy | Scores the cache target by calibrated hit quality; leaves real targets to the other strategies. |
SessionAffinityStrategy | re-export of opensmartroute.strategies.session.SessionAffinityStrategy | Prefer the target already serving context["session_id"] unless the intent shifted or it failed. |
SessionState | re-export of opensmartroute.strategies.session.SessionState | What the strategy remembers about one session. |
SimilarityStrategy | re-export of opensmartroute.strategies.similarity.SimilarityStrategy | Embed the request and each target's examples / description; score by best and top-k mean similarity. |
SpeculativeCascade | re-export of opensmartroute.strategies.speculative.SpeculativeCascade | Two-target cascade that overlaps the draft and the strong call when it pays. |
SpeculativeResult | re-export of opensmartroute.strategies.speculative.SpeculativeResult | Outcome of a speculative run: chosen mode, whether the draft was accepted, latency and cost. |
SpreadStrategy | re-export of opensmartroute.strategies.spread.SpreadStrategy | Spread requests across same-family targets in proportion to metadata[weight_key]. |
Strategy | re-export of opensmartroute.strategies.base.Strategy | Scores each candidate target in [0, 1] and explains why. |
StreamResult | re-export of opensmartroute.strategies.escalation.StreamResult | Text consumed by :func:wrap_stream, whether it escalated and the final decision. |
TaskProgress | re-export of opensmartroute.strategies.progress.TaskProgress | Where a multi-step task stands: step index, budget spent, failures in a row, last target, history. |
TaskTableStrategy | re-export of opensmartroute.strategies.task_table.TaskTableStrategy | Static task_type -> target -> quality table with family and prior fallbacks; learns from outcomes. |
TokenBudgetStrategy | re-export of opensmartroute.strategies.elastic.TokenBudgetStrategy | Score budgeted siblings by fit between the budget and the tokens the answer needs. |
decide_effort | re-export of opensmartroute.strategies.defer.decide_effort | Pick the effort level whose numeric value is closest to the reasoning need. |
default_bid | re-export of opensmartroute.strategies.auction.default_bid | Catalogue-derived bid: quality prior as the claim, unit cost per 1k tokens x tokens as the price. |
default_strategies | function (seed: int | None=None, settings: Settings | None=None, state_dir: str | Path | None=None) | The zero-configuration ensemble: capability fit + example similarity + Thompson bandit. |
expand_elastic | re-export of opensmartroute.strategies.elastic.expand_elastic | Create one sibling target per budget variant, sharing the parent's family, handler and metadata. |
expected_mode_costs | re-export of opensmartroute.strategies.speculative.expected_mode_costs | Expected weighted cost (objective.cost x USD + objective.latency x seconds) per mode. |
failure_risk | re-export of opensmartroute.strategies.protocol.failure_risk | Risk in [0, 1] that a single call fails: low confidence, high complexity and reasoning need,. |
hashing_embedder | re-export of opensmartroute.strategies.similarity.hashing_embedder | Word + bigram hashing embedder. Deterministic, zero deps, decent for routing. |
majority_vote | re-export of opensmartroute.strategies.aggregate.majority_vote | Largest meaning cluster wins; returns (answer, winner_target_id, agreement). |
quorum_accuracy | re-export of opensmartroute.strategies.human.quorum_accuracy | P(weighted majority is correct) for independent annotators with the given accuracies. |
request_modalities | re-export of opensmartroute.strategies.modality.request_modalities | Modalities a request carries and which of them have a text surrogate in context. |
wrap_stream | re-export of opensmartroute.strategies.escalation.wrap_stream | Consume chunks until the monitor escalates or the stream ends. |
opensmartroute.strategies.aggregate
Routing / aggregation switch (Mixture-of-Agents, Wang et al. 2024; JiSi 2601.01330).
| Name | Kind | Summary |
|---|---|---|
AggregateResult | class | Outcome of :class:MixtureOfAgents: the final response, participants, winner and agreement ratio. |
Aggregator | constant | (request, [(target_id, answer)]) -> answer. |
MixtureOfAgents | class | Route-or-aggregate switch: below a confidence threshold call the top-k alternatives and aggregate. |
Participant | class | One target's contribution to an aggregate: response, cost, latency, error and whether it agreed. |
majority_vote | function (request: RouteRequest, answers: list[tuple[str, Any]], embedder: Embedder | None=None, threshold: float=0.85) | Largest meaning cluster wins; returns (answer, winner_target_id, agreement). |
opensmartroute.strategies.auction
Error-aware reverse auction across providers (EA-RAM 2608.12719).
| Name | Kind | Summary |
|---|---|---|
AuctionResult | class | Winner, second-price payment and the per-bidder surplus / corrected claims of one auction. |
AuctionStrategy | class | Error-aware reverse auction: bias-corrected bids, highest surplus wins, second-price payment. |
BidFn | constant | -> (claimed P(success), price). |
BidderRecord | class | Calibration ledger of one bidder: signed claim bias and a Beta record of realised success. |
default_bid | function (target: RouteTarget, request: RouteRequest, signals: Signals) | Catalogue-derived bid: quality prior as the claim, unit cost per 1k tokens x tokens as the price. |
opensmartroute.strategies.bandit
Online-learning strategy: contextual Thompson-sampling bandit.
| Name | Kind | Summary |
|---|---|---|
BanditStrategy | class | Thompson-sampling Beta bandit per (context, target); context = dominant domain (+ plan role). |
opensmartroute.strategies.base
Strategy interface.
| Name | Kind | Summary |
|---|---|---|
Strategy | class | Scores each candidate target in [0, 1] and explains why. |
role_of | function (signals: Signals) | Plan-slot role (persona / skill / llm) the router is currently filling, or. |
memory_key | function (request_id: str, role: str | None) | Key for per-request strategy memory: the same request is scored once per plan role, and. |
opensmartroute.strategies.capability
Capability-fit strategy: match request signals to a target's declared capabilities.
| Name | Kind | Summary |
|---|---|---|
WEB_TAGS | constant | : Capability tags that say a target can reach the live web (grounded search models, browsing agents, search tools). |
GENERAL_DOMAIN | constant | : The extractor's fallback domain; a target that declares it serves any domain and is never "off-domain". |
CapabilityStrategy | class | Declarative fit: domain / action overlap, complexity band, language, modality and quality prior. |
opensmartroute.strategies.cascade
Cascade execution (FrugalGPT / Router-R1 multi-round / AutoMix POMDP).
| Name | Kind | Summary |
|---|---|---|
CascadeStep | class | One executed rung of a cascade: gate quality, latency, cost, acceptance and POMDP belief. |
CascadeResult | class | Final response of a cascade with every step, the planned order and the planner's expected value. |
CascadePlanner | class | Finite-horizon MDP over an ordered cascade with a stop action after each step. |
BeliefTracker | class | AutoMix-style POMDP belief over the hidden state "current answer is correct". |
Cascade | class | Execute ranked targets in planner order (cheapest / MDP / POMDP), stopping when the quality gate passes. |
opensmartroute.strategies.defer
Defer-to-human and effort ("think or not") strategies.
| Name | Kind | Summary |
|---|---|---|
DeferStrategy | class | Learning-to-defer: scores human targets by risk, PII, escalation intent, frustration and model uncertainty. |
EffortStrategy | class | Match a target's reasoning effort_level to signals.reasoning_need; penalise over- and under-thinking. |
decide_effort | function (signals: Signals, levels: tuple[str, ...]=('none', 'low', 'medium', 'high')) | Pick the effort level whose numeric value is closest to the reasoning need. |
opensmartroute.strategies.edge
Edge-cloud token-aware routing (Pro-Router 2608.28726; RelayLLM 2601.05167).
| Name | Kind | Summary |
|---|---|---|
EdgeCloudStrategy | class | Edge vs cloud tier choice: learned edge competence per complexity bucket vs upload / decode penalties. |
opensmartroute.strategies.elastic
Token-budget-aware routing to elastic / many-in-one models (Nemotron Elastic 2511.16664; Star 2605.07182).
| Name | Kind | Summary |
|---|---|---|
BudgetVariant | class | One budget of an elastic model. quality and cost_scale are relative to the parent. |
TokenBudgetStrategy | class | Score budgeted siblings by fit between the budget and the tokens the answer needs. |
expand_elastic | function (parent: RouteTarget, variants: list[BudgetVariant | dict[str, Any]]) | Create one sibling target per budget variant, sharing the parent's family, handler and metadata. |
opensmartroute.strategies.escalation
Bayesian self-escalation during generation (2608.24087).
| Name | Kind | Summary |
|---|---|---|
REFUSALS | constant | Refusal phrases that lower the streaming competence posterior. |
EscalationDecision | class | Verdict after a streamed chunk: continue / escalate / done with the competence estimate and reason. |
SelfEscalation | class | Streaming competence monitor with Bayesian optimal stopping. |
StreamResult | class | Text consumed by :func:wrap_stream, whether it escalated and the final decision. |
wrap_stream | function (chunks: Iterable[str], monitor: SelfEscalation | None=None) | Consume chunks until the monitor escalates or the stream ends. |
opensmartroute.strategies.human
Routing among human annotators and experts (QUORUM 2608.27974; Dawid-Skene 1979).
| Name | Kind | Summary |
|---|---|---|
AnnotatorPool | class | Skill estimation from agreement (Dawid-Skene EM) and quorum selection. Labels usually arrive from. |
AnnotatorSkill | class | Per-domain Beta accuracy estimate, cost and latency of one human annotator. |
HumanRoutingStrategy | class | Scores HUMAN candidates by estimated accuracy in the request's domain. |
QuorumPlan | class | A chosen set of annotators with the quorum's majority accuracy, total cost and latency. |
quorum_accuracy | function (accuracies: Sequence[float]) | P(weighted majority is correct) for independent annotators with the given accuracies. |
opensmartroute.strategies.llm_judge
Generative routing: let an LLM act as the router (Router-R1 / LLM-as-judge).
| Name | Kind | Summary |
|---|---|---|
PROMPT | constant | Prompt template for the judge; formatted with complexity, domains, actions, the catalogue and the request. |
LLMJudgeStrategy | class | LLM-as-router with optional score calibration. |
opensmartroute.strategies.memory
Memory-tier routing for agents (BudgetMem 2602.06025; Gated-Memory Routing 2609.00237).
| Name | Kind | Summary |
|---|---|---|
ImportanceGate | class | Hashed logistic gate: P(item will be used later | text, hint). |
MemoryItem | class | One stored memory: text, size, turn written, learned importance gate, tier and usage counters. |
MemoryRouter | class | Routes memory writes to tiers under budgets and recalls the most valuable items per token. |
MemoryTier | class | A storage tier: token capacity, read / write cost per token, latency and the minimum item value it accepts. |
RecallResult | class | Items recalled for a turn with their total tokens, read cost and latency. |
opensmartroute.strategies.modality
Multimodal routing and modality escalation (LatentRouter 2605.11301; modality escalation.
| Name | Kind | Summary |
|---|---|---|
EscalationResult | class | Outcome of :class:ModalityEscalation: which target answered, whether it escalated, confidence, cost. |
ModalityEscalation | class | Try the text-only target on the surrogate first; escalate to the multimodal target on low confidence. |
ModalityStrategy | class | Coverage of the request's modalities by each candidate, with surrogate discounts. |
request_modalities | function (request: RouteRequest) | Modalities a request carries and which of them have a text surrogate in context. |
opensmartroute.strategies.probe
Hidden-state routing with a Dirichlet probe (ProbeDirichlet, RouterXBench 2602.11877).
| Name | Kind | Summary |
|---|---|---|
HiddenStateStrategy | class | Dirichlet probe over a dense request representation; confidence drops with epistemic uncertainty. |
StateFn | constant | request -> dense feature / hidden-state vector. |
opensmartroute.strategies.progress
Agentic trajectories: per-step routing and multi-round execution.
| Name | Kind | Summary |
|---|---|---|
MultiRoundExecutor | class | Router-R1 style: keep routing/executing until the judge accepts or rounds run out. |
ProgressRouter | class | Route each step of a task with trajectory context. |
Round | class | One route -> execute -> judge iteration of :class:MultiRoundExecutor. |
RoundResult | class | Final response of a multi-round run with every round and the shared task id. |
TaskProgress | class | Where a multi-step task stands: step index, budget spent, failures in a row, last target, history. |
opensmartroute.strategies.protocol
Collaboration-protocol selection (2608.14927).
| Name | Kind | Summary |
|---|---|---|
DEFAULT_RULES | constant | Built-in risk / budget ladder: handoff > debate > aggregate > cascade > single. |
PROTOCOLS | constant | in escalation order. |
Protocol | constant | execution protocols. |
ProtocolChoice | class | The protocol picked for a request, the risk that drove it, the reason and the matching rule. |
ProtocolPolicy | class | Ordered rule table from (risk, budget, task type) to a protocol, with per-protocol ledgers. |
ProtocolRule | class | First matching rule wins. None bounds are open. |
failure_risk | function (decision: RouteDecision | None, signals: Signals | None=None, uncertainty: float | None=None) | Risk in [0, 1] that a single call fails: low confidence, high complexity and reasoning need,. |
opensmartroute.strategies.rules
Declarative rule-based routing (Arch-Router-style domain/action preferences).
| Name | Kind | Summary |
|---|---|---|
Rule | class | If all when conditions match, boost prefer targets and penalise avoid. |
RulesStrategy | class | Applies declarative :class:Rule preferences (prefer / avoid / pin) when their when conditions match. |
opensmartroute.strategies.semantic_cache
Semantic caching as a routing target (GPTCache; vLLM semantic router 2603.04444).
| Name | Kind | Summary |
|---|---|---|
CacheEntry | class | A cached response keyed by the embedding of its prompt, with source target, quality, timestamp and hits. |
CacheHit | class | The matched :class:CacheEntry and its similarity to the query. |
SemanticCache | class | Embedding-keyed LRU cache with TTL and a similarity threshold. Safe to share across threads:. |
SemanticCacheStrategy | class | Scores the cache target by calibrated hit quality; leaves real targets to the other strategies. |
opensmartroute.strategies.session
Session affinity: keep a conversation with the target that is already serving it.
| Name | Kind | Summary |
|---|---|---|
SessionAffinityStrategy | class | Prefer the target already serving context["session_id"] unless the intent shifted or it failed. |
SessionState | class | What the strategy remembers about one session. |
opensmartroute.strategies.similarity
Similarity-based routing (UniRoute / GraphRouter flavour).
| Name | Kind | Summary |
|---|---|---|
hashing_embedder | function (dim: int=512) | Word + bigram hashing embedder. Deterministic, zero deps, decent for routing. |
cosine | function (a: list[float], b: list[float]) | Cosine similarity; zero vectors are treated as unit norm (no division by zero). |
SimilarityStrategy | class | Embed the request and each target's examples / description; score by best and top-k mean similarity. |
opensmartroute.strategies.speculative
Speculative (draft-based) cascades (speculative cascades, Narasimhan et al. 2024; Differential.
| Name | Kind | Summary |
|---|---|---|
SpeculativeCascade | class | Two-target cascade that overlaps the draft and the strong call when it pays. |
SpeculativeResult | class | Outcome of a speculative run: chosen mode, whether the draft was accepted, latency and cost. |
expected_mode_costs | function (p_accept: float, draft: RouteTarget, strong: RouteTarget, objective: Objective, *, tokens: int=500, cancellable: bool=False, verify_ms: float=0.0) | Expected weighted cost (objective.cost x USD + objective.latency x seconds) per mode. |
opensmartroute.strategies.spread
Weighted spread across interchangeable deployments (LiteLLM "simple-shuffle", OpenRouter provider weights).
| Name | Kind | Summary |
|---|---|---|
SpreadStrategy | class | Spread requests across same-family targets in proportion to metadata[weight_key]. |
opensmartroute.strategies.task_table
Static task table strategy (SCX Router, 2609.02292).
| Name | Kind | Summary |
|---|---|---|
TaskTableStrategy | class | Static task_type -> target -> quality table with family and prior fallbacks; learns from outcomes. |
Something wrong or out of date on this page? Tell us - the page is named for you, so a one-line note is enough.