Fix unsupported MCP tools param (#8610)

This commit is contained in:
Engel Nyst
2025-05-21 16:41:01 +02:00
committed by GitHub
parent 37e9933092
commit c26ef180f2
3 changed files with 46 additions and 23 deletions

View File

@@ -10,6 +10,7 @@ if TYPE_CHECKING:
from openhands.events.action import Action
from openhands.llm.llm import ModelResponse
from openhands.llm.llm_utils import check_tools
import openhands.agenthub.codeact_agent.function_calling as codeact_function_calling
from openhands.agenthub.codeact_agent.tools.bash import create_cmd_run_tool
from openhands.agenthub.codeact_agent.tools.browser import BrowserTool
@@ -185,26 +186,7 @@ class CodeActAgent(Agent):
params: dict = {
'messages': self.llm.format_messages_for_llm(messages),
}
params['tools'] = self.tools
# Special handling for Gemini model which doesn't support default fields
if self.llm.config.model == 'gemini-2.5-pro-preview-03-25':
logger.info(
f'Removing the default fields from tools for {self.llm.config.model} '
"since it doesn't support them and the request would crash."
)
# prevent mutation of input tools
params['tools'] = copy.deepcopy(params['tools'])
# Strip off default fields that cause errors with gemini-preview
for tool in params['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']
# log to litellm proxy if possible
params['tools'] = check_tools(self.tools, self.llm.config)
params['extra_body'] = {'metadata': state.to_llm_metadata(agent_name=self.name)}
response = self.llm.completion(**params)
logger.debug(f'Response from LLM: {response}')