Skip to content

[BUG] Strands python OpenAI responses calls duplicate tool definitions on each turn #2405

@jbfalken

Description

@jbfalken

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

SDK Language

Python

Strands Version

1.41.0

Language Runtime Version

Python 3.12.9

Operating System

macOS 15.7.2

Installation Method

pip

Steps to Reproduce

Problem Description
While running Strands agents (OpenAI using the Responses API) I noticed unexpected context growth around tool calls. My tool definition size overall is around 10K tokens (I have a lot of tools) and each time Strands would internally call a tool and then make the next call to OpenAI, the context would grow by around 10K more than I was expecting, it was super weird, and I was hitting context limits.

Investigation
OpenAIResponsesModel._format_request shallow-copies params via ** spread,
so request["tools"] and self.config["params"]["tools"] are the SAME list.
.extend() permanently mutates the config, adding a full copy of every tool
spec on every API call.

Testcase
Run this file (you need to put an OPENAI_API_KEY into the env first)
strands_tool_duplication_bug.py
The idea is that it has an "hello world" tool, and we instruct the agent to call that tool 3 times. We override the _format_request method so we have a place to print the tools array before it gets sent to the next OpenAI call by Strands.

Testcase Output on Strands 1.41.0*
$ python3 strands_tool_duplication_bug.py


Running agent...

  API call #1: 2 tools (expect 2): ['web_search', 'hello_world']

Tool #1: hello_world
  API call #2: 3 tools (expect 2): ['web_search', 'hello_world', 'hello_world']

Tool #2: hello_world
  API call #3: 4 tools (expect 2): ['web_search', 'hello_world', 'hello_world', 'hello_world']

Tool #3: hello_world
  API call #4: 5 tools (expect 2): ['web_search', 'hello_world', 'hello_world', 'hello_world', 'hello_world']
Done.
Agent output: Done.

Final config['params']['tools']: 5 entries
Expected: 2 (1 web_search + 1 hello_world)

BUG CONFIRMED: _format_request mutates self.config['params']['tools']
via shared list reference, duplicating all tool specs on every call.

Expected Behavior

I expected that each followup call to OpenAI that was orchestrated by Strands would pass the same (original) list of tools.

Actual Behavior

Each followup call to OpenAI that was orchestrated by Strands is passing an increasingly long list of tools, one extra duplicate of each tool is added each round trip, so it can grow quite large.

Additional Context

I have tried to search for duplicates and be responsible about filing, but this is my first time, so if I missed something, I apologize and go easy on me!

Possible Solution

No response

Related Issues

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions