fix(anthropic): configurable max_tokens to prevent extended-thinking truncation (#45)#46
Merged
Merged
Conversation
…truncation Extended-thinking Claude models (e.g. claude-sonnet-5 on Azure AI Foundry) count thinking tokens toward the output budget. With max_tokens hard-coded to 4096, harder benchmark/chat prompts were cut off (stop_reason=max_tokens) while still in the thinking block, producing no text and failing with the misleading "missing text in Anthropic content block". - Make max_tokens configurable via ANTHROPIC_MAX_TOKENS (default 12800) and apply it to all Anthropic call sites: chat/benchmark answers, the benchmark judge, and the routing meta-model. - Surface stop_reason=max_tokens truncation as a distinct, actionable error that points to ANTHROPIC_MAX_TOKENS, instead of the generic "missing text" message. - Add tests for the truncation case; update the selection test's expected budget. - Docs: document ANTHROPIC_MAX_TOKENS in .env.example, README, SETUP, AGENTS.md, copilot-instructions, and add a CHANGELOG entry. Fixes #45
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
Fixes #45 — extended-thinking Anthropic models (e.g.
claude-sonnet-5on Azure AI Foundry) intermittently failed benchmark/chat tasks withmissing text in Anthropic content block.Root cause
The Anthropic Messages API request hard-coded
max_tokens: 4096. Extended-thinking models count thinking tokens toward the output budget, so on harder prompts the model was cut off (stop_reason: max_tokens) while still in itsthinkingblock — producing notextblock. It was intermittent because only harder tasks needed more thinking than 4096 tokens allowed. The same hard-coded limit existed on all three Anthropic call sites (chat/benchmark answers, the benchmark judge, and the routing meta-model).Changes
max_tokensconfigurable viaANTHROPIC_MAX_TOKENS(default 12800) and apply it to all three Anthropic paths (internal/llm/chat.go,internal/benchmark/scorer.go,internal/llm/model_selection.go).stop_reason: max_tokenstruncation as a distinct, actionable error pointing toANTHROPIC_MAX_TOKENS, instead of the generic "missing text" message.TestExtractAnthropicContent; update the selection test's expected budget..env.example, README, SETUP,AGENTS.md,copilot-instructions.md, and add a CHANGELOG entry.Verification
go build,go vet, and the affected package tests pass.Fixes #45