Skip to content

fix(prompt): send an Anthropic model the version map does not hold under its own id - #2219

Open
Aleksei Priakhin (alexcmd) wants to merge 2 commits into
JetBrains:developfrom
alexcmd:fix/anthropic-unknown-model
Open

Aleksei Priakhin (alexcmd) wants to merge 2 commits into
JetBrains:developfrom
alexcmd:fix/anthropic-unknown-model

Conversation

@alexcmd

Copy link
Copy Markdown
Member

Narrowing the context window of a predefined model makes it unusable:

val model = AnthropicModels.Sonnet_4.copy(contextLength = 100_000)
client.execute(prompt, model)   // IllegalArgumentException: Unsupported model: LLModel(...)

AnthropicClientSettings.modelVersionsMap is keyed by the whole LLModel value, and the lookup at AnthropicLLMClient.kt:449 throws when there is no entry. Change any field of a model the library ships and it stops being a model the library knows — the id is the same, the provider is the same, and the request never leaves the process.

The same lookup refuses a model released after the library. The map that ships today ends at claude-opus-4-7, so naming a newer model — which is the whole point of LLModel taking an id — fails with an argument error thrown from inside a client the caller did not think they were configuring.

There is an escape hatch, and it does not reach this lookup: AnthropicModels.addCustomModel adds to customModels, which feeds the models listing, while DEFAULT_ANTHROPIC_MODEL_VERSIONS_MAP is a separate top-level internal val built from the fixed set. A caller who follows the public API to register a custom model is still refused when they use it.

The change. A model the map does not hold is sent under model.id. A model the map does hold keeps its pinned dated snapshot, which is why the map exists and is unchanged: claude-sonnet-4-0 still resolves to claude-sonnet-4-20250514. Anthropic resolves an alias to its current snapshot itself, so a caller who wrote an alias gets what they asked for, and an id the API does not know now comes back as an error from the API naming the model.

The provider check is kept — an OpenAI model handed to the Anthropic client is a caller mistake, and that half of the old refusal is worth keeping. It is now stated as such rather than as "unsupported model".

Four tests, written against develop first: two of them (testAModelTheMapDoesNotKnowIsSentUnderItsOwnId, testACopiedPredefinedModelIsStillSentUnderItsId) fail there and pass here, while the pinned-version and wrong-provider tests pass on both — so the pair that changed is exactly the pair intended.

./gradlew :prompt:prompt-executor:prompt-executor-clients:prompt-executor-anthropic-client:jvmTest passes (50 tests), along with the openai-client and agents-core suites. Nothing in the repository referenced the old message.

Same shape as #2212 for the OpenAI client: a hand-written model refused for a reason that is about the library's bookkeeping rather than about the model.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.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