Let capabilities set the model and settings in `clai2` by passing only the user's own choices to `agent.run`
clai2 always passed model= to agent.run(), even when the user never chose a model. It also passed its GPT-6/GPT-5.6 family defaults, merged with the saved /model_settings overrides, as run-level model_settings. Run-level values beat agent- and capability-level ones, so anything configured below run level was silently overridden. That includes Logfire AgentControl, plugin capabilities, and capabilities on an --agent. Now only what the user explicitly chose goes to run(), and CLAI's own defaults sit below it.
New public surface: none (internal Session attributes only).
What moved where
- Default model: a model counts as chosen when it is in
Settings.model_fields_set: from-m,CLAI_MODEL, the project file, a saved/set modelor/model, or a fork's@model. A chosen model is still passed torun(). An unchosen default (openai-codex:gpt-6-astra) becomes the stock agent's own model, so a capability'sget_model()takes precedence. Names still resolve through CLAI's existing resolver first (Codex auth, OpenRouter, vLLM, Copilot, plugin providers), now via anoutermostrun-levelResolveModelId. Names it returns unchanged go on to agent and plugin resolvers and then toinfer_model, as before. - Family defaults: now an
outermostrun capability that resolves per request from the request's model name (ctx.model_id). It is merged before every other capability, and the defaults follow a model that a capability switches to. - Run-level settings: only the saved overrides, and only for requests on the model they were saved for. Codex-only settings are not sent to a model a capability selected. Like main's mid-turn
/model settings(#9831), both the overrides and the defaults' view of what was saved are read again before each request. - I didn't touch the
/model,/add_modelor/model_settingscommand and menu code. The only change near it:CommandContext.validate/reset_settingnow dump withexclude_unset, so/setand reset preserve which fields were actually chosen.
User-visible behavior
pydantic_clai2/runtime/_session.py :: Session.prompt()
+├─ Session._bind() # unchosen default → stock agent's own model; family defaults → outermost capability
-└─ Agent.run(model=<chosen or CLAI default>, model_settings=<family defaults + saved overrides>)
+└─ Agent.run(model=<chosen model only>, model_settings=<saved overrides, on their model only>)
└─ … unchanged machinery …
- └─ capability get_model() / get_model_settings() → overridden by run-level values
+ └─ capability get_model() / get_model_settings() → take effect over CLAI's defaults
Verification: tests/clai2/test_run_model_layers.py
test_effective_settings_unchangedcompares what the model receives before and after the change: the oldrun(model_settings=context.model_settings(name))against a real shell turn now. It covers OpenAI reasoning (including OpenRouter overrides), Anthropic, Codex as the default and chosen (including fast mode with custom params), and Copilot, on both the stock and a supplied agent. Equal in every case.- Further tests cover capability settings beating defaults but not saved overrides, a capability model replacing the default, a chosen model (saved or
-m) beating a capability, saved settings staying with their model, model-name resolution order,/set/reset keeping the model unchosen, and forks.
What changes for existing users: nothing, unless a capability selects a model or supplies overlapping settings. Such a capability now takes effect over CLAI's default model and family defaults; the user's chosen model and saved settings still win. Agent-level model_settings stay beneath the family defaults, as before.
Checklist
- No breaking changes in accordance with the version policy.
- Any permitted compatibility impact has a label, warning, migration, release note, and exact API-check waiver.
- PR title is fit for the release changelog.
Opened by Claude (Douwe's coding agent).
Part of #9781