Skip to content

feat: subagent model routing with Jev (PoC) - #1390

Open
hary73 wants to merge 48 commits into
mainfrom
hary/subagent-auto
Open

hary73 wants to merge 48 commits into
mainfrom
hary/subagent-auto

Conversation

@hary73

@hary73 hary73 commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor
  • Routing in core (core/modelRouting/): a decision model (Jev) classifies a thread's task as direct, fixed_steps or adaptive, and createModelRouter picks the cheapest model and effort pair in that cluster that the user has, by gateway token price. The router never throws and returns nothing when it can't pick, so the caller keeps its own model.
  • Generic router input: the classifier is any IDecisionModel and the question is data (classification.ts builds the request and reads the answer); each route takes only the thread id, the task (text or messages, long text cut from the middle) and a signal, so root auto mode can reuse it.
  • Decision models: IDecisionModel and OpenAIDecisionModel on the openai SDK's Decisions API (openai bumped to 7.57), with x-tfy-metadata on decision calls.
  • Subagents: SessionHandle routes a subagent spawned without a model and runs it at the routed effort, via ITurnResourceResolver.modelRouting.
  • Server: TRUEFOUNDRY_MODEL_ROUTING turns routing on per tenant (off by default), and listRoutingCandidates() lists the tenant's models with their canonical id and price.

AGE-2842


Note

Medium Risk
Changes which LLM and effort subagents run on and adds a pre-spawn decision-model call; failures are non-blocking but mis-routing could affect quality or cost.

Overview
Adds optional subagent model routing (off by default) gated by per-tenant TRUEFOUNDRY_MODEL_ROUTING in TrueFoundry mode.

Core introduces IDecisionModel / OpenAIDecisionModel (OpenAI SDK bumped to 7.57 for the Decisions API), plus createModelRouter: a classifier assigns each delegated task to direct, fixed_steps, or adaptive, then picks the cheapest available model + reasoning effort from predefined clusters using gateway canonical ids and blended token cost. Routing never throws—on failure the subagent keeps its requested model.

Harness wiring: ITurnResourceResolver.modelRouting feeds dynamic sub-agent creation in SessionHandle, which classifies name + task text and applies routed model and reasoning_effort before resolveAgentDefinition.

Server: turnModelRouting resolves the tenant’s decision model and lists routable models with has_catalog_info; TrueFoundry’s model store surfaces canonicalModel/cost from gateway metadata and allows decision models by name without listing them in the chat model picker.

Reviewed by Cursor Bugbot for commit c8e73f4. Bugbot is set up for automated code reviews on this repo. Configure here.

@changeset-bot

changeset-bot Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c51ec2e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@truefoundry/trueforge-core Patch
@truefoundry/trueforge Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

hary73 and others added 5 commits November 16, 2026 14:06
Co-authored-by: Cursor <cursoragent@cursor.com>
…ing, routing trace keys)

Co-authored-by: Cursor <cursoragent@cursor.com>
…ad_id

Co-authored-by: Cursor <cursoragent@cursor.com>
…hreshold

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@hary73
hary73 force-pushed the hary/subagent-auto branch from 42ed3b4 to 88b3379 Compare November 16, 2026 08:36
@hary73 hary73 changed the title docs: LLD for subagent auto model routing with Jev feat: subagent model routing with Jev (PoC, TrueFoundry mode) Nov 16, 2026
hary73 and others added 3 commits November 16, 2026 15:10
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@hary73 hary73 changed the title feat: subagent model routing with Jev (PoC, TrueFoundry mode) feat: subagent model routing with Jev (PoC) Nov 16, 2026
hary73 and others added 2 commits November 16, 2026 15:39
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@hary73
hary73 marked this pull request as ready for review November 16, 2026 10:19
@veria-ai

veria-ai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

PR overview

No security issues were found in this pull request.

Reviews

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

hary73 and others added 2 commits November 16, 2026 17:32
…bilities

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
hary73 and others added 4 commits November 18, 2026 16:55
Co-authored-by: Cursor <cursoragent@cursor.com>
…lder

Co-authored-by: Cursor <cursoragent@cursor.com>
The router takes the classifier as an IDecisionModel and the question
separately; building the request and reading the answer live in
classification.ts. Long tasks keep their start and end. The router no
longer takes a fallback model and logs once; the caller logs what the
thread ends up on.

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
hary73 and others added 10 commits November 19, 2026 08:51
…use reasoning efforts

modelRouting and RoutableModel's canonicalModel and price are required
and allow undefined instead of being optional. Decision requests no
longer take an abort signal, so routes no longer take one either. The
clusters and the routed effort use SUPPORTED_REASONING_EFFORTS instead
of their own effort list.

Co-authored-by: Cursor <cursoragent@cursor.com>
…ffort

The router's inputs are ModelRouterDeps (classifier, question,
listModels, timeoutMs), which the resolver exposes directly; the logger
is a separate argument. ReasoningEffort names the supported efforts once.

Co-authored-by: Cursor <cursoragent@cursor.com>
prepareTurnExecution reads the routing config and builds the turn's
ModelRouterDeps, which createTurnResolver receives as a dependency like
web search and memory.

Co-authored-by: Cursor <cursoragent@cursor.com>
public_cost is only set on filtered or sorted listings, which routing
doesn't request. Cost entries need both prices as numbers.

Co-authored-by: Cursor <cursoragent@cursor.com>
Routing asks only the category question. The routing log line says
whether the task was cut from the middle (input_truncated).

Co-authored-by: Cursor <cursoragent@cursor.com>
Route first and put the pick in request.model before resolving the
definition; the routed effort is set on modelParams without conditional
spreads.

Co-authored-by: Cursor <cursoragent@cursor.com>
…ting timeout

listRoutingCandidates is required; SQLite and Postgres return no
candidates. RoutableModel uses name and cost. The router and its config
no longer have a timeout.

Co-authored-by: Cursor <cursoragent@cursor.com>
The gateway ignores the chat-only headers on decision requests, so
withGatewayMetadata is dropped and OpenAIDecisionModel uses
buildOutboundRequestHeaders.

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
hary73 and others added 2 commits November 19, 2026 13:31
listModels takes include_catalog_info and returns CatalogModel, which
adds canonical_model and cost (TypeScript only; the public schema is
unchanged). listRoutingCandidates is removed.

Co-authored-by: Cursor <cursoragent@cursor.com>
…ssage

Our image part schema accepts the SDK's 'original' detail, so the SDK
type is assignable again. The published OpenAPI spec is unchanged.

Co-authored-by: Cursor <cursoragent@cursor.com>
@hary73 hary73 mentioned this pull request Nov 20, 2026
4 of 5 tasks
The store's listModels now returns AvailableModelWithCatalogInfo, which
extends AvailableModel and RoutableModel, so listModels passes straight
into the router and the field-copying map in turns.ts is gone. The
TypeScript-only type replaces CatalogModel; the public schema is
unchanged.

Co-authored-by: Cursor <cursoragent@cursor.com>
@datadog-official

datadog-official Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Code Quality  Code Vulnerabilities  IaC  Library Vulnerabilities  Secrets

🎉 All green!

🛠️ No new code quality issues
🛡️ No new code vulnerabilities
📚 No new vulnerable libraries detected
🧱 No new Infrastructure as Code (IaC) issues
🔑 No new secrets detected

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: c8e73f4 | Docs | Give us feedback!

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

hary73 and others added 4 commits November 20, 2026 15:12
Object.hasOwn does not narrow the classifier's string, so the router
asserted RoutingCategory. isRoutingCategory is the same membership check
and narrows the value for selectModel.

Co-authored-by: Cursor <cursoragent@cursor.com>
Rename classificationRequest's `truncated` to `isTruncated` and the
`include_catalog_info` list option to `has_catalog_info`. The
`input_truncated` log key is unchanged.

Co-authored-by: Cursor <cursoragent@cursor.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit c8e73f4. Configure here.

This branch has not been deployed

No deployments
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.

2 participants