Skip to content

feat(router): Route turns with a decision model - #2241

Draft
sentry-junior[bot] wants to merge 1 commit into
mainfrom
feat/turn-router-decide
Draft

sentry-junior[bot] wants to merge 1 commit into
mainfrom
feat/turn-router-decide

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Follow-up to #2238. The turn router now uses the AI SDK decision API on the configured decision model (AI_DECISION_MODEL, default typesafe-ai/jev), not a completeObject call on the fast model.

What changed

  • The router asks two choice questions in one decision call:
    • profile: the options are the configured profiles. Each option's criteria text is that profile's description.
    • reasoning_level: the options are none … xhigh. Each option uses the same criteria text as the old system prompt.
  • The confidence is the lower of the two chosen-option probabilities. The existing 0.75 threshold now uses model probabilities instead of a self-reported number. The low/medium/high label handling is removed. When a provider returns no probabilities, the choice counts as certain.
  • Decision models return no text. The reason (span level_reason and turn_routed) is now handoff p=0.91, xhigh p=0.88 style.
  • These stay the same: low-confidence and error fallback to the current profile at medium, one retry on invalid_response (this includes decision refusals), the reasoning floor, and profile reasoning overrides. An unknown profile or level from the model also falls back.
  • The router eval harness uses botConfig.decisionModelId. The docs now list the turn router under AI_DECISION_MODEL.

Tests

  • tests/unit/services/turn-router.test.ts is rewritten for the decision call. It covers the question shape, confidence from probabilities, missing probabilities, and an unknown-choice fallback.
  • Agent-run mocks of @/chat/pi/client fake completeDecision and spread the real module, so the model-fake lint count stays at baseline.
  • mockTurnRouterModel now answers /v4/ai/decision-model.

Verification

  • pnpm lint and typecheck (junior, junior-evals) pass.
  • 30 test files / 217 tests pass: turn router unit, plugin and runtime component, bot-handlers, agent-continue-slack, and config.
  • I did not run the router evals (evals/router/*) locally because there is no recording token. The CI run on this PR is the Jev comparison against the 12/12 Luna baseline. I did not change the eval cases.

via David Cramer.

--

View Junior Session [Sentry]

Move the turn router from a structured completeObject call on the fast
model to the AI SDK decision API on the configured decision model
(AI_DECISION_MODEL, default typesafe-ai/jev).

The router asks two choice questions. Profile options come from the
configured profile descriptions. Reasoning-level options use the same
criteria as before. Confidence is now the lower of the two chosen-option
probabilities, so the 0.75 threshold uses model probabilities instead of
a self-reported number. Decision models return no text, so the logged
reason is now a 'handoff p=0.91, xhigh p=0.88' summary.

Fallback, retry, reasoning floor, and profile reasoning overrides are
unchanged.

Co-Authored-By: David Cramer <david@sentry.io>
@vercel

vercel Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
junior-docs Ready Ready Preview Oct 26, 2026 10:08pm UTC

Request Review

@sentry-evals

sentry-evals Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Sentry Evals

junior-behavioral

Run Status Passed Failed Errored Cost Tokens Duration
Head Failed 73 2 0 $0.74 0 464.86s

Base commit 30601ca has no eval run to compare against.

junior-integration

Run Status Passed Failed Errored Cost Tokens Duration
Head Passed 101 0 0 $0.74 0 537.55s

Base commit 30601ca has no eval run to compare against.

junior-router

Run Status Passed Failed Errored Cost Tokens Duration
Head Passed 12 0 0 $0.00 0 7.34s

Base commit 30601ca has no eval run to compare against.

This branch was successfully deployed

1 active deployment
Preview – junior-docs — 02086036 Deployed Oct 26, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants