mirror of
https://github.com/OpenHands/OpenHands.git
synced 2025-12-26 05:48:36 +08:00
Fix issue with "default" in tool schema for gemini-preview (#7964)
This commit is contained in:
parent
6ac23aea80
commit
52d881c98d
@ -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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user