# `Nous.Router.DecisionModel`
[🔗](https://github.com/nyo16/nous/blob/v0.21.1/lib/nous/router/decision_model.ex#L1)

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. A `Nous.DecisionModel` struct or a decision-model
    string for `Nous.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
    what `granularity: :escalate_only` climbs. Keys are option ids (atoms or
    strings, `[A-Za-z0-9_.-]`). A value is one of:
    * a model string or a `Nous.Model` struct
    * 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 any `Nous.Model.parse/2` options for that tier
      (`base_url:`, `api_key:`, `llamacpp_model:`, ...). Strings are parsed
      with `Nous.Fallback.parse_fallback_models/2`, so per-tier options ride
      along.
  * `:min_confidence` - 0.0 to 1.0 (default `0.0`). A decision below it is
    `{:default, %{cause: :low_confidence}}`: the agent's own model answers.
    The answer's `confidence`, or its top probability when the backend
    reports none.
  * `:granularity` - see `Nous.Router` (default `:per_turn`).
  * `:context_turns` - how many earlier user messages to include in the
    state (default `0`). More context costs decision latency.
  * `:instructions` - replaces the default routing question.
  * `:timeout` - per-decision timeout in ms, passed to
    `Nous.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`).

---

*Consult [api-reference.md](api-reference.md) for complete listing*
