Skip to content

feat(agents): an agent's own default model, one resolver for every turn path (ent#1202) - #4431

Merged
dolho merged 6 commits into
devfrom
feature/1202-template-runtime-model
Nov 10, 2026
Merged

dolho merged 6 commits into
devfrom
feature/1202-template-runtime-model

Conversation

@vybe

@vybe vybe commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

What

An agent can carry its own default model, and every turn path honours it (abilityai/trinity-enterprise#1202, core half).

  • Schema: nullable agent_ownership.default_model on both database tracks — Alembic 0123_agent_ownership_default_model and the SQLite migration. An empty column changes nothing for any agent.
  • One resolver (services/agent_model_service.py): explicit model > public-channel override > the agent's own model > platform default. Used by task, schedule, loop and reminder turns, caller and ask-ending wakes (via execute_task), the a2a pre-create, and portal / public / channel / paid turns, in that one order. Only an authenticated /chat that names no model skips it (deferred by the plan).
  • model_used on pre-created rows (reminder, schedule, loop) is filled by execute_task only when empty (stamp_model_used_if_null).
  • Read-back: GET /api/agents/{name}/model gains the effective resolved model and its source (column / platform default), from the resolver, not the container's value. A read-only MemberAgentModelPanel in Settings shows it.
  • Conditional write set_default_model_if (db/agents.py, database.py facade) for the enterprise boot sync.
  • Intended change: a non-Claude agent's a2a row is now stamped empty instead of a Claude id.

The value is set by the enterprise module (companion PR abilityai/trinity-enterprise#1210); without it the column stays empty and behaviour is unchanged.

Rulings carried (trinity-pm, autonomous chain chain-ent1201)

Review + security

Reading review (Opus) over both repos: MERGEABLE, nothing critical; I1/I5 (enterprise) fixed, I4 here: the GET /model resolver call now runs off the event loop. /cso --diff: the reviewer's own short pass, nothing at ≥8/10.

Tests

Builder: 573 OSS backend and 42 frontend passed. Evidence sweep: 25 of 25 files green in random order (incl. test_3677 GET/PUT /model and the schema / Alembic / SQLite parity guards). Mutations, each caught and restored byte-identical: platform default ahead of the agent's own → 6 reds; model_used "only if empty" guard dropped → test_stamp_model_used_if_null_fills_only_a_blank red on a real DB. Four existing tests changed on purpose (test_157, test_3749 fakes; the platform-default regression source check). Sweep verdict incomplete (full vitest run hit its 540 s cap with no failure) — CI's full shuffled run is the sweep; the pinned-guard run named in the fix report is not readable from the orchestrator, so CI's guard run is the check.

Before merge

Handoffs

Part of abilityai/trinity-enterprise#1202.

🤖 Generated with Claude Code

Trinity Agent (trinity) and others added 3 commits November 9, 2026 18:15
…nt#1202)

A turn that names no model ran on the platform default for every Claude
Code agent, so an agent's own model never applied to backend-dispatched
turns (reminders, ask-ending and caller wakes, schedules, loops).

- agent_ownership.default_model TEXT NULL, both tracks: SQLite migration
  agent_ownership_default_model + Alembic 0123 (single head). NULL changes
  nothing.
- services/agent_model_service.resolve_default_model: explicit > public
  override > the agent's own model when model_catalog.unrunnable_reason
  passes it (catalog ids and Claude Code aliases only) > platform default.
  Non-Claude runtimes resolve to None. Unrunnable values are skipped by
  name; fail-open except the strict a2a pre-create.
- _default_model_for, the a2a pre-create, the portal ladder and label and
  the public-channel model reads all go through it.
- execute_task stamps a pre-created row's blank model_used with the
  resolved model (db.stamp_model_used_if_null); never an explicit one.
- GET /api/agents/{name}/model adds backend_turn_model, default_model,
  default_model_source and default_model_refused.

Mutation: reverting task_execution_service turns
test_a_wake_with_no_model_runs_and_stamps_the_agents_own_model and
test_a_pre_created_row_gets_the_resolved_model_stamped red.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…t#1202)

The Access tab shows, read-only, the model member messages run on and the
model each member agent's own turns (wakes, reminders) run on, with its
source (template / default). A template model this instance cannot run is
named in a callout with the model that runs instead. Collapsed to the
summary when every agent agrees; a bounded list otherwise.

Reads the member-agents settings response the welcome panel already
loads: the store now keeps the whole view (`settings`), so the tab issues
one GET, and a welcome save replaces only `welcome`.

Mutation: dropping the store's `settings` capture turns three of the five
new specs red.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…iters (ent#1202)

set_default_model_if(agent, expected, model) updates the column only
while it still holds the value the caller read (IS NOT DISTINCT FROM, so
NULL matches NULL) and returns whether this call changed the row. Of
several writers that read the same old value, exactly one sees True; the
private boot sync uses it so a change is audited once when several
workers start together (abilityai/trinity-enterprise#1202, review I1).

GET /api/agents/{name}/model resolves the default model off the event
loop (asyncio.to_thread; review I4).

Test: test_set_default_model_if_lands_only_on_the_value_read (tmp DB).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Trinity Agent (trinity) and others added 2 commits November 9, 2026 20:26
…o the new column and stamp (ent#1202)

CI regression diff on #4431 named 18 new failures. Causes:

- Code: get_owned_roster did not select agent_ownership.default_model, so
  an owned agent's Workspace card could never show its own model, and the
  owned and shared row shapes diverged
  (test_ent357_workspace_owned_roster went red).
- Test fakes: the a2a message/send mint now resolves through
  resolve_default_model(strict=True) (plan decision 22: the a2a rung keeps
  raise-on-failure), so a routers.a2a db fake that mints rows needs
  get_default_model_raw. Added to the four fakes that mint
  (test_736, test_ent623, test_ent679_a2a_payment_gate, test_ent751); the
  other a2a fakes never mint.
- Re-pin: the create-mode golden records every agent_ownership column, and
  default_model is the column ent#1202 adds. Regenerated per the module's
  rule (serial, TRINITY_ENT695_REGENERATE_GOLDEN=abilityai/trinity-enterprise#1202);
  the diff is 12 "default_model": null rows plus _meta.regenerated_by.
- Re-pin: stamp_model_used_if_null is a new update(schedule_executions)
  site. It is a non-status writer (model_used only, CAS on IS NULL), so it
  goes in the inventory's non-status section.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Brings in #4401 (ent#1158) and #4402 (ent#1174). tests/registry.json
resolved by union: dev's five new entries plus this branch's
test_ent1202_default_model_resolution.py entry appended last.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@trinity-ability

Copy link
Copy Markdown
Contributor

/validate-pr — REQUEST CHANGES (tip 76e520ec9)

This PR requires the following changes before merge:

  • V1 (Invariant feat: SMARTS trading pipeline with Telegram notifications and Miro visualization #13 / §5.5): add a first-line # mcp: header to src/backend/routers/chat.py and src/backend/routers/a2a.py. Use a pointer to the covering tool module, or # mcp: none — <reason>. Both routers change code in this PR, and GET /api/agents/{name}/model gains four response fields. The contract itself is fine: no MCP tool calls /model (grep over src/mcp-server/src is empty), and the a2a pre-create change does not change the route contract. So no tool is stale. Only the header is missing, a gap that predates this PR.

Everything else passes:

  • Tier 1: 23 pass / 5 skip. dev-ci is green.
  • Schema: dual track ✅. The Alembic line has a single head and merge-tree against live dev is clean.
  • Journey Impact, secrets, the enterprise-docs grep and the §4.11 audit rows all pass.
  • No internal product terms in the diff, PR text or UI copy.
  • Tests run here: test_ent1202_default_model_resolution + test_platform_default_model_regression 47 passed. memberAgentModelPanel.spec.js 5 passed (jsdom mount).

Warnings (do not block):

Not run: /review / /cso --diff (out of scope; the PR body records its own), any full suite, the Tier 2 PR-side runs (lane B doesn't need them), and the post-merge dev-ci check.

@trinity-ability trinity-ability added the status-needs-fix PR has an unaddressed review/validation finding; cleared by the author's next push (#2815) label Nov 10, 2026
…ariant #13)

Answers /validate-pr V1 on #4431. chat.py points at chat.ts
(chat_with_agent, get_chat_history) and connector.ts (run_playbook, ask);
a2a.py points at a2a.ts (get_agent_a2a_card) and a2a_call.ts
(call_a2a_agent, get_a2a_task). Comment-only; no route changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@trinity-ability

Copy link
Copy Markdown
Contributor

/validate-pr re-validation: fix-6 (V1 only), tip d83afc89a

Decision: APPROVE on code (V1 cleared). Merge waits until pytest (head, seed 12345) is green (still running at 03:33Z). Everything else in the 03:04Z decision (issuecomment-6757781700) stands and is not repeated here.

Fix-6 scope: confirmed. It is one commit with 2 insertions, both first-line comments (src/backend/routers/chat.py, src/backend/routers/a2a.py). It makes no other change.

V1: Invariant #13 (§5.5). Ran the block at head d83afc89a

line the block printed answer
❌ #13 src/backend/routers/chat.py: 19 code line(s) changed; covering tool chat.ts connector.ts untouched (b) passes. Header present; tools chat_with_agent, get_chat_history (chat.ts), run_playbook, ask (connector.ts). Contract change = GET /api/agents/{name}/model gains default_model, default_model_source, default_model_refused, backend_turn_model. grep -nE '/model\b|default_model|default_model_source|default_model_refused|backend_turn_model' chat.ts connector.ts a2a.ts a2a_call.ts → 0 hits (exit 1). Same grep over all src/mcp-server/src → 0. No tool sends, branches on, or documents any of these.
❌ #13 src/backend/routers/a2a.py: 5 code line(s) changed; covering tool a2a.ts a2a_call.ts untouched (b) passes. Header present; tools get_agent_a2a_card (a2a.ts), call_a2a_agent, get_a2a_task (a2a_call.ts). The diff changes only how the pre-created row's model is resolved (resolve_default_model(strict=True)). No path, param, status code or response field changes. Same grep → 0 hits.
❌ #13 src/backend/routers/agent_config.py: 7 code line(s) changed; covering tool permissions.ts untouched Not part of V1, but the block prints it, so it is answered here. (b) passes. Header present (get_agent_capability_grants). The only change is the value of resolved_model (now falls through to the agent's own model). grep -rn 'resolved_model|public_chat_model' src/mcp-server/src → 0; default_model|/model in permissions.ts → 0.

The engineer's report of 0 references is verified.

CI rollup (03:24Z, rechecked 03:33Z)

All checks pass or skip except pytest (head, seed 12345): pending. Job 129604116157 has been in_progress since 03:11:57Z. Passing: Analyze (python), Analyze (javascript-typescript), schema-parity, verify-non-root, CodeQL, gitleaks, both guards, lint, journey-impact, pg-migrations, e2e, build, prod-image-smoke, cached dev baseline, backend boots without enterprise submodule, verify-compose-file-sets, verify-docker-gid-detection. Skipped: report, journey-smoke, pytest (base, inline fallback), pytest (push, absolute failures), auto-merge, clear-needs-fix. dev-ci: success. No ent926 red is visible yet.

Merge condition: wait for pytest (head, seed 12345) and the regression diff to come back green. If ent926 is the only red, that is the known base flake (#4401, #4428). Any other red blocks the merge.

Not run

  • The result of pytest (head, seed 12345) and the regression diff. They were still running when the 15-minute budget ran out.
  • §5.5 Invariant Setup improvements #5 twin half and every other step. Narrow pass by rider; they are covered by the 03:04Z decision.

Merge order unchanged: #4431 → abilityai/trinity-enterprise#1210 → gitlink bump.

@vybe
vybe marked this pull request as ready for review November 10, 2026 03:34
@vybe vybe removed the status-needs-fix PR has an unaddressed review/validation finding; cleared by the author's next push (#2815) label Nov 10, 2026

@dolho dolho left a comment

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.

Reviewed with /validate-pr at d83afc89a (Lane B + schema), together with abilityai/trinity-enterprise#1210. Approving.

Verified

  • Schema, both tracks: the SQLite entry agent_ownership_default_model, Alembic 0123_agent_ownership_default_model, and the DDL in schema.py / tables.py. check_alembic_heads.py: 124 revisions, 1 head. dev is still at 0122, so the only fork is against open #4425 (disjoint tables, mechanical; the body says so).
  • test_ent1202_default_model_resolution.py (20 tests, none reads source text) plus the touched a2a, gate-caller, schedule and regression files: 391 passed.
  • Frontend: memberAgentModelPanel.spec.js mounts the panel; with the three ratchets, 33 passed.
  • The resolver is an allowlist on read (unrunnable_reason), so an author-controlled value never reaches --model. stamp_model_used_if_null only fills a blank. set_default_model_if uses IS NOT DISTINCT FROM, which SQLAlchemy renders correctly on both backends.
  • The change to test_platform_default_model_regression.py follows the helper into the resolver rather than dropping the guard.
  • Secret, address and host-path greps: clean. No enterprise detail in the public docs.
  • CI: all green at this head.

Non-blocking

  1. Sync calls on the event loop. GET /model moved the resolver into asyncio.to_thread (review I4), but get_public_channel_model, set_public_channel_model (routers/agent_config.py) and _mint_a2a_execution (routers/a2a.py) call resolve_default_model directly. Each call is now a DB read plus a runtime lookup where there was one settings read.
  2. A non-Claude agent's stored value is never read. resolve_default_model returns before the DB read when the runtime is not Claude Code, so GET /model reports default_model: null for a Codex agent even when the column is set. Harmless for turns; the read-back just can't show what is stored. See the related finding on #1210.
  3. set_default_model has no deleted_at IS NULL filter, while the two readers do. It matches set_public_channel_model, so I'm only noting it.
  4. No closing keyword ("Part of …#1202"): the issue status needs moving by hand after merge.
  5. The body flags T10 (public turns now follow the agent's own model) for the release notes. Worth making sure that lands, since it is a behaviour change for anyone who sets the column.

@dolho
dolho merged commit 2a4f0b9 into dev Nov 10, 2026
29 checks passed
@vybe
vybe deleted the feature/1202-template-runtime-model branch November 10, 2026 18:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ui PR touches the frontend UI — triggers Playwright e2e tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants