Repository navigation
fix(chat): say which key an agent's picked model runs on - #2132
Merged
Merged
Conversation
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
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:agent-driver.tspassesversion.model).resolvePickedModelKeyinweb/src/lib/chat/key.ts, used byresolveChatModels):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:
It also covers two cases where the engine runs Auto anyway, and the line shows Auto's key:
modelChoiceOpen);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.resolvePickedModelKeynow 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)inweb/src/lib/chat/agent-form.tsis what the form calls:runChoiceOf;pickedModelOwnKey;Server data.
agentFormSetupFor(agent-form-setup.ts) feeds the new and edit pages. It now adds two fields:ownKeyProviderscomes fromownChatKeyProviders, 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[].modelChoiceOpencomes frommodelChoiceOpen(ctx.plan).No strings change: the existing
chatAgents.form.model.ownKeyandmodel.limitcover every case.Tests
agent-form.test.ts:modelKeyProviderfor each case:key-routing.test.ts: checks thatpickedModelOwnKeyagrees withresolvePickedModelKeyfor 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:agent-form-setup.test.ts: the setup carriesownKeyProvidersandmodelChoiceOpen. It checks the[]fallback when the read fails, and that a Growth trial getsmodelChoiceOpen: false.Help: no article change in this PR.
help/chat/models.mdalready gives the order for a picked model.help/chat/agents.md› On your own AI key said every agent runs on the workspace's key. docs(help): one section for agents that publish on their own #2130 fixes that: it says agents on Auto run on that key, and gives the order for Fast and Best writing. The form line now says the same thing. Editing that section here too would conflict with docs(help): one section for agents that publish on their own #2130.Related issue
None. Found while checking Help against #2032 and #2033 (see #2130).
Type of change
feat— New featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsHow to test
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
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/)yarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)help/(or no user-visible change) — see help/README.md: no change needed here; docs(help): one section for agents that publish on their own #2130 corrects On your own AI keyChecked locally on d7c42de (branched from main 8be573d):
format:checkpasses.linthas 0 errors, and its 7 warnings are all in files this PR doesn't touch.typecheckpasses.yarn buildpasses with CI's placeholder env.Nothing under
server/,supabase/,skills/orhelp/changed.Generated by Claude Code