Repository navigation
fix(platform): steer chat tool budget and derive limits from catalog - #2980
Merged
Merged
Conversation
A chat turn that hit MAX_TOOL_ROUNDS withheld the tools silently, so the model announced its next lookup and stopped instead of answering, and the reply ceiling was a hardcoded 4096 whatever the model declared. Steer the round budget instead of enforcing it silently: - Wire-only user-role notices (the truncation-notice pattern, never persisted): the last offered round tells the model to batch every remaining lookup as parallel calls, the forced round tells it the budget is spent and to answer from what it read, stating coverage. - One tool-docs line declares the per-reply lookup budget up front. Derive capability limits from the model catalog instead of constants: - Default and thinking maxTokens follow the declared maxOutputTokens (4096 only as the undeclared fallback), under an output share of half the window so the reply never starves the history slice. - fitSamplingToWindow re-applies the share when governance shrinks the effective window, shrinking a thinking budget alongside to keep the maxTokens > budgetTokens wire invariant. - The flat 96k history cap is gone: the history slice is the effective window minus reserve and system prompt; cost control belongs to the governance maxContextTokens cap alone. Verified live against a 491-page BGB.pdf: the capped turn now batches six parallel rag_fetch reads in its last round and ends with a complete cited answer, and deepseek-v4-flash (1M window / 384k output declared) requests 393216 output tokens instead of 4096, finishing the previously truncated section with a proper ending.
7 tasks
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
Two hardcoded ceilings degraded document-heavy chat turns (repro: 491-page BGB.pdf, a five-topic "详细说说" question):
MAX_TOOL_ROUNDSended without an answer. The loop withholds the tools on the forced final round, but nothing told the model — mid-plan, it announced its next lookup ("现在让我搜索…") and stopped. The unit test masked this: its fake model conveniently answers when tools vanish; real models don't. Therag_fetchkeep-fetching steer made it worse on huge documents.max_tokens: 4096— the seven-section answer cut off mid-sentence. The flat 96k history cap was the same class of hardcode.Change
Steer the round budget instead of enforcing it silently (
turn.ts,context.ts):Derive capability limits from the model catalog (
effort.ts,budget.ts,context.ts,turn_action.ts):maxTokensfollow the declaredmaxOutputTokens; 4096 survives only as the undeclared-entry fallback. The one structural rule left is the output share — half the window (the precedent the thinking budget clamp already used) — so a huge declared output can never starve the history slice.fitSamplingToWindowre-applies that share when governance shrinks the effective window, shrinking a thinking budget alongside so themaxTokens > budgetTokenswire invariant survives.maxContextTokenscap, not a hidden constant. Note the cost surface: long threads on 1M-window models now replay what the window allows.Verification
rag_fetchreads in its last round and ends with a complete, cited seven-section answer plus an honest "not read" caveat, instead of a dangling narration. After the ceiling change the wire requests 393216 output tokens instead of 4096, and the previously truncated §§ 355–361 exposition completes with a proper ending; the model's long deliberation lands in the thinking accordion, not the visible text.