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

This commit is contained in:
Michael Panchenko 2025-04-21 21:21:33 +02:00 committed by GitHub
parent 6ac23aea80
commit 52d881c98d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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)