fix(agent): boost max_tokens on length-continuation retries#9489
Closed
ygd58 wants to merge 1 commit into
Closed
Conversation
Models with a low default output limit (e.g. GLM-4.7 on NVIDIA Build) truncate at the same limit on every continuation attempt, exhausting all 3 retries without ever finishing the response. Fix: set _ephemeral_max_output_tokens before each continuation retry, doubling the output budget per attempt (capped at 32K). This applies to both chat_completions and anthropic_messages modes: - chat_completions: _ephemeral_max_output_tokens now consumed in _build_api_kwargs() alongside the existing anthropic path - Retry 1: max_tokens * 2, Retry 2: max_tokens * 3 (max 32K) Fixes NousResearch#9372
1 task
Collaborator
|
Related to #12231 (merged) which wired ephemeral max_tokens into chat_completions. Check if the continuation-retry boost in this PR is already covered by that merge. |
1 task
Contributor
|
Thanks for this contribution @ygd58! The fixes described in this PR are already present on This is an automated hermes-sweeper review. Evidence:
As noted by @alt-glitch, PR #12231 (merged) covered the same ground. Closing as implemented on main. |
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.
Problem
Closes #9372
Models with a low default output limit (e.g. GLM-4.7 on NVIDIA Build) truncate at the same limit on every continuation attempt, exhausting all 3 retries without ever finishing.
Root Cause
The continuation loop sends the continue prompt but calls the API with the same max_tokens each time. If the model hits the limit on the first call, it hits it again on every retry.
Fix
Set _ephemeral_max_output_tokens before each continuation retry, growing the budget per attempt (capped at 32K): Retry 1 = max_tokens x 2, Retry 2 = max_tokens x 3.
Also extended _ephemeral_max_output_tokens consumption to the chat_completions path in _build_api_kwargs() so both chat_completions and anthropic_messages modes benefit.
Before / After
Before: GLM-4.7 truncated x3 at same limit, error.
After: GLM-4.7 retried with growing limit, more room to finish.