diff --git a/aider/__init__.py b/aider/__init__.py index fbbf12541b9..40adcbeff8e 100644 --- a/aider/__init__.py +++ b/aider/__init__.py @@ -1,6 +1,6 @@ from packaging import version -__version__ = "0.88.38.dev" +__version__ = "0.88.39.dev" safe_version = __version__ try: diff --git a/aider/coders/agent_coder.py b/aider/coders/agent_coder.py index bba0353e3e0..fe7880e8634 100644 --- a/aider/coders/agent_coder.py +++ b/aider/coders/agent_coder.py @@ -802,7 +802,7 @@ def format_chat_chunks(self): if repetitive_tools: tool_context = self._generate_tool_context(repetitive_tools) if tool_context: - pre_dynamic_blocks.append(tool_context) + post_dynamic_blocks.append(tool_context) if pre_dynamic_blocks: dynamic_message = "\n\n".join(pre_dynamic_blocks) @@ -1717,7 +1717,7 @@ def _get_repetitive_tools(self): history_len = len(self.tool_usage_history) # Not enough history to detect a pattern - if history_len < 2: + if history_len < 5: return set() # Check for similarity-based repetition @@ -1741,12 +1741,12 @@ def _get_repetitive_tools(self): if all(tool.lower() in self.read_tools for tool in all_tools): return set(all_tools) - # Check for any read tool used more than once across rounds + # Check for any read tool used more than 5 times across rounds tool_counts = Counter(all_tools) count_repetitive_tools = { tool for tool, count in tool_counts.items() - if count >= 2 and tool.lower() in self.read_tools + if count >= 5 and tool.lower() in self.read_tools } # Combine both detection methods diff --git a/aider/coders/base_coder.py b/aider/coders/base_coder.py index c55d4ddb69b..910fabef7fc 100755 --- a/aider/coders/base_coder.py +++ b/aider/coders/base_coder.py @@ -2819,6 +2819,9 @@ def add_assistant_reply_to_cur_messages(self): elif self.partial_response_function_call: msg["function_call"] = self.partial_response_function_call + if "reasoning_content" not in msg: + msg["reasoning_content"] = self.partial_response_reasoning_content + # Only add a message if it's not empty. if msg is not None: self.cur_messages.append(msg) diff --git a/aider/helpers/requests.py b/aider/helpers/requests.py index 230f89a1012..857544a0eaa 100644 --- a/aider/helpers/requests.py +++ b/aider/helpers/requests.py @@ -1,6 +1,37 @@ from ..sendchat import ensure_alternating_roles +def add_reasoning_content(messages): + """Add empty reasoning content field to assistant messages if not present. + + Args: + messages: List of message dictionaries + + Returns: + List of messages with reasoning content added to assistant messages + """ + for msg in messages: + if msg.get("role") == "assistant" and "reasoning_content" not in msg: + msg["reasoning_content"] = "" + return messages + + +def remove_empty_tool_calls(messages): + """Remove messages with tool_calls that are empty arrays. + + Args: + messages: List of message dictionaries + + Returns: + List of messages with empty tool_calls messages removed + """ + return [ + msg + for msg in messages + if not (msg.get("role") == "assistant" and "tool_calls" in msg and msg["tool_calls"] == []) + ] + + def thought_signature(model, messages): # Add thought signatures for Vertex AI and Gemini models if model.name.startswith("vertex_ai/") or model.name.startswith("gemini/"): @@ -40,6 +71,7 @@ def thought_signature(model, messages): def model_request_parser(model, messages): messages = thought_signature(model, messages) + messages = remove_empty_tool_calls(messages) messages = ensure_alternating_roles(messages) - + messages = add_reasoning_content(messages) return messages