fix(reflect): cap done tool answers - #2757
Conversation
Apply the configured max_tokens budget when the reflect agent finishes through the done tool. Add a regression test covering the previously uncapped completion path.
|
Thanks @Sanjays2402 — and nice root-cause report on #2756. I verified this locally: the fix faithfully mirrors the existing short-circuit rewrite path (same prompt, Routing to @nicoloboschi for the merge call, because this is a behavior decision as much as a bug fix. Today two of the three final-answer paths (forced-final, direct-text short-circuit) enforce the cap; the done path — the common one — does not. Applying the cap here means an extra LLM round-trip + a lossy summarization rewrite on the hot path, turning Fix looks correct and ready if you want it; flagging the design tradeoff so the decision is yours. cc @nicoloboschi |
Fixes #2756.
The normal
donetool path now applies the same capped rewrite used by direct-text completions when an answer exceedsmax_tokens. The rewrite's token usage and trace entry are included in the final result.Regression coverage confirms the done-tool answer is uncapped before this change and rewritten with the configured budget afterward.