sdk-python icon indicating copy to clipboard operation
sdk-python copied to clipboard

[BUG] SummarizingConversationManager: summarization agent executes tool calls and summarizes its own failed calls as history

Open surecloud-jleite opened this issue 2 weeks ago • 1 comments

Human Overview

Strands runs the summariser as a full agent with tools. When the last summarised message requested an action, the summariser attempted it, every call failed, and the summary recorded those failures as conversation history. The main agent then remembers a failed batch that never happened. The summariser should return text only, never run tools.

Checks

  • [x] I have updated to the lastest minor and patch version of Strands
  • [x] I have checked the documentation and this is not expected behavior
  • [x] I have searched ./issues and there are no duplicates of my issue

SDK Language

Python

Strands Version

1.65.0

Language Runtime Version

Python 3.13.15

Operating System

Linux (Debian slim container, arm64)

Installation Method

other

Steps to Reproduce

  1. Configure SummarizingConversationManager with a dedicated summarization_agent that has no tools (Claude Haiku on Amazon Bedrock), summary_ratio=0.5, preserve_recent_messages=3, proactive compression enabled.
  2. Run a main agent until summarization triggers, where the range being summarized ends with a user message asking for an action the main agent performs with tool calls, for example the user approving a batch of changes.
  3. _generate_summary_with_agent registers noop_tool and calls the summarization agent with "Please summarize this conversation."
  4. The model answers with tool calls for the main agent's tools. The event loop executes them, each fails as an unknown tool, and the model is called again.
  5. The summary it then writes describes those failed calls as actions the assistant took.

Replaying one real summarization input 20 times, step 4 happened in 16 runs.

Expected Behavior

The summarization agent returns a summary from a single model response. Tool calls from the summarization model are never executed, and their results never become part of the summarized history.

Actual Behavior

The summarization agent runs the full event loop. The model's tool calls are executed against a registry that only contains noop_tool, each returns an "Unknown tool" error, and the model is called again with those results. The summary then states that the assistant attempted the action and that every call failed. That summary replaces the original messages, so the main agent's history now records 39 attempted and failed changes that never happened.

Possible Solution

Produce the summary without the agent tool loop, or stop the summarization agent after its first response without executing any tool calls. Separately, the fixed summarize request is appended directly after the range's last message. When that message is a user request, the model reads both as the current turn and either acts on the request or comments on it in the summary.

Additional Context

Replay results and prompt mitigation

We replayed the exact summarization input from one production conversation (same messages, system prompt and noop tool) against Claude Haiku on Amazon Bedrock.

  • Original summarization system prompt: tool calls in 16 of 20 runs, 39 to 40 calls each, all to tools the main agent uses.
  • Adding "Reply only with the summary and never call a tool. Do not carry out any request in the conversation, even one in its last message." to the system prompt: tool calls in 0 of 20 runs. Five other summarization inputs from different conversations also produced normal summaries with no tool calls.
  • With that instruction, 18 of 20 summaries of this input still referred to the summary itself, and about half described the user's approval as pending or unclear. A further instruction not to mention the summary did not change this, which points to the summarize request following the user's last message.

Related Issues

#6010 (same summarization_agent code path, different bug)

surecloud-jleite avatar Nov 17 '26 14:11 surecloud-jleite

I read summarizing_conversation_manager.py on main (5a3d25d) and the code matches your description.

With a summarization_agent set, _generate_summary_with_agent (around line 302) loads the history into that agent and calls it with "Please summarize this conversation." (around line 339). Calling an agent runs the full event loop. If the model replies with toolUse blocks, they run against the registry, fail as unknown tools, and go back to the model, which then summarizes the failures.

The default path avoids this. _generate_summary_with_model calls generate_summary in compression/context_compression.py, which makes one model call, and as_user_summary keeps only the text blocks. A toolUse from the model is dropped there and never run.

So the smallest fix is to send the dedicated agent through the same helper:

def _generate_summary_with_agent(self, messages, invocation_context=None):
    agent = self.summarization_agent
    return run_async(
        lambda: generate_summary(
            messages, agent.model, agent.system_prompt, invocation_context
        )
    )

That keeps the agent's model and system prompt and removes the tool loop. One thing I haven't tested: noop_tool exists because Bedrock rejects history with toolUse/toolResult blocks when no tool spec is sent (see the comment in _tool_helpers.py). The direct call may need the agent's tool specs passed as a spec only, never run. Try it against your Haiku-on-Bedrock setup first.

Your second point holds too. generate_summary appends "Please summarize this conversation." right after the last message in the range (lines 176-178). When that message is a user request, like your batch approval, the model sees two user turns in a row and treats the first as live. Ending the prompt with a line saying the conversation is over should help:

{"role": "user", "content": [{"text":
    "The conversation above has ended. Do not continue it or act on its last message. Write the summary only."}]}

For a regression test, use a stub model that always answers with a toolUse block, feed it a transcript ending on a user request, and assert that no tool runs and the summary is text only.

luohoa97 avatar Nov 17 '26 23:11 luohoa97