-
Notifications
You must be signed in to change notification settings - Fork 437
feat(hooks): elide repeated read-only tool results instead of re-sending them #3940
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dwin-gharibi
wants to merge
8
commits into
docker:main
Choose a base branch
from
dwin-gharibi:feat/tool-result-cache
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f3fa133
feat(pkg/runtime/toolexec/dispatcher.go): adding up readonly tool cac…
dwin-gharibi 7f5659f
feat(pkg/hooks/builtins/elide_repeated_tool_results.go): adding up th…
dwin-gharibi eaf0fa3
test(pkg/hooks/builtins/elide_repeated_tool_results_test.go): adding …
dwin-gharibi f35b877
feat(hooks): expose tool category and read-only hint on every tool event
dwin-gharibi 7b2414c
fix(hooks): scope elision to what it can deliver, and drop state when…
dwin-gharibi 8673190
test(hooks): cover the limit_large interaction and context rebuilds
dwin-gharibi aa49c67
docs(hooks): document elide_repeated_tool_results
dwin-gharibi f6a1397
Merge remote-tracking branch 'upstream/main' into feat/tool-result-cache
dwin-gharibi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| #!/usr/bin/env docker-agent run | ||
| # | ||
| # Opt in to eliding repeated read-only tool results. | ||
| # | ||
| # When a read-only tool returns output byte-for-byte identical to what the model | ||
| # already saw for the same arguments in this session, the payload is replaced | ||
| # with a one-line marker instead of being repeated. An agent that re-reads the | ||
| # same file across turns pays for it once. | ||
| # | ||
| # This is NOT a cache: the tool always runs and its fresh output is what gets | ||
| # hashed, so a changed file can never be served stale. The saving is in tokens, | ||
| # not latency. | ||
| # | ||
| # Whether the marker is good for model behaviour is unmeasured — some models may | ||
| # re-request the file anyway — which is why this is opt-in rather than on by | ||
| # default. | ||
|
|
||
| agents: | ||
| root: | ||
| model: claude | ||
| description: An agent that does not pay twice for the same file. | ||
| instruction: | | ||
| You are a helpful assistant working in a code repository. | ||
| Read files as you need them. | ||
| toolsets: | ||
| - type: filesystem | ||
| hooks: | ||
| tool_response_transform: | ||
| - matcher: "*" | ||
| hooks: | ||
| - type: builtin | ||
| command: elide_repeated_tool_results | ||
| # State is per session. Wire all three cleanup legs: session_end frees it, | ||
| # and compaction or a context reset removes the very messages a | ||
| # fingerprint stands for — keeping it would tell the model "nothing has | ||
| # changed" about bytes it can no longer see. | ||
| session_end: | ||
| - type: builtin | ||
| command: elide_repeated_tool_results | ||
| after_compaction: | ||
| - type: builtin | ||
| command: elide_repeated_tool_results | ||
| session_start: | ||
| - type: builtin | ||
| command: elide_repeated_tool_results | ||
|
|
||
| models: | ||
| claude: | ||
| provider: anthropic | ||
| model: claude-sonnet-4-5 |
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[medium]
permission_requesthook does not receivetool_categoryortool_read_onlydespite docs claiming it doesThe PR adds
tool_categoryandtool_read_onlyto thepermission_requestrow of the event-fields table, butrunPermissionRequestHookinpkg/runtime/toolexec/dispatcher.go(line 843) still constructshooks.Inputby hand without those fields:The new
hooksInput()helper (added in this same PR) correctly populates both fields and is already used forpre_tool_use,pre_tool_use_pre_yolo,tool_response_transform, andpost_tool_use— butrunPermissionRequestHookwas not updated to use it. Anypermission_requesthook that readstool_categoryortool_read_onlywill always receive zero values (""andfalse), making the elide builtin's category guard silently ineffective on that event.The fix is to replace the inline
&hooks.Input{...}construction inrunPermissionRequestHookwithc.hooksInput()(optionally extended for any permission-request-specific fields thatNewHooksInputdoes not cover).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please review this feedback @dwin-gharibi
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. Soon