Code and dense tables are folded away. Open any of them on demand.
Live demo · no signup
Try this use case
Edit the text if you like, then press run. Laya answers every question at once, with a probability for each option.
The questions it answers
difficultyscoreHow hard is `request` for a language model?domainchoiceWhat domain does `request` belong to?toolchoiceWhich tool should the agent call first to handle `request`?needs_toolsyes / noDoes answering `request` require external tools, search or private data?
The answers appear here as bars: the longer the bar, the more likely Laya thinks that option is.
Show the full API requestHide technical details· JSON
What is agent tool routing?
Agent tool routing is the decision an AI agent makes before each step: which tool to call, which model to send the request to, or whether to hand off. Laya makes that decision as a typed question with a probability in one fast forward pass, so expensive models only run on the steps that need them.
A production agent does not only answer questions. Before each step it decides what to do: call a SQL tool or a search tool, answer directly, send the request to a small model or a frontier one, ask the user a clarifying question, or stop and hand off. Most teams make these decisions with the same large model that does the reasoning, either through function calling or a "router prompt".
That works, but it puts a multi-second, token-billed call in front of every step, including the trivial ones ("hi", "thanks", "what is your refund policy"). It also makes the routing decision hard to audit: the model emits a tool call, but there is no probability attached, so you cannot tell a confident choice from a coin flip, and you cannot set a policy such as "use the cheap tier only when we are sure the request is easy".
Routing decisions have exactly the properties a decision model for agents is designed for: small, fixed answer spaces, high volume, a tight latency budget, and a need for honest uncertainty. The laya package ships a preset for this (router_questions(), with difficulty, domain, needs_tools and is_sensitive), and the example on this page extends it with a tool-selection question.
Why a decision model rather than an LLM router
The comparison that matters is between routing with the model you are trying to avoid calling and routing with something an order of magnitude cheaper.
- Latency. The model card reports 32.8 ms for a single question on the multilingual checkpoint and 39.5 ms on the English checkpoint on one T4 GPU. Five questions in one call took 84.5 ms on the English checkpoint and 40.1 ms on the multilingual one, because all questions share a single forward pass (batching). Network time to the hosted API is extra. For comparison, TypeSafe Jev, a closed decision API with the same wire protocol, has been measured by third parties at 236–276 ms p50.
- Typed output. The router returns one of your labels with a probability for each. A non-autoregressive model does not generate text, so it cannot emit a malformed tool call or a tool that does not exist. It can still pick the wrong tool, which is why the probability matters.
- Calibrated confidence. A router that says "cheap tier, 0.95" and one that says "cheap tier, 0.40" should be treated differently. With calibrated probabilities you can send the second case to the stronger model and keep the savings on the first.
- Cost. Laya Studio bills input tokens (1 credit = 1 input token), and each of the router's five questions reads the step once. See pricing.
The goal is not to replace the reasoning model. It is the System 1 / System 2 split: a fast, calibrated classifier decides what to do; the slow, generative model does it when needed.
Designing routing questions: difficulty, domain, tool and risk
The example combines the package preset with one custom question.
difficulty(score, 4 levels) drives model-tier selection. Each level describes the work required ("several steps", "long multi-step reasoning"), which is observable from the request, rather than an opinion of how "smart" the model must be.domain(choice, 6 options) lets you send code to a code-tuned model and chit-chat to the cheapest one.tool(choice) names your actual tools. Describe each by what data it reaches ("internal tables: revenue, refunds, usage, orders"), because that is what distinguishes them. Always includenoneso direct answers are possible.needs_toolsandis_sensitive(noul) are cross-checks. Iftool = nonebutneeds_toolsis high, the answers disagree and the step should escalate.
Design rules that matter for routing:
- Keep tool lists short. Options share a prompt budget (192 tokens on the English checkpoint, 256 on multilingual), and the model card shows accuracy falling off on 77-option Banking77. If you have 40 tools, route in two steps: tool family first, then the tool within the family.
- Put context in the state, not the instructions. Pass the latest user message, the turn count and plan tier as JSON. The English checkpoint reads about 320 tokens of state; truncate long histories to the last turn or two.
- Watch noul on English. The card documents noul answers that follow the
false:/true:labels rather than the text (issue #156). Ifneeds_toolslooks stuck, rephrase it as a two-option choice with neutral keys.
Observability of agent traces
The laya-typed-decisions checkpoint was fine-tuned on four workflows, one of which is agent_trace_observability, with exactly the question ids action, needs_review, outcome, risk and urgency. The model card reports 0.730 accuracy on that workflow. It suits after-the-fact review of a completed agent trace rather than pre-step routing. The router only selects that checkpoint when the ids match exactly and auto task detection is enabled, or when you pass "model": "typed-decisions" explicitly. See typed decisions.
Thresholds and escalation for agent steps
Gate on confidence, not on action.act_probability.
The model card is explicit that act_probability carries no usable signal yet: it reads close to 1.0 for almost every input, and its raw logits run against correctness (AUROC 0.30 on 396 labelled decisions, issue #185). confidence reached an AUROC of 0.77 on the same items. For choice and score questions confidence is one minus normalized entropy, so a split between two tools shows up as low confidence even when one is slightly ahead. For noul questions it is max(p, 1 - p).
Fit temperatures on a few hundred labelled routing decisions before choosing thresholds: the checkpoints ship over-confident, and the card reports mean ECE dropping from 0.466 to 0.081 on the English checkpoint after per-(type, option count) temperature scaling.
A starting policy, to be tuned against your own error costs:
Show technical detailsHide technical details· python sample
The asymmetry is the point. Wrongly sending a hard request to a small model costs a bad answer; wrongly sending an easy request to a frontier model costs money. Set the "small tier" threshold strictly and let uncertain steps fall through to the stronger path. Track the fraction of steps that fall through; that is your real saving. See act/escalate routing.
Integration: calling the router before each agent step
Call POST https://api.laya.studio/v1/systemone with the step's state and questions. Omit model to let Laya route between the English and multilingual checkpoints automatically.
Show technical detailsHide technical details· bash sample
Show technical detailsHide technical details· python sample
Show technical detailsHide technical details· typescript sample
Set a short timeout and a fallback: if the router call fails, take the conservative path (the stronger model). Log the full answer object per step so you can later label routing decisions and refit thresholds. Get an API key or read the docs.
Limitations of decision-model routing for agents
- It routes; it does not reason. Laya can say a request looks like "data_analysis, moderate, needs sql_warehouse". It cannot write the SQL or verify the result.
- Zero-shot accuracy on your tools is unknown until you measure it. The model card reports the base checkpoints near chance on the typed-decisions benchmark zero-shot (0.362 vs a 0.461 majority baseline); the 0.766 figure belongs to the fine-tuned checkpoint on its own four workflows. Collect a labelled set of real agent steps before trusting the router.
- Difficulty is a score question, and score is the weakest primitive (the card cites 0.372 on SST-5). Use difficulty to pick a tier, with a conservative default, not to make irreversible decisions.
- Large tool catalogues degrade accuracy because options share a fixed token budget. Route hierarchically above roughly 20 tools.
- Short context. Roughly 320 tokens of state on the English checkpoint and 768 on the multilingual and typed-decisions checkpoints. Summaries of long conversations must be done elsewhere.
- The typed-decisions checkpoint is narrow. It was fine-tuned on synthetic workflows; do not send it unrelated schemas.
Frequently asked questions
How do I route requests between a cheap and an expensive LLM?
Can Laya replace function calling in my agent?
How much latency does a routing call add?
Which confidence value should decide whether to use the cheap model?
What if I have more than 20 tools?
When is the typed-decisions checkpoint used?
Sources
Last updated . Laya Studio is an independent hosted service for the open-source Laya model (Apache-2.0, © Convai Innovations) and is not affiliated with Convai Innovations or TypeSafe.