[GH-ISSUE #5039] [BUG]: Anthropic agent responses truncate at 4096 tokens on modern models #3160

Closed
opened 2026-02-22 18:32:50 -05:00 by yindo · 0 comments
Owner

Originally created by @elevatingcreativity on GitHub (Feb 20, 2026).
Original GitHub issue: https://github.com/Mintplex-Labs/anything-llm/issues/5039

How are you running AnythingLLM?

All versions

What happened?

The Anthropic agent provider hardcodes max_tokens: 4096 for all API calls. Modern Claude models
(Claude 3.5 and later) support output limits well above 4096 tokens, but the hardcoded value was
set when older models had smaller limits. As a result, agent responses are silently cut off at
4096 tokens regardless of which model is selected.

Affected versions:
All current versions of AnythingLLM using the Anthropic agent provider.

Behavior:
When an agent session produces a response longer than 4096 tokens — for example, when processing
large inputs passed via flow variables, or when a task requires a detailed output — the response
is truncated at 4096 tokens with no warning or error shown to the user.

Expected behavior:
Agent responses are not artificially limited below the selected model's actual output capacity.

Location:
The issue originates in server/utils/agents/aibitat/providers/anthropic.js, where max_tokens: 4096
is hardcoded in both the stream() and complete() methods (lines 192 and 319).

Fix:
Replaces the hardcoded max_tokens: 4096 with a per-model lookup table mapping each Anthropic model
to its actual API-enforced output token limit. Newer models (Claude 3.5+) get their full 8192
token capacity, legacy models stay safely at 4096, and any unknown or future models fall back to
4096 by default.

Will make a PR for the fix.

Are there known steps to reproduce?

Steps to reproduce:

  1. Configure AnythingLLM to use Anthropic with a Claude 3.5 or later model
  2. Start an agent session with a prompt that would naturally produce a long response (e.g.
    summarize a large document, or pass a large text block via a flow variable)
  3. Observe the response cuts off at approximately 4096 tokens
Originally created by @elevatingcreativity on GitHub (Feb 20, 2026). Original GitHub issue: https://github.com/Mintplex-Labs/anything-llm/issues/5039 ### How are you running AnythingLLM? All versions ### What happened? The Anthropic agent provider hardcodes max_tokens: 4096 for all API calls. Modern Claude models (Claude 3.5 and later) support output limits well above 4096 tokens, but the hardcoded value was set when older models had smaller limits. As a result, agent responses are silently cut off at 4096 tokens regardless of which model is selected. Affected versions: All current versions of AnythingLLM using the Anthropic agent provider. Behavior: When an agent session produces a response longer than 4096 tokens — for example, when processing large inputs passed via flow variables, or when a task requires a detailed output — the response is truncated at 4096 tokens with no warning or error shown to the user. Expected behavior: Agent responses are not artificially limited below the selected model's actual output capacity. Location: The issue originates in server/utils/agents/aibitat/providers/anthropic.js, where max_tokens: 4096 is hardcoded in both the stream() and complete() methods (lines 192 and 319). Fix: Replaces the hardcoded max_tokens: 4096 with a per-model lookup table mapping each Anthropic model to its actual API-enforced output token limit. Newer models (Claude 3.5+) get their full 8192 token capacity, legacy models stay safely at 4096, and any unknown or future models fall back to 4096 by default. Will make a PR for the fix. ### Are there known steps to reproduce? Steps to reproduce: 1. Configure AnythingLLM to use Anthropic with a Claude 3.5 or later model 2. Start an agent session with a prompt that would naturally produce a long response (e.g. summarize a large document, or pass a large text block via a flow variable) 3. Observe the response cuts off at approximately 4096 tokens
yindo added the possible bug label 2026-02-22 18:32:50 -05:00
yindo changed title from [BUG]: Anthropic agent responses truncate at 4096 tokens on modern models to [GH-ISSUE #5039] [BUG]: Anthropic agent responses truncate at 4096 tokens on modern models 2026-06-05 14:50:39 -04:00
yindo closed this issue 2026-06-05 14:50:39 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Mintplex-Labs/anything-llm#3160