Repository navigation
fix(compact): count and shed reasoning_content - #79
Merged
Merged
Conversation
With thinking_format=reasoning_content and thinking_in_history, every prior assistant turn carries its full reasoning on the wire, but estimate_tokens counted only content and no compactor touched the field. A DeepSeek-flash TBS run estimated ~3.5k tokens against a 66-80k real prompt, so Tier 2 never won and reasoning grew unbounded. - Both estimate_tokens implementations now include reasoning_content. - New strip_stale_reasoning(); Tier 1 keeps reasoning only on the last keep_tool_result assistant turns, compress_tool_results (tool-compression candidates and the Tier 2 input) keeps it only on the latest turn. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Collaborator
Author
Proxy check: stripped historical reasoning is accepted (llm-hub deepseek-flash)I tested the PR's assumption with a real request. First I ran a 3-turn tool-call chain ((17×23) → +41 → ×3) where every assistant turn returned
Not covered: the self-hosted DSV4 checkpoint ( |
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
With
thinking_format: reasoning_contentandthinking_in_history: true, previous assistant turns resend their reasoning, but compaction previously ignored it. A llm-hub deepseek-flash TBS run estimated about 3.5k tokens for a 66–80k-token prompt, preventing the tiered compactor from recognizing sufficient relief.This PR:
reasoning_contentin loop, state-aware middleware, and portableSummarizationMiddlewaretoken estimates.strip_stale_reasoning(messages, keep_last)without mutating the source history.keep_tool_result=-1still disables Tier 1 filtering). Tool-result compression candidates and Tier 2 input retain the latest assistant reasoning.keep_tool_result=0behavior.Proxy validation
A real llm-hub
deepseek-flashthree-turn tool-call chain was replayed with reasoning on all turns, only the latest turn, and no turns. All three requests returned HTTP 200 and the correct answer (1296). Prompt tokens were 599, 487, and 479 respectively, confirming the field contributes to the prompt and older reasoning can be omitted for this proxy.This does not establish compatibility with the self-hosted DSV4 checkpoint, which was unavailable, or answer-quality effects on long tasks.
Testing
keep_tool_result=0and-1, tool-result compression, and non-mutation.