Skip to content

[AGE-2841] Persist each thread's model and restore it for subagents - #1426

Open
hary73 wants to merge 10 commits into
mainfrom
haryahuja/age-2841-fix-subagent-model-overrides
Open

hary73 wants to merge 10 commits into
mainfrom
haryahuja/age-2841-fix-subagent-model-overrides

Conversation

@hary73

@hary73 hary73 commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A subagent on a different model from its parent should run with its own model's settings, not the parent's, and THREAD_CREATED should save the model the subagent actually runs on.

AGE-2841

Changes

Split the model out of AgentDefinition (refactor commit, no behaviour change)

  • A thread is built from its definition (instructions, messages, tools, response format, iteration limit) and a separate model (AgentModel: client, name, provider type, properties and params).
  • resolveAgentDefinition returns { definition, model, extraCapabilities }. AgentThread, builtinsFromSpec and contextCompaction read the model from model.

A thread on another model runs on that model's own defaults

  • In TurnResourceResolver, a thread whose model is the spec's model gets the model's defaults and then the spec's params, as before.
  • Any other model gets the model's defaults (its known max_tokens, or none) plus parallel_tool_calls: true. None of the spec's params carry over.

Record and restore the model a subagent actually runs on

  • thread.created records the model the subagent was built with, instead of the requested one (empty when the model is routed).
  • Every thread's turn_thread.checkpoint gets a model field: written when a subagent is added (from thread.created) and on every new turn (through a new thread_models input to createTurn).
  • On rebuild, a subagent comes back on its saved checkpoint.model, falling back to agent_info.model for older rows. The root keeps following its spec, so switching models mid-chat still works.
  • Postgres and SQLite migrations (20261118_000001_turn_thread_model) set model: null on existing checkpoints, following the pending_mcp_auth backfill.

AgentDefinition is an exported type of trueforge-core, so code built on the library that constructs it needs updating. The agent spec, the HTTP API and the generated SDKs are unchanged.

How was this tested?

  • Guardrail tests:
    • a thread on another model gets that model's own defaults and parallel_tool_calls, with none of the spec's max_tokens, temperature or reasoning_effort, and no max_tokens when the limit isn't known;
    • a rebuilt subagent comes back on its saved model while the root follows its spec (fails without the change);
    • thread.created records the model the subagent runs on;
    • store contract tests, run against the in-memory, SQLite and Postgres stores: each thread's model is recorded per turn, kept when a turn has no entry for it, and kept for a thread added mid-turn.
  • The refactor updated 13 test files mechanically, with no test logic changed.
  • trueforge-core (604), trueforge unit (930), SQLite store (251) and Postgres store (255) suites pass; both typechecks, ESLint and Prettier are clean on the changed files.

Checklist

  • I have read the contributing guidelines
  • pnpm build, pnpm test, pnpm typecheck, pnpm lint:ci, and pnpm format:check pass locally (ran both typechecks, the core, server, SQLite and Postgres suites, and lint and format on the changed files)
  • Tests added/updated where it makes sense
  • No hand-edits to generated code
  • Docs / .env.example updated if configuration or behavior changed (no configuration change)

Note

Medium Risk
Touches core thread rebuild, LLM param routing, and durable checkpoint schema with DB migrations; behavior changes for subagents on alternate models.

Overview
Separates execution model from agent config by introducing AgentModel (client, name, params, properties) alongside a slimmer AgentDefinition, and wiring AgentThread, builtins, and resolveAgentDefinition to consume both.

Fixes subagent model behavior: threads on a model other than the spec use that catalog model’s defaults (plus parallel_tool_calls), not the parent agent’s max_tokens / temperature / reasoning_effort. Rebuilt subagents restore model and effort via agent_info.reasoning_effort and saved checkpoint data.

Persists model per thread: ModelSnapshot (name, effort) lives on thread checkpoints—written on THREAD_CREATED for subagents (resolved model, not just the request) and on each createTurn via main_thread_model for the root. Postgres/SQLite migrations backfill checkpoint.model on existing turn_thread rows.

AgentDefinition no longer carries model fields—a breaking shape change for consumers that construct definitions directly; HTTP agent spec is unchanged.

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

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

changeset-bot Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a858bd3

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 hary73 changed the title refactor: split the model out of AgentDefinition (AGE-2841, part 1) Fix subagent model overrides Nov 18, 2026
@hary73
hary73 marked this pull request as ready for review November 18, 2026 12:42
@veria-ai

veria-ai Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

PR overview

No security issues were found in this pull request.

Reviews

@hary73 hary73 changed the title Fix subagent model overrides [AGE-2841] Persist each thread's model and restore it for subagents Nov 18, 2026
Co-authored-by: Cursor <cursoragent@cursor.com>
@datadog-official

datadog-official Bot commented Nov 18, 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: dc6043f | 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.

custom: Record<string, unknown> | null;
}

export interface CreateTurnInput {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

fix input for create turn because we only have main thread context from last turn , we won't have multiple threads

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we do this in a follow up PR

createTurn no longer takes per-thread models: a thread's model is
recorded when the thread is created (the root via createTurn's new
threads, a subagent via thread.created) and carried with its row.

Co-authored-by: Cursor <cursoragent@cursor.com>
@hary73 hary73 mentioned this pull request Nov 20, 2026
4 of 5 tasks
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.

Stale Bugbot comment from a previous run.

Subagent agent_info now carries reasoning_effort, set from the resolved model params on thread.created. A rebuilt subagent resumes on that name and effort, and the root keeps following its spec.

The thread checkpoint model is now { name, effort }. The main thread's model is written on every turn, including the first, so the root's resolved model and effort are recorded even though nothing reads them on rebuild yet.

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 1 potential issue.

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 4fe5e33. Configure here.

reasoning_effort: z
.string()
.optional()
.describe('Reasoning effort the resolved model runs at. Omitted when none was resolved.'),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

OpenAPI and SDK not regenerated

Medium Severity

AgentInfoSchema now includes reasoning_effort, and thread.created emits that field so a rebuilt subagent can restore effort. ThreadCreatedEvent is part of the public OpenAPI document, but .github/fern/openapi/openapi.json, docs/openapi.json, and packages/trueforge-sdk still describe AgentInfo without reasoning_effort. Run pnpm sdk:generate and add a patch changeset that names @truefoundry/trueforge-sdk.

Additional Locations (1)
Fix in Cursor Fix in Web

Triggered by project rule: TrueForge review rules

Reviewed by Cursor Bugbot for commit 4fe5e33. Configure here.

ModelSnapshot and ModelSnapshotSchema name the stored { name, effort } on a thread snapshot, separate from the runtime AgentModel. modelSnapshotFromAgent replaces threadModelFromAgent to match.

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

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