Skip to content

fix(anthropic): configurable max_tokens to prevent extended-thinking truncation (#45)#46

Merged
Izzetee merged 1 commit into
mainfrom
fix/anthropic-max-tokens-45
Jul 10, 2026
Merged

fix(anthropic): configurable max_tokens to prevent extended-thinking truncation (#45)#46
Izzetee merged 1 commit into
mainfrom
fix/anthropic-max-tokens-45

Conversation

@Izzetee

@Izzetee Izzetee commented Jul 10, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes #45 — extended-thinking Anthropic models (e.g. claude-sonnet-5 on Azure AI Foundry) intermittently failed benchmark/chat tasks with missing 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 its thinking block — producing no text block. 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

  • Make max_tokens configurable via ANTHROPIC_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).
  • Surface stop_reason: max_tokens truncation as a distinct, actionable error pointing to ANTHROPIC_MAX_TOKENS, instead of the generic "missing text" message.
  • Tests: add the truncation case to TestExtractAnthropicContent; update the selection test's expected budget.
  • Docs: document the setting in .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

…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
@Izzetee
Izzetee merged commit 0b87a93 into main Jul 10, 2026
7 checks passed
@Izzetee
Izzetee deleted the fix/anthropic-max-tokens-45 branch July 10, 2026 11:22
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.

[Bug] Extended-thinking Anthropic models truncate at max_tokens before producing text

1 participant