Skip to content

[BUG] SlidingWindowConversationManager incorrectly returning the error "The tool result was too large" when the window size is less than number of messages. #702

@joychak

Description

@joychak

Checks

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

Strands Version

1.5.0

Python Version

3.13.3

Operating System

macOS 15.6

Installation Method

pip

Steps to Reproduce

from strands import Agent, tool
from strands_tools import calculator
from strands.agent.conversation_manager import SlidingWindowConversationManager

conversation_manager = SlidingWindowConversationManager(
    window_size=5,  # Maximum number of message pairs to keep
)

agent = Agent(
    conversation_manager=conversation_manager,
    tools=[calculator],
    messages=[
        {"role": "user", "content": [{"text": "Hello, my name is Strands!"}]},
        {"role": "assistant", "content": [{"text": "Hi there! How can I help you today?"}]}
    ]
)
agent("What's my name?")
print('\n===================================================')

response = agent.tool.calculator(expression="123 * 456")

# Direct tool call without recording
agent.tool.calculator(expression="765 / 987", record_direct_tool_call=False)

[print(msg) for msg in agent.messages]
  

Expected Behavior

We expect the agent to return the last 5 messages including the successful tool result.

Your name is Strands! Nice to meet you, Strands. Is there anything I can help you with today, perhaps some mathematical calculations or problem-solving?
===================================================
'role': 'assistant', 'content': [{'text': 'Your name is Strands! Nice to meet you, Strands. Is there anything I can help you with today?'}]}
{'role': 'user', 'content': [{'text': 'agent.tool.calculator direct tool call.\nInput parameters: {"expression": "123 * 456"}\n'}]}
{'role': 'assistant', 'content': [{'toolUse': {'toolUseId': 'tooluse_calculator_533712149', 'name': 'calculator', 'input': {'expression': '123 * 456'}}}]}
{'role': 'user', 'content': [{'toolResult': {'status': 'success', 'content': [{'text': 'Result: 56088'}], 'toolUseId': 'tooluse_calculator_533712149'}}]}
{'role': 'assistant', 'content': [{'text': 'agent.tool.calculator was called.'}]}

Actual Behavior

It gives a "The tool result was too large" error for the multiplication operation for the calculator tool.

Your name is Strands! Nice to meet you, Strands. Is there anything I can help you with today, perhaps some mathematical calculations or problem-solving?
===================================================
{'role': 'assistant', 'content': [{'text': 'Your name is Strands! Nice to meet you, Strands. Is there anything I can help you with today, perhaps some mathematical calculations or problem-solving?'}]}
{'role': 'user', 'content': [{'text': 'agent.tool.calculator direct tool call.\nInput parameters: {"expression": "123 * 456"}\n'}]}
{'role': 'assistant', 'content': [{'toolUse': {'toolUseId': 'tooluse_calculator_237287153', 'name': 'calculator', 'input': {'expression': '123 * 456'}}}]}
{'role': 'user', 'content': [{'toolResult': {'status': 'error', 'content': [{'text': 'The tool result was too large!'}], 'toolUseId': 'tooluse_calculator_237287153'}}]}
{'role': 'assistant', 'content': [{'text': 'agent.tool.calculator was called.'}]}

Additional Context

If you set the window_size big enough to accomodate all messages-

conversation_manager = SlidingWindowConversationManager(
    window_size=10,  # Maximum number of message pairs to keep
)

Then, it does produce the correct following output -

Your name is Strands! Nice to meet you, Strands. Is there anything I can help you with today, perhaps some mathematical calculations or problem-solving?
===================================================
{'role': 'user', 'content': [{'text': 'Hello, my name is Strands!'}]}
{'role': 'assistant', 'content': [{'text': 'Hi there! How can I help you today?'}]}
{'role': 'user', 'content': [{'text': "What's my name?"}]}
{'role': 'assistant', 'content': [{'text': 'Your name is Strands! Nice to meet you, Strands. Is there anything I can help you with today?'}]}
{'role': 'user', 'content': [{'text': 'agent.tool.calculator direct tool call.\nInput parameters: {"expression": "123 * 456"}\n'}]}
{'role': 'assistant', 'content': [{'toolUse': {'toolUseId': 'tooluse_calculator_533712149', 'name': 'calculator', 'input': {'expression': '123 * 456'}}}]}
{'role': 'user', 'content': [{'toolResult': {'status': 'success', 'content': [{'text': 'Result: 56088'}], 'toolUseId': 'tooluse_calculator_533712149'}}]}
{'role': 'assistant', 'content': [{'text': 'agent.tool.calculator was called.'}]}

Possible Solution

No response

Related Issues

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions