You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This updates context compaction so it preserves complete tool rounds instead of trimming raw message slices.
The bug was that snip_compact and reactive_compact could separate an assistant message containing tool_use blocks from the following user message containing tool_result blocks. That leaves orphaned tool results in history and can break the next model request.
Changes
add message-span helpers in s08_context_compact, s09_memory, and s20_comprehensive
make snip_compact trim by complete tool rounds instead of raw message count
make reactive_compact retain a safe tail instead of messages[-5:]
update s08_context_compact docs and generated site docs to describe the constraint correctly
@wangle201210
Hi! The issue itself is valid, but the current PR implementation is too heavy. The current changes noticeably increase the complexity of the teaching code and make the README examples harder to read.This problem is better suited for a small boundary fix, rather than introducing a relatively heavy span/window helper system separately into s08/s09/s20.
@wangle201210 Hi! The issue itself is valid, but the current PR implementation is too heavy. The current changes noticeably increase the complexity of the teaching code and make the README examples harder to read.This problem is better suited for a small boundary fix, rather than introducing a relatively heavy span/window helper system separately into s08/s09/s20.
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
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
Fixes #325.
This updates context compaction so it preserves complete tool rounds instead of trimming raw message slices.
The bug was that
snip_compactandreactive_compactcould separate an assistant message containingtool_useblocks from the following user message containingtool_resultblocks. That leaves orphaned tool results in history and can break the next model request.Changes
s08_context_compact,s09_memory, ands20_comprehensivesnip_compacttrim by complete tool rounds instead of raw message countreactive_compactretain a safe tail instead ofmessages[-5:]s08_context_compactdocs and generated site docs to describe the constraint correctlyValidation
python3 -m py_compile s08_context_compact/code.py s09_memory/code.py s20_comprehensive/code.py