A Nous.Router that asks a Nous.DecisionModel (Clef, Clef-Flash, ...)
which model tier should answer, LiteLLM-style.
dm = Nous.DecisionModel.parse("workers_ai:clef-flash")
agent =
Nous.new("openai:gpt-4o",
router:
{Nous.Router.DecisionModel,
model: dm,
tiers: [
simple: [model: "openai:gpt-4o-mini", description: "greetings, lookups, short factual answers"],
complex: [model: "openai:gpt-4o", description: "multi-step reasoning, code, proofs, planning"]
],
min_confidence: 0.6}
)Each routing decision is one :choice question whose options are the
tiers, over a JSON-framed state: %{"latest_user_message" => text}, plus
"previous_user_messages" when :context_turns is above 0. The state is
defanged by Nous.DecisionModel.decide/4. The decision model's answer is
mapped back through the declared tier keys; nothing from the backend is
turned into an atom.
Options
:model- required. ANous.DecisionModelstruct or a decision-model string forNous.DecisionModel.parse/1.:tiers- required, at least two, as an ordered keyword list (or list of{key, value}with string keys), cheapest first: that order is whatgranularity: :escalate_onlyclimbs. Keys are option ids (atoms or strings,[A-Za-z0-9_.-]). A value is one of:- a model string or a
Nous.Modelstruct - a keyword list with
:model(string or%Nous.Model{}), an optional:description(what the tier is for; the decision model reads it, default: the key) and anyNous.Model.parse/2options for that tier (base_url:,api_key:,llamacpp_model:, ...). Strings are parsed withNous.Fallback.parse_fallback_models/2, so per-tier options ride along.
- a model string or a
:min_confidence- 0.0 to 1.0 (default0.0). A decision below it is{:default, %{cause: :low_confidence}}: the agent's own model answers. The answer'sconfidence, or its top probability when the backend reports none.:granularity- seeNous.Router(default:per_turn).:context_turns- how many earlier user messages to include in the state (default0). More context costs decision latency.:instructions- replaces the default routing question.:timeout- per-decision timeout in ms, passed toNous.DecisionModel.decide/4.
Failure
A decision-model error (timeout, oversize state, backend down) returns
{:default, %{cause: :error, reason: error}}: the request goes to the
agent's own model. Routing fails open by design. A request with no user
text is not decided (cause: :no_input).