# Routing decisions (/docs/plugins/routing-decisions)



> An intent in `@pleach/core` is a plain string, `"<plugin>.<intent>"` by
> convention, to avoid collisions between plugins. There's nothing to
> register first. Plugins influence model fallback through
> `contributeFamilyPivot`, tool schemas through
> `contributeIntentToolMap`, and the turn's intent through
> `contributeIntentClassifiers`.

## The hooks [#the-hooks]

| Hook                          | What it does                                                                                                                                                                                            |
| ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `contributeFamilyPivot`       | Supplies the two operations a fallback retry uses: `deriveFamilyFromModelId(modelId)` and `pickNextInFamily(family, currentModel, triedModels)`. With several contributors, the last non-null one wins. |
| `contributeIntentToolMap`     | Maps an intent to priority tools, which keep their full schema when tool schemas are condensed.                                                                                                         |
| `contributeIntentClassifiers` | Contributes classifiers that can set the turn's intent. See [Intent classifiers](#intent-classifiers).                                                                                                  |

## Intent classifiers [#intent-classifiers]

On a turn that host classification and keyword classification left
ambiguous, the runtime runs every contributed classifier before it asks
the utility model. Each `classify` call is synchronous and returns the
classifications it can make, or `[]`. The top result is adopted as the
turn's intent when its confidence is 0.7 or higher, and the utility call
is then skipped. Below 0.7, or on a tie between different intents, the
turn continues as it would without classifiers. Host and keyword
classification rank above plugin classifiers.

```ts
contributeIntentClassifiers: () => [{
  id: "my-plugin.refund",
  classify: ({ userText }) =>
    /refund|chargeback/i.test(userText)
      ? [{ intent: "my-plugin.refund", confidence: 0.8, toolAlignment: ["refund_lookup"] }]
      : [],
}],
```

A classifier's intent must be namespaced `"<plugin>.<intent>"`; other results are discarded. Tools in `toolAlignment` reach the
planner as non-binding evidence. You can also read the contributions
through `runtime.plugins.collectIntentClassifiers()`.

## What a plugin can't override [#what-a-plugin-cant-override]

* Seam-level routing. `callClass` literals are seam-only — see
  [Plugin contract — what a plugin cannot do](/docs/plugin-contract#what-a-plugin-cannot-do).
* Registration timing. Plugins register at construction time, before
  `SessionRuntime` boots.

## How a fallback picks a model [#how-a-fallback-picks-a-model]

When a retry falls back, the runtime calls your
`deriveFamilyFromModelId` on the current model, then your
`pickNextInFamily` with that family, the current model and the set of
models tried this turn. Return a model from the same family, or `null`
when the family is exhausted. Neither operation sees a call class. See
[Call classes](/docs/call-classes) and [Family lock](/docs/family-lock).

With `@pleach/gateway`, each routed call carries a `RoutingDecision`.
The type is exported from `@pleach/core/model-family`.

For a starting point, see the
[`@pleach/recipes` `verticalAgent` factory](/docs/recipes/vertical-agent).

## What this is NOT [#what-this-is-not]

* **Not a per-call model picker.** Plugins can't choose between
  GPT-4 and Claude on a per-call basis outside the family lock.
  The family is locked at session start; pivots route within the
  family.
* **Not a cost-aware router.** Cost routing lives in
  `@pleach/gateway` and reads from the substrate's family-strict
  cascade. Plugins don't override gateway-level cost decisions.

## Where to go next [#where-to-go-next]

<Cards>
  <Card title="Family lock" href="/docs/family-lock" description="Why model family is locked at session start and how cascade pivots work within it." />

  <Card title="Call classes" href="/docs/call-classes" description="The four canonical call classes — utility, reasoning, converse, synthesize." />

  <Card title="Model resolution matrix" href="/docs/model-resolution-matrix" description="The substrate's (Family × CallClass) → model resolution table." />

  <Card title="Authoring" href="/docs/plugins/authoring" description="The full HarnessPlugin hook surface." />
</Cards>
