From cdc740a10ba7dd428765ce1282d85a4d5f5fa29a Mon Sep 17 00:00:00 2001 From: Xingyao Wang Date: Mon, 18 Nov 2024 16:45:15 -0500 Subject: [PATCH 1/4] fix #5111: add FunctionCallNotExistsError to handle cases where tool calling failed --- openhands/agenthub/codeact_agent/function_calling.py | 5 ++++- openhands/core/exceptions.py | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/openhands/agenthub/codeact_agent/function_calling.py b/openhands/agenthub/codeact_agent/function_calling.py index 42ce1f98db87..a4ee35ff7b59 100644 --- a/openhands/agenthub/codeact_agent/function_calling.py +++ b/openhands/agenthub/codeact_agent/function_calling.py @@ -12,6 +12,7 @@ ModelResponse, ) +from openhands.core.exceptions import FunctionCallNotExistsError from openhands.core.logger import openhands_logger as logger from 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 action if i == 0: diff --git a/openhands/core/exceptions.py b/openhands/core/exceptions.py index 0c0a771191b4..bf5a29f60752 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) From d730d1bb83a19340292465238fd5fab2018fb7ff Mon Sep 17 00:00:00 2001 From: Xingyao Wang Date: Mon, 18 Nov 2024 16:46:31 -0500 Subject: [PATCH 2/4] add FunctionCallNotExistsError to agent controller --- openhands/controller/agent_controller.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/openhands/controller/agent_controller.py b/openhands/controller/agent_controller.py index 9ba8c3d0a154..f9e4a8edb555 100644 --- a/openhands/controller/agent_controller.py +++ b/openhands/controller/agent_controller.py @@ -12,6 +12,7 @@ from openhands.controller.stuck import StuckDetector from openhands.core.config import AgentConfig, LLMConfig from openhands.core.exceptions import ( + FunctionCallNotExistsError, FunctionCallValidationError, LLMMalformedActionError, LLMNoActionError, @@ -488,6 +489,7 @@ async def _step(self) -> None: LLMNoActionError, LLMResponseError, FunctionCallValidationError, + FunctionCallNotExistsError, ) as e: self.event_stream.add_event( ErrorObservation( From b4ad2d1516abd5a1f72ff7a0647216c04dc79678 Mon Sep 17 00:00:00 2001 From: Xingyao Wang Date: Mon, 18 Nov 2024 16:59:52 -0500 Subject: [PATCH 3/4] fix keep runtime alive --- evaluation/swe_bench/run_infer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/evaluation/swe_bench/run_infer.py b/evaluation/swe_bench/run_infer.py index 386c0dd19238..9cb9dd77f498 100644 --- a/evaluation/swe_bench/run_infer.py +++ b/evaluation/swe_bench/run_infer.py @@ -145,7 +145,7 @@ def get_config( platform='linux/amd64', api_key=os.environ.get('ALLHANDS_API_KEY', None), remote_runtime_api_url=os.environ.get('SANDBOX_REMOTE_RUNTIME_API_URL'), - keep_remote_runtime_alive=False, + keep_runtime_alive=False, remote_runtime_init_timeout=3600, ), # do not mount workspace From 78cd09033bdfd63e750461d89450c78517d1c1c3 Mon Sep 17 00:00:00 2001 From: Xingyao Wang Date: Mon, 18 Nov 2024 17:00:05 -0500 Subject: [PATCH 4/4] Revert "fix keep runtime alive" This reverts commit b4ad2d1516abd5a1f72ff7a0647216c04dc79678. --- evaluation/swe_bench/run_infer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/evaluation/swe_bench/run_infer.py b/evaluation/swe_bench/run_infer.py index 9cb9dd77f498..386c0dd19238 100644 --- a/evaluation/swe_bench/run_infer.py +++ b/evaluation/swe_bench/run_infer.py @@ -145,7 +145,7 @@ def get_config( platform='linux/amd64', api_key=os.environ.get('ALLHANDS_API_KEY', None), remote_runtime_api_url=os.environ.get('SANDBOX_REMOTE_RUNTIME_API_URL'), - keep_runtime_alive=False, + keep_remote_runtime_alive=False, remote_runtime_init_timeout=3600, ), # do not mount workspace