Skip to content

feat: Add tool result pruning compactor - #12243

Merged
sjrl merged 19 commits into
mainfrom
add-tool-result-pruning-compactor
Aug 5, 2026
Merged

feat: Add tool result pruning compactor#12243
sjrl merged 19 commits into
mainfrom
add-tool-result-pruning-compactor

Conversation

@sjrl

@sjrl sjrl commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Related Issues

Proposed Changes:

Added the experimental ToolResultPruningCompactor. It reduces Agent context usage by replacing older, large tool results with short placeholders while preserving tool-call/result structure. Results from a configurable number of recent tool-calling Agent steps remain intact, including parallel results from those steps.

from haystack.hooks.compaction import ContextCompactionHook, ToolResultPruningCompactor

compaction_hook = ContextCompactionHook(
    compactor=ToolResultPruningCompactor(
        min_keep_steps=2,
        min_tokens=200,
    ),
    context_window=400_000,
    compact_at=0.7,
    compact_to=0.4,
)

Also went ahead and added the docs pages for this in the same PR

How did you test it?

New tests

Notes for the reviewer

Checklist

  • I have read the contributors guidelines and the code of conduct.
  • I have updated the related issue with new insights and changes.
  • I have added unit tests and updated the docstrings.
  • I've used one of the conventional commit types for my PR title: fix:, feat:, build:, chore:, ci:, docs:, style:, refactor:, perf:, test: and added ! in case the PR includes breaking changes.
  • I have documented my code.
  • I have added a release note file, following the contributors guidelines.
  • I have run pre-commit hooks and fixed any issue.

@vercel

vercel Bot commented Aug 5, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
haystack-docs Ignored Ignored Preview Aug 5, 2026 2:28pm

Request Review

@github-actions github-actions Bot added topic:tests type:documentation Improvements on the docs labels Aug 5, 2026
@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  haystack/hooks/compaction
  __init__.py
  sliding_window.py
  tool_result_pruning.py
  utils.py
Project Total  

This report was generated by python-coverage-comment-action

@sjrl
sjrl marked this pull request as ready for review August 5, 2026 12:06
@sjrl
sjrl requested a review from a team as a code owner August 5, 2026 12:06
@sjrl
sjrl requested review from anakin87 and removed request for a team August 5, 2026 12:06
Comment thread haystack/hooks/compaction/sliding_window.py

@anakin87 anakin87 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a few minor comments

Comment thread haystack/hooks/compaction/tool_result_pruning.py
Comment thread haystack/hooks/compaction/tool_result_pruning.py Outdated
Comment thread test/hooks/compaction/test_tool_result_pruning.py
Comment thread test/hooks/compaction/test_tool_result_pruning.py
sjrl and others added 2 commits August 5, 2026 16:13
…-result-pruning-compactor.mdx

Co-authored-by: Stefano Fiorucci <stefanofiorucci@gmail.com>
@sjrl
sjrl requested a review from anakin87 August 5, 2026 14:33

@anakin87 anakin87 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

Pushed a fix for my wrong docs suggestion in e7af32f.
For some reason, Docusaurus build was not done in this PR but I saw locally that it broke the build.

@sjrl

sjrl commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

Looks good!

Pushed a fix for my wrong docs suggestion in e7af32f. For some reason, Docusaurus build was not done in this PR but I saw locally that it broke the build.

thanks for the catch! very odd that the docusaurus build was skipped in this PR though ...

@sjrl
sjrl enabled auto-merge (squash) August 5, 2026 14:48
@sjrl
sjrl merged commit ab42444 into main Aug 5, 2026
23 checks passed
@sjrl
sjrl deleted the add-tool-result-pruning-compactor branch August 5, 2026 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic:tests type:documentation Improvements on the docs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants