You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
AI Agent responses get cut off mid-answer — no maxOutputTokens set, provider falls back to 4096 #539
The installed @ai-sdk/anthropic (3.0.81) has no entry for claude-sonnet-5 in its known-model capabilities table, so the model falls into the unknown-model branch with a default of maxOutputTokens: 4096 — that's the max_tokens sent to the Anthropic API.
On claude-sonnet-5, adaptive thinking is on by default when the thinking parameter is omitted, and thinking tokens count against the same max_tokens budget. The visible answer therefore gets significantly less than 4096 tokens, and long responses stop with stop_reason: max_tokens mid-sentence.
Fix
Add an explicit output cap to the streamText call in web/src/app/api/agent/chat/route.ts:
The route already streams, so a higher cap carries no timeout risk; the model still stops naturally when the answer is done — this only raises the ceiling.
The limit applies per generation step in the tool loop (stopWhen: stepCountIs(20)), so the truncation showed up mostly on long final answers.
Cost is on the org's own BYOK Anthropic key and scales with actual usage, not with the cap.
Acceptance criteria
Long agent answers complete instead of stopping mid-sentence.
Tool-calling behavior and token-usage recording (recordAgentTokenUsage) are unchanged.
Activity
BharadwajKanneveti commentedon Jul 28, 2026
Hi @gkhngyk I will work on this issue
gkhngyk commentedon Jul 30, 2026
Assigned to you @BharadwajKanneveti — looking forward to the PR!