feat(context): keep the latest read of each file inline - #40
Merged
Conversation
Stops the re-read loop on multi-file tasks: once the agent has read a file, its most-recent read stays in live context instead of being externalized to an artifact, so the model doesn't re-read the same file to "confirm." - ContextManager gains `keepLatestReadsInline` (default true) and `readToolNames` (default ["read_file"]). - modelMessages() precomputes the newest `rest` index per file path for keep-worthy reads (in readToolNames, not error, ≤ maxActiveResultChars), and the oldest-first eviction loop skips externalizing the whole exchange that holds a latest-per-path read (preserving tool_call/result pairing). - Bounded: only over inlineBudgetChars, size-capped per read, and older kept reads still fall out via Conversation.trim() — can't grow unbounded. Tests (5): latest read kept while older shell evicted; only newest read of a path kept; newest read of each distinct path kept; large read still externalized (size guard); flag off restores old behavior. Full suite 160 green. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
What
Stops the re-read loop on multi-file coding tasks. Once the agent reads a file, its most-recent read stays in live context instead of being externalized to an artifact — so the model doesn't re-read the same file to "confirm" (the behavior that burned 100+ tool calls / hit the turn cap).
How
ContextManagergainskeepLatestReadsInline: Bool = trueandreadToolNames: Set<String> = ["read_file"](a set so the generic manager isn't coupled to any tools product).modelMessages(): buildscallsByIDbefore the eviction loop, precomputes the newestrestindex per file path for keep-worthy reads (inreadToolNames, not an error, ≤maxActiveResultChars), and the oldest-first eviction loop skips externalizing the whole exchange that holds a latest-per-path read — keeping the whole exchange preservestool_call/tool_resultpairing (a provider requirement).inlineBudgetChars, each kept read is size-capped, and older kept reads still fall out viaConversation.trim()— can't grow unbounded.Testing
✅ Full suite 160 green, incl. 5 new: latest read kept while older
run_shellevicted; only newest read of a path kept; newest of each distinct path kept; a read > maxActiveResultChars still externalized (size guard); flag off restores old behavior.Rollout
Consumed by Naseem via a dependency bump to
0.3.0-alpha.31— no app code change (AgentFactory buildsContextManager()with defaults, feature on). Spec in the Naseem repo:docs/superpowers/specs/2026-08-05-ctxmgr-keep-latest-read-design.md.🤖 Generated with Claude Code