π OpenHands: AI-Driven Development
fix #5111: add FunctionCallNotExistsError to handle cases where tool calling failed (#5113)
Xingyao Wang422104c8778b
diff --git a/openhands/agenthub/codeact_agent/function_calling.py b/openhands/agenthub/codeact_agent/function_calling.pyindex 42ce1f98db..a4ee35ff7b 100644--- a/openhands/agenthub/codeact_agent/function_calling.py+++ b/openhands/agenthub/codeact_agent/function_calling.py@@ -12,6 +12,7 @@ from litellm import (ModelResponse,)+from openhands.core.exceptions import FunctionCallNotExistsErrorfrom openhands.core.logger import openhands_logger as loggerfrom openhands.events.action import (Action,@@ -484,7 +485,9 @@ def response_to_actions(response: ModelResponse) -> list[Action]:elif tool_call.function.name == 'browser':action = BrowseInteractiveAction(browser_actions=arguments['code'])else:- raise RuntimeError(f'Unknown tool call: {tool_call.function.name}')+ raise FunctionCallNotExistsError(+ f'Tool {tool_call.function.name} is not registered. (arguments: {arguments}). Please check the tool name and retry with an existing tool.'+ )# We only add thought to the first actionif i == 0:diff --git a/openhands/controller/agent_controller.py b/openhands/controller/agent_controller.pyindex 9ba8c3d0a1..f9e4a8edb5 100644--- a/openhands/controller/agent_controller.py+++ b/openhands/controller/agent_controller.py@@ -12,6 +12,7 @@ from openhands.controller.state.state import State, TrafficControlStatefrom openhands.controller.stuck import StuckDetectorfrom openhands.core.config import AgentConfig, LLMConfigfrom openhands.core.exceptions import (+ FunctionCallNotExistsError,FunctionCallValidationError,LLMMalformedActionError,LLMNoActionError,@@ -488,6 +489,7 @@ class AgentController:LLMNoActionError,LLMResponseError,FunctionCallValidationError,+ FunctionCallNotExistsError,) as e:self.event_stream.add_event(ErrorObservation(diff --git a/openhands/core/exceptions.py b/openhands/core/exceptions.pyindex 0c0a771191..bf5a29f607 100644--- a/openhands/core/exceptions.py+++ b/openhands/core/exceptions.py@@ -114,3 +114,10 @@ class FunctionCallValidationError(Exception):def __init__(self, message):super().__init__(message)+++class FunctionCallNotExistsError(Exception):+ """Exception raised when an LLM call a tool that is not registered."""++ def __init__(self, message):+ super().__init__(message)