Repository navigation
Python: preserve hosted tool results in ToolResultCompactionStrategy - #9887
Kip (uragoodman) wants to merge 4 commits into
Conversation
Handle shell, code interpreter, image generation, and computer tool results when collapsing old tool-call groups. Preserve status and timeout information, avoid embedding image payloads, and fall back to an explicit "no output returned" instead of "no results". Add regression tests for all four result types, status-only and timeout cases, mixed hosted results, multiple outputs/errors, and payload exclusion. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
@microsoft-github-policy-service agree |
mypy and zuban report "Need type annotation for excluded" at test_compaction.py:2483 because the first assignment is an empty list. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
Updated to address both failing CI jobs, and merged
Locally verified with the CI commands: Workflow runs are back to |
|
Thanks for contributing this work. We are closing this PR while we plan #9886, which remains open. The issue form asks contributors to wait for explicit maintainer agreement before implementing a non-trivial change, and this PR was opened before that agreement. A /plan request is now pending to settle the hosted-result summary contract and scope. Please wait for that agreement before further implementation; the existing work can inform the plan, and a maintainer can coordinate the next step once the direction is settled. This closure is a process/planning decision, not a code-review assessment. |
Motivation & Context
ToolResultCompactionStrategycollapses old tool-call groups into a shortsummary, but its result extraction only handles
function_result,mcp_server_tool_result, andsearch_tool_result. Groups containingshell_tool_result,code_interpreter_tool_result,image_generation_tool_result, orcomputer_tool_resultare still excluded,yet their summary says
[Tool results: no results]. The tool output is silentlylost from the compacted conversation.
This is reachable through
ContextWindowCompactionStrategy, which usesToolResultCompactionStrategyinternally, as well as by callers using thestrategy directly.
Based on upstream main at commit ca65085 (agent-framework-core 1.24.0), merged into the branch after the first CI run.
Fixes #9886
The issue was filed with a complete reproduction. This PR is submitted
concurrently for early direction feedback; happy to adjust the approach or wait
if maintainers prefer to discuss the direction first.
Description & Review Guide
What are the major changes?
ToolResultCompactionStrategy._hosted_tool_result_summaryto render:base64 payloads;
no output returnedfallback instead ofno resultswhenthere is genuinely no result text.
mixed hosted results, multiple outputs/errors, original-message exclusion,
and payload exclusion.
What is the impact of these changes?
Only older tool-call groups containing these hosted result types change. The
function, MCP, and search paths are unchanged. No public API changes. Hosted
image payloads are represented by metadata (
media_type,file_id, orscreenshot) rather than copied into the summary.This PR intentionally scopes itself to
ToolResultCompactionStrategy.SummarizationStrategyhas a related rendering gap and is left for a separatefollow-up.
What do you want reviewers to focus on?
is acceptable, since these content types have no separate tool name.
explicit
no output returnedfallback are the right level of detail.AI Assistance
AI assistance details: an AI coding assistant helped with code-path analysis,
implementation, tests, and drafting this PR description. I reviewed and
verified the change and ran the focused tests below.
Contribution Checklist
pytest tests/core/test_compaction.py -q— 168 passed on Python 3.12.16.ruff check agent_framework/_compaction.py tests/core/test_compaction.pypasses with the repository-pinned Ruff 0.17.1.
ready-for-implementationlabel was present when this PR was opened; it is submitted for early direction feedback.