Skip to content

πŸ™Œ OpenHands: AI-Driven Development

Fix issue with "default" in tool schema for gemini-preview (#7964)

Michael Panchenko52d881c98d9d
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)