Skip to content

fix(chat): say which key an agent's picked model runs on - #2132

Merged
gkhngyk merged 2 commits into
ansvisor:mainfrom
cihan-gyk:fix/agent-form-key-line
Nov 5, 2026
Merged

gkhngyk merged 2 commits into
ansvisor:mainfrom
cihan-gyk:fix/agent-form-key-line

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

The Model step of the agent form (Agent Center › New agent or Edit) shows a line under the models. It reads either "Runs on your {provider} key, which {provider} bills…" or "Uses your monthly AI limit". Which one it showed depended only on Auto's key (setup.ownKeyProvider), whatever model was chosen. That was right before #2032 and #2033, but it's wrong now:

Take a workspace whose own key is OpenAI. An agent on Fast (Haiku) or Best writing (Sonnet) there runs on the AI limit, but the form still said "Runs on your OpenAI key".

What changes. Two texts now follow the model the form has chosen: the key line, and the note under Max per run ("On your own key it is measured at list prices"). The key is picked the way the engine picks it:

Chosen model The line says
Auto, with a workspace key for Chat Runs on your {provider} key (Auto's key, as before)
A picked model whose provider has a workspace key Runs on your {that provider} key, e.g. Anthropic for Fast and Best writing
A picked model with no key for its provider, and a workspace OpenRouter key Runs on your OpenRouter key
Anything else Uses your monthly AI limit (the existing wording)

It also covers two cases where the engine runs Auto anyway, and the line shows Auto's key:

  • the free trial (modelChoiceOpen);
  • a model that is no longer offered (runChoiceOf).

One rule, not two copies. The key order now lives in pure helpers in web/src/lib/chat/models.ts, which the browser can import:

  • pickedModelKeyOrder(provider) gives the order: the provider's own key, then OpenRouter. resolvePickedModelKey now loops over it. Its behavior doesn't change.
  • pickedModelOwnKey(provider, ownKeyProviders) names the own key that runs the model, or returns null for the AI limit. The model menu's Your key badge (model-menu.ts) now uses it instead of its own copy of the rule.
  • modelKeyProvider(model, setup) in web/src/lib/chat/agent-form.ts is what the form calls:
    • it first applies runChoiceOf;
    • a picked model then gets pickedModelOwnKey;
    • otherwise it gets Auto's key.

Server data. agentFormSetupFor (agent-form-setup.ts) feeds the new and edit pages. It now adds two fields:

  • ownKeyProviders comes from ownChatKeyProviders, the same read the model menu uses. It reads which providers have a key for Chat and decrypts no key. If the read fails, it logs the error and falls back to [].
  • modelChoiceOpen comes from modelChoiceOpen(ctx.plan).

No strings change: the existing chatAgents.form.model.ownKey and model.limit cover every case.

Tests

  • agent-form.test.ts: modelKeyProvider for each case:
    • Auto on a key, and Auto on the limit;
    • a picked model on its provider's key (before OpenRouter), and on the OpenRouter key;
    • a picked model on the limit while Auto runs on an OpenAI key;
    • the trial, and a model that is no longer offered.
  • key-routing.test.ts: checks that pickedModelOwnKey agrees with resolvePickedModelKey for every set of saved keys tested (none, Anthropic, OpenRouter, OpenAI, and pairs), so the form and the engine can't drift apart.
  • agent-form.test.tsx: the rendered line and Max per run's note change as Auto, Fast and Best writing are clicked. The test covers four setups:
    • an OpenAI key: Fast and Best writing are on the limit;
    • Anthropic and OpenRouter keys: they run on Anthropic;
    • an OpenRouter key only: they run on OpenRouter;
    • the trial: the line shows Auto's key.
  • agent-form-setup.test.ts: the setup carries ownKeyProviders and modelChoiceOpen. It checks the [] fallback when the read fails, and that a Growth trial gets modelChoiceOpen: false.

Help: no article change in this PR.

Related issue

None. Found while checking Help against #2032 and #2033 (see #2130).

Type of change

  • feat — New feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

  1. On an Enterprise workspace, go to Settings › AI Providers. Save an OpenAI key for Chat and make it the active one. Have no Anthropic or OpenRouter key.
  2. Open Agent Center › New agent and go to the last step, Connections & model.
    • Auto: the line reads "Runs on your OpenAI key, which OpenAI bills…", and the Max per run note mentions list prices.
    • Fast or Best writing: the line reads "Uses your monthly AI limit", and the Max per run note has no list-price sentence.
  3. Add an Anthropic key for Chat. Fast and Best writing now say "Runs on your Anthropic key…". Remove it and add an OpenRouter key: they say "Runs on your OpenRouter key…".
  4. Edit an existing agent: the line matches its saved model.
  5. Run cd web && npx vitest run src/lib/chat/agent-form.test.ts src/lib/chat/agent-form-setup.test.ts src/lib/chat/key-routing.test.ts src/lib/chat/model-menu.test.ts src/components/chat/agents/agent-form.test.tsx.

Checklist

Checked locally on d7c42de (branched from main 8be573d):

  • web format:check passes. lint has 0 errors, and its 7 warnings are all in files this PR doesn't touch.
  • typecheck passes.
  • All tests pass: 974 files, 10,405 passed, 1 skipped.
  • yarn build passes with CI's placeholder env.

Nothing under server/, supabase/, skills/ or help/ changed.


Generated by Claude Code

The Model step of the agent form (Agent Center > new or edit agent) said
"Runs on your {provider} key" from Auto's key alone. Since ansvisor#2032 an agent
runs on its own model, and since ansvisor#2033 a picked model runs on the key for
its provider, then the workspace's OpenRouter key, then Ansvisor's key on
the monthly AI limit. So an agent on Fast or Best writing in a workspace
whose own key is OpenAI ran on the AI limit while the form said OpenAI.

The line and Max per run's note now follow the model the form has chosen,
as the engine picks its key:
- Auto: the key Auto runs on, else the monthly AI limit;
- a picked model: the own key for its provider, else the OpenRouter key,
  else the monthly AI limit;
- the free trial, and a model no longer offered, run Auto: Auto's key.

The order lives in one place: pickedModelKeyOrder and pickedModelOwnKey
(lib/chat/models.ts, safe in the browser). resolvePickedModelKey loops
over pickedModelKeyOrder, the model menu's "Your key" uses
pickedModelOwnKey, and the form's modelKeyProvider uses it with
runChoiceOf. The form's setup carries the providers of the own keys for
Chat (ownChatKeyProviders, no key decrypted) and whether the plan runs a
picked model (modelChoiceOpen).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
gkhngyk
gkhngyk previously approved these changes Nov 5, 2026

@gkhngyk gkhngyk 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.

LGTM.

ansvisor#2036 (model providers) changed model-menu.ts's imports; keep both its
provider imports and this branch's pickedModelOwnKey. The agent form
offers only Anthropic models (Auto, Fast, Best writing), which the
provider switches can't turn off, so the key line needs no change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9

@gkhngyk gkhngyk 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.

LGTM.

@gkhngyk
gkhngyk merged commit c7c0f9a into ansvisor:main Nov 5, 2026
12 checks passed
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.

3 participants