Repository navigation
Python: [Bug]: ToolResultCompactionStrategy drops hosted tool results during compaction #9886
Description
Observed Behavior
ToolResultCompactionStrategy replaces an old tool-call group containing a hosted
tool result with [Tool results: no results], even when the tool returned output.
The original call and result messages are then marked excluded, so the output
disappears from the compacted conversation.
For example, a shell_tool_result whose stdout is hello is summarized as having
no results. The same omission affects code_interpreter_tool_result,
image_generation_tool_result, and computer_tool_result.
No exception is raised; the data loss is silent.
Expected Behavior
The compacted summary should preserve the hosted tool result, including useful
text output when available. For the example below, the summary should include
hello (and ideally exit_code: 0) rather than report no results.
Binary payloads such as generated images do not need to be embedded verbatim in
the summary; preserving descriptive metadata is sufficient.
Steps to Reproduce
- Build a message list containing a user message, an assistant
shell_tool_call,
a toolshell_tool_resultwith stdouthello, and an assistantDonemessage. - Run
annotate_message_groups(messages). - Run
ToolResultCompactionStrategy(keep_last_tool_call_groups=0)(messages). - Inspect the messages returned by
included_messages(messages).
Minimal Reproduction
import asyncio
from agent_framework import (
Content,
Message,
ToolResultCompactionStrategy,
annotate_message_groups,
included_messages,
)
async def main() -> None:
messages = [
Message(role="user", contents=["Run a command"]),
Message(
role="assistant",
contents=[
Content.from_shell_tool_call(
call_id="shell-1",
commands=["echo hello"],
)
],
),
Message(
role="tool",
contents=[
Content.from_shell_tool_result(
call_id="shell-1",
outputs=[
Content.from_shell_command_output(
stdout="hello",
exit_code=0,
)
],
)
],
),
Message(role="assistant", contents=["Done"]),
]
annotate_message_groups(messages)
await ToolResultCompactionStrategy(keep_last_tool_call_groups=0)(messages)
for message in included_messages(messages):
if message.text and message.text.startswith("[Tool results:"):
print(message.text)
asyncio.run(main())Observed on commit 4d4e2168f:
[Tool results: no results]
The original call and result messages are also marked as excluded, so their
content is no longer available to the model in the compacted conversation.
Error Messages and Stack Traces
None.
Package Versions
agent-framework-core: 1.24.0 (upstream main at commit 4d4e216)
Python Version
3.12.16
Operating System
Windows 10 Pro 22H2 (19045)
Regression
Unknown.
Additional Context
- The same omission affects
code_interpreter_tool_result,
image_generation_tool_result, andcomputer_tool_result; the function, MCP,
and search branches are already handled. ContextWindowCompactionStrategyuses this strategy internally, so token-budget
compaction and harness agents can hit it.- These content types were added to the tool-call grouping classifier in Python: Fix Foundry reasoning MCP compaction #6907 and
Python: Add native computer use to Responses clients #8751 without matching result extraction. I did not bisect earlier releases, so
Regression is marked Unknown. - No exact duplicate found; related closed issues address different bugs.
- The reproduction needs no model call or external service.
Acknowledgements
- I searched existing issues and did not find a duplicate.
- I personally verified this behavior and the reproduction details are authentic.
- I will wait for explicit maintainer agreement before starting implementation of a non-trivial change.
Metadata
Metadata
Labels
Type
Projects
- StatusShow more project fieldsNo status
Activity
uragoodman commentedon Oct 30, 2026
Proposed minimal fix with regression tests: #9887
github-actions commentedon Oct 30, 2026
🤖 Automated triage reproduction notes (agent-authored — trust but verify)
Agent analysis
The bug reproduces in
python/packages/core/agent_framework/_compaction.py::ToolResultCompactionStrategy.__call__around lines 1977-1998 when a compacted group contains a hosted result type such asshell_tool_result; the extraction loop ignores it and_summary_textemitsno results. Minimal repro: construct matching shell call/result messages with stdouthello, annotate them, runToolResultCompactionStrategy(keep_last_tool_call_groups=0), and assert the included summary containshello.python/packages/core/tests/core/test_compaction.py::test_tool_result_compaction_preserves_shell_result1.24.01.24.0