API reference
Every public module, class and function with its signature, generated from the source.
Every module under src/opensmartroute and every public name it exports, generated from the source
by python scripts/api_reference.py (checked by tests/test_docs.py; do not edit by hand). The
first line of each docstring is the summary; open the module for the full contract. Narrative
documentation: GUIDE.md (usage), SDK.md (stability, extension points),
ARCHITECTURE.md, MATH.md, ENTERPRISE.md,
SECURITY.md, RESEARCH.md.
Stability: names re-exported from opensmartroute (the top-level package) are frozen by
tests/public_api.json 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. (69 names)opensmartroute.adapters- Adapters connect OpenSmartRoute to real providers and infrastructure. (70 names)opensmartroute.adapters.a2a- Import A2A (Agent-to-Agent protocol) Agent Cards asTargetKind.AGENTtargets. (4 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.mcp- Import MCP (Model Context Protocol) tools asTargetKind.TOOLtargets. (11 names)opensmartroute.adapters.mcp_servers- MCP server recommendation (MCP-Zero 2506.01056; ToolRet 2603.06467). (3 names)opensmartroute.adapters.openai_compat- OpenAI-compatible HTTP client (stdlib only). (6 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. (14 names)opensmartroute.aio- Async façade. Routing itself is CPU-bound and sub-millisecond, so we run it in. (1 names)opensmartroute.branding- OpenSmartRoute naming conventions: one place for every brand-bound identifier. (27 names)opensmartroute.cli-osrcommand-line interface. (2 names)opensmartroute.config- Configuration loading: targets and rules from JSON or YAML. (3 names)opensmartroute.core- see module (16 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. (16 names)opensmartroute.credentials- Credentials for theosrCLI: where the access token lives and how it is obtained. (18 names)opensmartroute.discovery- Tool discovery beyond text similarity. (5 names)opensmartroute.enterprise- Enterprise integration layer: ports (hexagonal architecture), middleware and telemetry. (18 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. (7 names)opensmartroute.errors- Exception hierarchy. Every error raised by the SDK derives from :class:OpenSmartRouteError. (11 names)opensmartroute.estimate- Token, cost and latency estimates before a request is sent anywhere. (9 names)opensmartroute.eval- RouterBench-style evaluation harness. (19 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. (13 names)opensmartroute.eval.collect- Collect routing datasets from the Hugging Face Hub, your own feedback log and synthetic seeds. (29 names)opensmartroute.eval.criteria- Offline realisations of the ROADMAP 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. (5 names)opensmartroute.feedback- Feedback store: append-only outcome log that closes the learning loop. (1 names)opensmartroute.learning- Auto-learning strategies built on :mod:opensmartroute.math. (47 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). (4 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. (2 names)opensmartroute.learning.handoff- Permanent-handoff policy from censored teacher signals (TACIT-Switch 2608.27911). (3 names)opensmartroute.learning.multiturn- Multi-turn routing with history-target joint embeddings (MTRouter 2604.23530). (3 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.self_improve- Self-improvement loop: refresh the catalogue, gather evidence, train a challenger, promote it only if better. (2 names)opensmartroute.learning.slm- The OpenSmartRoute routing SLM: a small, self-contained model that picks the target for a prompt. (5 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. (8 names)opensmartroute.observability- Tracing and observability: every step of routing, execution and learning as a structured event. (18 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. (9 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. (16 names)opensmartroute.security- Security controls for the routing control plane. (27 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.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. (14 names)opensmartroute.settings- Typed, environment-overridable settings: the only home for OpenSmartRoute's tunable constants. (13 names)opensmartroute.signals- Signal extraction: cheap, deterministic features computed from the request. (44 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. (12 names)opensmartroute.strategies- see module (66 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. (1 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.task_table- Static task table strategy (SCX Router, 2609.02292). (1 names)
opensmartroute#
Source: src/opensmartroute/init.py
OpenSmartRoute — an open, intelligent route to the right decision, solution, or destination.
| Name | Kind | Summary |
|---|---|---|
AsyncRouter | re-export of opensmartroute.aio.AsyncRouter | await-able wrapper around a :class:Router: route / learn / execute / run off the event loop. |
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. |
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. |
FeedbackStore | re-export of opensmartroute.feedback.FeedbackStore | Append-only :class:Outcome log (in memory or JSONL file) with per-target statistics. |
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. |
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. |
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. |
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, and 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. |
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. |
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). |
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). |
policy_rule | re-export of opensmartroute.sdk.policy_rule | @policy_rule: register fn(target, request, signals) -> reason | None. |
signal | re-export of opensmartroute.sdk.signal | @signal: register a SignalExtractor class or fn(request, signals) -> mapping. |
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.adapters#
Source: src/opensmartroute/adapters/init.py
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. |
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 and the 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. |
InMemoryQueue | re-export of opensmartroute.adapters.handlers.InMemoryQueue | Reference :class:Queue: FIFO in memory, resolves into :class:~opensmartroute.Outcome. |
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. |
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). |
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. |
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. |
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 return (client, targets). |
duckduckgo_search | re-export of opensmartroute.adapters.websearch.duckduckgo_search | DuckDuckGo instant-answer API (abstract + related topics). Keyless; shallow but good for definitions. |
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_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_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). |
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. |
mcp_tool_handler | re-export of opensmartroute.adapters.handlers.mcp_tool_handler | RouteTarget.handler that invokes one MCP tool via call(name, arguments). |
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. |
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. |
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. |
route_and_execute | re-export of opensmartroute.adapters.frameworks.route_and_execute | Route text and optionally execute the plan; returns (decision, ExecutionResult | None). |
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. |
opensmartroute.adapters.a2a#
Source: src/opensmartroute/adapters/a2a.py
Import A2A (Agent-to-Agent protocol) Agent Cards as TargetKind.AGENT targets.
| Name | Kind | Summary |
|---|---|---|
a2a_handler | function (url: str, token: str | None=None, timeout_s: float=60.0, method: str='message/send') | 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.catalogue#
Source: src/opensmartroute/adapters/catalogue.py
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#
Source: src/opensmartroute/adapters/frameworks.py
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#
Source: src/opensmartroute/adapters/handlers.py
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#
Source: src/opensmartroute/adapters/harness.py
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.mcp#
Source: src/opensmartroute/adapters/mcp.py
Import MCP (Model Context Protocol) tools as TargetKind.TOOL targets.
| Name | Kind | Summary |
|---|---|---|
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='', **kw: Any) | Spawn a stdio MCP server, list its tools and return (client, targets). |
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). |
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#
Source: src/opensmartroute/adapters/mcp_servers.py
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.openai_compat#
Source: src/opensmartroute/adapters/openai_compat.py
OpenAI-compatible HTTP client (stdlib only).
| Name | Kind | Summary |
|---|---|---|
ChatResult | class | Result of a chat completion: text, model, token counts, latency and the 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. |
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. |
opensmartroute.adapters.optional#
Source: src/opensmartroute/adapters/optional.py
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#
Source: src/opensmartroute/adapters/personas.py
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#
Source: src/opensmartroute/adapters/semantic_router.py
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#
Source: src/opensmartroute/adapters/skills.py
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#
Source: src/opensmartroute/adapters/websearch.py
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). |
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_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. |
opensmartroute.aio#
Source: src/opensmartroute/aio.py
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 :class:Router: route / learn / execute / run off the event loop. |
opensmartroute.branding#
Source: src/opensmartroute/branding.py
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_...). |
METADATA_PREFIX | constant | osr- - SKILL.md / persona front-matter keys (osr-domains). |
PACKAGE | constant | Python package / distribution / logger root. |
REPOSITORY | constant | source repository (installer fallback URLs). |
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#
Source: src/opensmartroute/cli.py
osr command-line interface.
| Name | Kind | Summary |
|---|---|---|
build_router | function (targets: str, 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). |
main | function (argv: list[str] | None=None) | Entry point of the osr console script; returns the process exit status. |
opensmartroute.config#
Source: src/opensmartroute/config.py
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#
Source: src/opensmartroute/core/init.py
| Name | Kind | Summary |
|---|---|---|
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. |
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#
Source: src/opensmartroute/core/registry.py
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#
Source: src/opensmartroute/core/types.py
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). |
RoutePlan | class | A composed route (MasRouter-style): several targets working together. |
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#
Source: src/opensmartroute/credentials.py
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.discovery#
Source: src/opensmartroute/discovery.py
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#
Source: src/opensmartroute/enterprise/init.py
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. |
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. |
opensmartroute.enterprise.ops#
Source: src/opensmartroute/enterprise/ops.py
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#
Source: src/opensmartroute/enterprise/savings.py
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#
Source: src/opensmartroute/enterprise/stores.py
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. |
opensmartroute.errors#
Source: src/opensmartroute/errors.py
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. |
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 policy in CONTRIBUTING.md. |
opensmartroute.estimate#
Source: src/opensmartroute/estimate.py
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. |
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) | Approximate the tokenizer count of text without any tokenizer library. |
target_prices | function (target: RouteTarget) | (usd per 1k input tokens, usd per 1k output tokens) from the target's declared cost. |
opensmartroute.eval#
Source: src/opensmartroute/eval/init.py
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_rows | re-export of opensmartroute.eval.collect.synthetic_rows | Ontology seed prompts labelled with the best capability-fit target (cold-start supervision). |
opensmartroute.eval.agentic#
Source: src/opensmartroute/eval/agentic.py
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#
Source: src/opensmartroute/eval/audit.py
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#
Source: src/opensmartroute/eval/baselines.py
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 (default: 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). |
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. |
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#
Source: src/opensmartroute/eval/collect.py
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. |
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) | 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_rows | function (targets: Sequence[RouteTarget], *, per_template: int=2, seed: int=0) | Ontology seed prompts labelled with the best capability-fit target (cold-start supervision). |
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#
Source: src/opensmartroute/eval/criteria.py
Offline realisations of the ROADMAP 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#
Source: src/opensmartroute/eval/datasets.py
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#
Source: src/opensmartroute/eval/frontier.py
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#
Source: src/opensmartroute/eval/headroom.py
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#
Source: src/opensmartroute/eval/ope.py
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#
Source: src/opensmartroute/eval/robustness.py
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#
Source: src/opensmartroute/execution.py
Plan-aware execution: turn a :class:RouteDecision into a real answer.
| Name | Kind | Summary |
|---|---|---|
PRELUDE_ROLES | constant | Roles executed before the primary target, in this order. |
ExecutionResult | class | What happened when a decision was executed. |
ExecutionStep | class | One executed plan slot: role, target, latency and whether it succeeded. |
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. |
execute | function (decision: RouteDecision, request: RouteRequest, learn: LearnFn | None=None, *, min_slot_confidence: float=0.0, task_id: str | None=None, **kw: Any) | Run the plan (persona -> skill -> primary) and record outcomes via learn. |
opensmartroute.feedback#
Source: src/opensmartroute/feedback/init.py
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.learning#
Source: src/opensmartroute/learning/init.py
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. |
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. |
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. |
RegretReport | re-export of opensmartroute.learning.policy_gradient.RegretReport | Decision regret versus prediction error on a scored dataset. |
RequestMemory | re-export of opensmartroute.learning.coldstart.RequestMemory | Bounded LRU of request texts keyed by request id. |
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, and 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. |
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. |
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). |
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. |
history_vector | re-export of opensmartroute.learning.multiturn.history_vector | Recency-weighted joint embedding of the last turns messages and the current text. |
load_embedder | re-export of opensmartroute.learning.embed.load_embedder | Build the embedder a model file names: sentence-transformers/... (or any Hugging Face id) via. |
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. |
outcome_counts | re-export of opensmartroute.learning.coldstart.outcome_counts | Number of recorded outcomes per target id. |
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). |
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). |
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#
Source: src/opensmartroute/learning/attention.py
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. |
AttentionEncoder | class | One self-attention block with attention pooling; encodes text into a dim-vector (unnormalised). |
opensmartroute.learning.autopilot#
Source: src/opensmartroute/learning/autopilot.py
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#
Source: src/opensmartroute/learning/coldstart.py
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. |
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#
Source: src/opensmartroute/learning/contrastive.py
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. |
soft_labels | function (scores: dict[str, float], temperature: float=0.1) | Zooter soft labels: softmax(score / temperature) over the scored targets. |
opensmartroute.learning.credit#
Source: src/opensmartroute/learning/credit.py
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#
Source: src/opensmartroute/learning/embed.py
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) | Build the embedder a model file names: sentence-transformers/... (or any Hugging Face id) via. |
opensmartroute.learning.handoff#
Source: src/opensmartroute/learning/handoff.py
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.multiturn#
Source: src/opensmartroute/learning/multiturn.py
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.personal#
Source: src/opensmartroute/learning/personal.py
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#
Source: src/opensmartroute/learning/policy_gradient.py
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.self_improve#
Source: src/opensmartroute/learning/self_improve.py
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. |
opensmartroute.learning.slm#
Source: src/opensmartroute/learning/slm.py
The OpenSmartRoute routing SLM: a small, self-contained model that picks the target for a prompt.
| Name | Kind | Summary |
|---|---|---|
SLM_FORMAT | constant | on-disk format version of RouterSLM.state(). |
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, and it keeps learning online. |
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. |
opensmartroute.math#
Source: src/opensmartroute/math/init.py
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 :math:\tau 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: :math:\hat\mu_a + c\sqrt{\frac{2\ln t}{n_a}}; 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 :math:\lceil (n+1)(1-\alpha)\rceil / n empirical quantile. |
digamma | re-export of opensmartroute.math.dirichlet.digamma | Digamma :math:\psi(x) 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#
Source: src/opensmartroute/math/bandits.py
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: :math:\hat\mu_a + c\sqrt{\frac{2\ln t}{n_a}}; 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#
Source: src/opensmartroute/math/calibration.py
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 :math:\tau 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 :math:\lceil (n+1)(1-\alpha)\rceil / n 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#
Source: src/opensmartroute/math/decision.py
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#
Source: src/opensmartroute/math/dirichlet.py
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 :math:\psi(x) for x > 0 via recurrence to x >= 6 and the asymptotic series. |
opensmartroute.math.energy#
Source: src/opensmartroute/math/energy.py
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#
Source: src/opensmartroute/math/estimators.py
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#
Source: src/opensmartroute/math/irt.py
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#
Source: src/opensmartroute/math/markov.py
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#
Source: src/opensmartroute/math/preference.py
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#
Source: src/opensmartroute/mcp_server.py
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. |
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. |
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). |
decision_dict | function (d: RouteDecision) | RouteDecision.to_dict() plus signals and the ranked candidates - what IDE clients want to show. |
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. |
opensmartroute.observability#
Source: src/opensmartroute/observability.py
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). |
text_digest | function (text: str) | Loggable stand-in for request text: {"text_sha256": <16 hex>, "text_len": n}. |
use_tracer | class | with use_tracer(t): makes t the tracer that :func:current_tracer returns in this context. |
opensmartroute.ocm#
Source: src/opensmartroute/ocm.py
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#
Source: src/opensmartroute/policy/init.py
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 declared latency exceeds the request's 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. |
tools | function (target: RouteTarget, request: RouteRequest, signals: Signals) | When tools are required (constraint or context['tools']), LLM targets must supports_tools. |
opensmartroute.realtime#
Source: src/opensmartroute/realtime/init.py
Real-time operational controls: health, circuit breaking, rate & budget limits.
| Name | Kind | Summary |
|---|---|---|
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.retrieval#
Source: src/opensmartroute/retrieval.py
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#
Source: src/opensmartroute/router.py
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#
Source: src/opensmartroute/sdk.py
OpenSmartRoute SDK: decorator-driven registration of routing components.
| Name | Kind | Summary |
|---|---|---|
ComponentKind | class | The component families a :class:ComponentRegistry can hold. |
ComponentRegistry | class | Blueprints for every routing component, with decorators that register into it. |
FunctionMiddleware | class | Adapts fn(request, next_) -> RouteDecision. |
FunctionSignal | class | Adapts fn(request, signals) -> None | {field: value}. |
FunctionStrategy | class | Adapts fn(request, signals, candidates) -> {target_id: score | StrategyScore}. |
Registration | class | A registered blueprint. factory() returns a fresh component instance. |
agent | constant | @agent(id, ...): shorthand for an agent target. |
components | constant | : The process-wide registry that the top-level decorators (opensmartroute.strategy ...) bind to. |
middleware | constant | @middleware: register a Middleware class or fn(request, next_route). |
policy_rule | constant | @policy_rule: register fn(target, request, signals) -> reason | None. |
signal | constant | @signal: register a SignalExtractor class or fn(request, signals) -> mapping. |
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#
Source: src/opensmartroute/security/init.py
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)). |
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. |
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. |
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. |
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#
Source: src/opensmartroute/security/gadget.py
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=260, 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#
Source: src/opensmartroute/security/injection.py
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#
Source: src/opensmartroute/security/limits.py
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.provenance#
Source: src/opensmartroute/security/provenance.py
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#
Source: src/opensmartroute/security/safety.py
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#
Source: src/opensmartroute/server.py
Optional FastAPI server exposing the router over HTTP.
| Name | Kind | Summary |
|---|---|---|
AUTO_SLUG | constant | : Slug prefix of the router's own pseudo-models on the OpenAI-compatible proxy (osr/auto). |
DEFAULT_PROXY_ALIASES | constant | : Model names that mean "let the router choose" on the OpenAI-compatible proxy. |
AUTO_VARIANTS | constant | : osr/auto:<variant> presets: objective weights, hard constraints and allowed kinds. |
APP_HEADER | constant | : Request header naming the calling application (OpenRouter-style attribution); echoed in metadata. |
TARGET_HEADER | constant | : Response headers carrying the decision (target id, request id) beside the OpenAI-shaped body. |
REQUEST_ID_HEADER | constant | : Response headers carrying the decision (target id, request id) beside the OpenAI-shaped body. |
OPEN_PATHS | constant | : Paths that never require a token when access control is on (probes, metrics, token check, OpenAPI pages). |
UNTRACED_PATHS | constant | : Paths that never open an http.request span (probes and the observability endpoints themselves). |
bearer_token | function (headers: Any) | The access token of a request: X-API-Key first, else Authorization: Bearer <token>. |
token_accepted | function (token: str | None, tokens: Iterable[str]) | Constant-time membership test of token in the configured access tokens. |
create_app | function (router: Any, proxy_aliases: frozenset[str]=DEFAULT_PROXY_ALIASES, autopilot: Any=None, auth_tokens: Iterable[str]=()) | FastAPI app: /route, /feedback, /targets, /stats, /healthz and the OpenAI-compatible /v1. |
resolve_model | function (model: str, aliases: frozenset[str]=DEFAULT_PROXY_ALIASES) | Split a proxy model into (pinned target id | None, route options). |
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) | Shape an execution result as an OpenAI chat.completion object (model = chosen target id). |
opensmartroute.settings#
Source: src/opensmartroute/settings.py
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). |
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#
Source: src/opensmartroute/signals/init.py
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 | after domain detection (uses domain bonus). |
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. |
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. |
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. |
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. |
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 |
extract_signals | function (request: RouteRequest, extractors: list[SignalExtractor] | None=None) | Run the extractor chain (DEFAULT_EXTRACTORS unless given) and return the populated :class:Signals. |
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.events#
Source: src/opensmartroute/signals/events.py
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#
Source: src/opensmartroute/signals/models.py
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. |
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) | Generate labelled prompts from ontology templates x topics with light noise. |
opensmartroute.signals.ontology#
Source: src/opensmartroute/signals/ontology.py
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#
Source: src/opensmartroute/signals/uncertainty.py
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#
Source: src/opensmartroute/stack.py
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). |
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#
Source: src/opensmartroute/strategies/init.py
| 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. |
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#
Source: src/opensmartroute/strategies/aggregate.py
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#
Source: src/opensmartroute/strategies/auction.py
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#
Source: src/opensmartroute/strategies/bandit.py
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#
Source: src/opensmartroute/strategies/base.py
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#
Source: src/opensmartroute/strategies/capability.py
Capability-fit strategy: match request signals to a target's declared capabilities.
| Name | Kind | Summary |
|---|---|---|
CapabilityStrategy | class | Declarative fit: domain / action overlap, complexity band, language, modality and quality prior. |
opensmartroute.strategies.cascade#
Source: src/opensmartroute/strategies/cascade.py
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#
Source: src/opensmartroute/strategies/defer.py
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#
Source: src/opensmartroute/strategies/edge.py
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#
Source: src/opensmartroute/strategies/elastic.py
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#
Source: src/opensmartroute/strategies/escalation.py
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#
Source: src/opensmartroute/strategies/human.py
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#
Source: src/opensmartroute/strategies/llm_judge.py
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#
Source: src/opensmartroute/strategies/memory.py
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#
Source: src/opensmartroute/strategies/modality.py
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#
Source: src/opensmartroute/strategies/probe.py
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#
Source: src/opensmartroute/strategies/progress.py
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#
Source: src/opensmartroute/strategies/protocol.py
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#
Source: src/opensmartroute/strategies/rules.py
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#
Source: src/opensmartroute/strategies/semantic_cache.py
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#
Source: src/opensmartroute/strategies/session.py
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#
Source: src/opensmartroute/strategies/similarity.py
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#
Source: src/opensmartroute/strategies/speculative.py
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.task_table#
Source: src/opensmartroute/strategies/task_table.py
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. |