Skip to content

fix(agent): redesign compaction to use tree branching#19

Merged
urmzd merged 2 commits intomainfrom
fix/compaction-redesign
Mar 30, 2026
Merged

fix(agent): redesign compaction to use tree branching#19
urmzd merged 2 commits intomainfrom
fix/compaction-redesign

Conversation

@urmzd
Copy link
Copy Markdown
Owner

@urmzd urmzd commented Mar 29, 2026

Summary

  • Compaction redesign: compaction now forks a new branch off root via tree.Branch, adds compacted messages as nodes, and sets the new branch as active. Original branch is preserved untouched. This also eliminates the re-firing bug (new branch starts below threshold).
  • Seven contained fixes: configurable KeepLast (was hardcoded to 4), ToolUseContent serialization in MessagesToText, SlidingWindowCompactor tool-pair integrity check, compactNow no-op warning, removal of unused tree.Store/WithStore, and joinStringsstrings.Join.

Test plan

  • All ./agent/... tests pass
  • All ./rag/... tests pass
  • TestAgentWithSummarizeCompactor updated to verify both the active (compacted) branch and the preserved main branch
  • Manual verification of compaction with agentic tool-use conversations (ToolUseContent/ToolResultContent pairs)

urmzd added 2 commits March 29, 2026 18:03
… bugs

Compaction now forks a new branch off root instead of only modifying the
in-memory message slice. This preserves the original branch, prevents
the SummarizeCompactor from re-firing every iteration, and sets the
compacted branch as active for subsequent Invoke calls.

Additional fixes: configurable KeepLast, ToolUseContent serialization,
SlidingWindow tool-pair integrity, compactNow warning, remove unused
tree.Store, replace joinStrings with strings.Join.
Extract compaction logic from runLoop into tryCompact helper to bring
cyclomatic complexity from 31 to under 30 (fixes CI lint failure).

Add 13 tests covering persistCompacted, tryCompact, SlidingWindow
tool-pair integrity, configurable KeepLast, MessagesToText with
ToolUseContent, and CompactConfig round-trip.
@urmzd urmzd merged commit 4b49086 into main Mar 30, 2026
6 checks passed
@urmzd urmzd deleted the fix/compaction-redesign branch March 30, 2026 00:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant