feat: add ToolOutputTrimmer for smart context management #2468
+647
−0
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.
Summary
Adds a built-in
ToolOutputTrimmerclass that implementsCallModelInputFilter— a sliding-window filter that surgically trims large tool outputs from older conversation turns while keeping recent turns at full fidelity.Closes #2467. Related: #177, #1494.
What it does
function_call_outputitems in old turns — preserves user/assistant messages andfunction_callitemscall_idmapping for informative summariesrecent_turns >= 1,max_output_chars >= 1,preview_chars >= 0)Usage
Files changed
src/agents/memory/tool_output_trimmer.pyToolOutputTrimmerdataclass (170 lines)src/agents/memory/__init__.pyToolOutputTrimmersrc/agents/__init__.pyToolOutputTrimmertests/memory/test_tool_output_trimmer.pyTest plan
make format— cleanmake lint— cleanmake mypy— 0 new errorsmake tests— 1888 passed, 4 skipped, 0 failures (no regressions)