feat: Add tool result offloading - #11849
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
anakin87
left a comment
There was a problem hiding this comment.
Looks generally good!
I left a few minor comments.
I also played with the demo script, making it more challenging and it seems to work well.
| return None | ||
|
|
||
|
|
||
| def _serialize_offload_strategies(strategies: dict[str | tuple[str, ...], OffloadPolicy]) -> dict[str, Any]: |
There was a problem hiding this comment.
Looking at this part made me think (partly unrelated): do we plan to move human_in_the_loop folder into hooks?
There was a problem hiding this comment.
Yeah I was wondering the same actually. The only downside I see is that it would change the import structure, but that should probably be okay since we do have quite a few other breaking changes already. WDYT?
There was a problem hiding this comment.
If you think it makes more sense, let's do it (in another PR).
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
Related Issues
Proposed Changes:
Added tool result offloading for the
Agentvia the newhaystack.hooks.tool_result_offloadingmodule.ToolResultOffloadHookis anafter_toolhook that writes selected tool results to aToolResultStoreandreplaces them in the conversation with a compact pointer (reference plus a short preview), so the next LLM call
sees a reference instead of the full result. This helps manage the context window and is a step towards letting an
Agent operate on offloaded results with follow-up tools (e.g. a bash tool reading the referenced files).
Configure what gets offloaded, per tool, via
offload_strategies:"*"to anOffloadPolicy. More specific keys win over"*"; a tool with no matching key is not offloaded.AlwaysOffload,NeverOffload, andOffloadOverChars(threshold)(offload when the resultexceeds a character threshold).
OffloadPolicyprotocol (it provides defaultto_dict/from_dict, so astateless policy only needs a
should_offloadmethod).Choose where results are stored:
FileSystemToolResultStorewrites results to the local file system.ToolResultStoreprotocol to target other backends.hook_context.What is offloaded:
before_toolhuman-in-the-loop rejections)are left in context.
A warning is logged when a non-text result has a matching offload policy.
How did you test it?
Added new tests.
Also tested locally with this script
agent_tool_result_offloading_demo.py
Notes for the reviewer
Checklist
fix:,feat:,build:,chore:,ci:,docs:,style:,refactor:,perf:,test:and added!in case the PR includes breaking changes.