fix: wire ephemeral max_tokens into chat_completions + NVIDIA NIM default#12231
Merged
Conversation
Contributor
|
…NVIDIA NIM default Based on #12152 by @LVT382009. Two fixes to run_agent.py: 1. _ephemeral_max_output_tokens consumption in chat_completions path: The error-recovery ephemeral override was only consumed in the anthropic_messages branch of _build_api_kwargs. All chat_completions providers (OpenRouter, NVIDIA NIM, Qwen, Alibaba, custom, etc.) silently ignored it. Now consumed at highest priority, matching the anthropic pattern. 2. NVIDIA NIM max_tokens default (16384): NVIDIA NIM falls back to a very low internal default when max_tokens is omitted, causing models like GLM-4.7 to truncate immediately (thinking tokens exhaust the budget before the response starts). 3. Progressive length-continuation boost: When finish_reason='length' triggers a continuation retry, the output budget now grows progressively (2x base on retry 1, 3x on retry 2, capped at 32768) via _ephemeral_max_output_tokens. Previously the retry loop just re-sent the same token limit on all 3 attempts.
4954768 to
f38de37
Compare
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
Salvage of #12152 by @LVT382009.
What this fixes
_ephemeral_max_output_tokensnot consumed by chat_completions — The error-recovery ephemeral override (set when the API returns "max_tokens too large given prompt") was only consumed in theanthropic_messagesbranch of_build_api_kwargs. Allchat_completionsproviders (OpenRouter, NVIDIA NIM, Qwen, Alibaba, custom, etc.) silently ignored it. Now consumed at highest priority in the cascade, matching the anthropic pattern.NVIDIA NIM max_tokens default (16384) — NVIDIA NIM falls back to a very low internal default when
max_tokensis omitted, causing models like GLM-4.7 to truncate immediately (thinking tokens exhaust the budget before the response starts).Progressive length-continuation boost — When
finish_reason='length'triggers a continuation retry, the output budget now grows progressively (2x base on retry 1, 3x on retry 2, capped at 32768) via_ephemeral_max_output_tokens. Previously the retry loop re-sent the same token limit on all 3 attempts.Test plan
pytest tests/run_agent/ tests/agent/test_auxiliary_client.py— 851 passed (3 pre-existing failures on main)Closes #12152