Skip to content

Python: [Bug]: ToolResultCompactionStrategy drops hosted tool results during compaction #9886

Description

@uragoodman

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

  1. Build a message list containing a user message, an assistant shell_tool_call,
    a tool shell_tool_result with stdout hello, and an assistant Done message.
  2. Run annotate_message_groups(messages).
  3. Run ToolResultCompactionStrategy(keep_last_tool_call_groups=0)(messages).
  4. 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, and computer_tool_result; the function, MCP,
    and search branches are already handled.
  • ContextWindowCompactionStrategy uses 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.

Activity

  1. added
    pythonUsage: [Issues, PRs], Target: Python
    triageUsage: [Issues], Target: All issues that still need to be triaged
    on Oct 30, 2026
  2. uragoodman commented on Oct 30, 2026

    @uragoodman
    Author

    Proposed minimal fix with regression tests: #9887

  3. added
    reproducedUsage: [Issues], Target: all issues that can be reproduced by the triage workflow
    on Oct 30, 2026
  4. github-actions commented on Oct 30, 2026

    @github-actions
    Contributor

    🤖 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 as shell_tool_result; the extraction loop ignores it and _summary_text emits no results. Minimal repro: construct matching shell call/result messages with stdout hello, annotate them, run ToolResultCompactionStrategy(keep_last_tool_call_groups=0), and assert the included summary contains hello.

    • Failing test: python/packages/core/tests/core/test_compaction.py::test_tool_result_compaction_preserves_shell_result
    • Files examined: python/packages/core/agent_framework/_compaction.py, python/packages/core/tests/core/test_compaction.py, python/packages/core/pyproject.toml
    • Tests run: test_tool_result_compaction_preserves_hosted_search_result, test_tool_result_compaction_preserves_tool_results_in_summary, test_tool_result_compaction_preserves_shell_result
    • Reported version: 1.24.0
    • Current version: 1.24.0
  5. added
    agentsUsage: [Issues, PRs], Target: Single agent
    compactionUsage: [Issues, PRs], Target: compaction
    and removed
    triageUsage: [Issues], Target: All issues that still need to be triaged
    on Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

agentsUsage: [Issues, PRs], Target: Single agentcompactionUsage: [Issues, PRs], Target: compactionpythonUsage: [Issues, PRs], Target: PythonreproducedUsage: [Issues], Target: all issues that can be reproduced by the triage workflow

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions