Skip to content
pleach
Plugins

Routing decisions

How plugins influence routing today — contributeFamilyPivot, contributeIntentToolMap and contributeIntentClassifiers — and what a plugin cannot override.

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

HookWhat it does
contributeFamilyPivotSupplies the two operations a fallback retry uses: deriveFamilyFromModelId(modelId) and pickNextInFamily(family, currentModel, triedModels). With several contributors, the last non-null one wins.
contributeIntentToolMapMaps an intent to priority tools, which keep their full schema when tool schemas are condensed.
contributeIntentClassifiersContributes classifiers that can set the turn's intent. See 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.

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

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 and 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.

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