From 52d881c98d9d66b048ea0a1b2063fd3320c72e67 Mon Sep 17 00:00:00 2001 From: Michael Panchenko <35432522+MischaPanch@users.noreply.github.com> Date: Mon, 21 Apr 2025 21:21:33 +0200 Subject: [PATCH] Fix issue with "default" in tool schema for gemini-preview (#7964) --- .../agenthub/codeact_agent/codeact_agent.py | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/openhands/agenthub/codeact_agent/codeact_agent.py b/openhands/agenthub/codeact_agent/codeact_agent.py index 7ab23e4316..0fbdc78e3d 100644 --- a/openhands/agenthub/codeact_agent/codeact_agent.py +++ b/openhands/agenthub/codeact_agent/codeact_agent.py @@ -1,3 +1,4 @@ +import copy import os from collections import deque @@ -186,8 +187,25 @@ class CodeActAgent(Agent): for tool in self.mcp_tools if tool['function']['name'] not in existing_names ] - params['tools'] += unique_mcp_tools + if self.llm.config.model == 'gemini-2.5-pro-preview-03-25': + logger.info( + f'Removing the default fields from the MCP tools for {self.llm.config.model} ' + "since it doesn't support them and the request would crash." + ) + # prevent mutation of input tools + unique_mcp_tools = copy.deepcopy(unique_mcp_tools) + # Strip off default fields that cause errors with gemini-preview + for tool in unique_mcp_tools: + if 'function' in tool and 'parameters' in tool['function']: + if 'properties' in tool['function']['parameters']: + for prop_name, prop in tool['function']['parameters'][ + 'properties' + ].items(): + if 'default' in prop: + del prop['default'] + + params['tools'] += unique_mcp_tools # log to litellm proxy if possible params['extra_body'] = {'metadata': state.to_llm_metadata(agent_name=self.name)} response = self.llm.completion(**params)