From 8437e1cdea471cf84b5e066a3ff0e82182c7dc21 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Tue, 2 Dec 2025 10:48:41 +0000 Subject: [PATCH] fix: avoid in-place mutation of cached add_image results MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Address Bugbot feedback: remove format reminder logic for add_image tool to avoid in-place mutation of cached results. The cached dict was being modified when format reminders were appended, causing reminders to accumulate across cache hits. Co-Authored-By: João --- lib/crewai/src/crewai/tools/tool_usage.py | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/lib/crewai/src/crewai/tools/tool_usage.py b/lib/crewai/src/crewai/tools/tool_usage.py index fa95a621c..667303f57 100644 --- a/lib/crewai/src/crewai/tools/tool_usage.py +++ b/lib/crewai/src/crewai/tools/tool_usage.py @@ -320,25 +320,15 @@ class ToolUsage: # For add_image tool, preserve the raw dict result for multimodal handling # The result is a dict like {"role": "user", "content": [...]} that should - # not be stringified + # not be stringified. We skip format reminders for add_image to avoid + # in-place mutation of cached results. add_image_tool = self._i18n.tools("add_image") is_add_image_tool = ( isinstance(add_image_tool, dict) and tool.name.casefold().strip() == add_image_tool.get("name", "").casefold().strip() ) - if is_add_image_tool: - # For add_image, only apply format reminder if needed (skip stringification) - if self._should_remember_format(): - # Append format reminder to the text content if present - format_reminder = self._i18n.slice("tools").format( - tools=self.tools_description, tool_names=self.tools_names - ) - if isinstance(result, dict) and "content" in result: - # Add format reminder as a text item in the content list - if isinstance(result["content"], list): - result["content"].append({"type": "text", "text": format_reminder}) - else: + if not is_add_image_tool: result = self._format_result(result=result, skip_counter=True) data = {