Skip to content

Commit

Permalink
fix #5111: add FunctionCallNotExistsError to handle cases where tool …
Browse files Browse the repository at this point in the history
…calling failed (#5113)
  • Loading branch information
xingyaoww authored Nov 19, 2024
1 parent c75ca7d commit 422104c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
5 changes: 4 additions & 1 deletion openhands/agenthub/codeact_agent/function_calling.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions openhands/controller/agent_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -488,6 +489,7 @@ async def _step(self) -> None:
LLMNoActionError,
LLMResponseError,
FunctionCallValidationError,
FunctionCallNotExistsError,
) as e:
self.event_stream.add_event(
ErrorObservation(
Expand Down
7 changes: 7 additions & 0 deletions openhands/core/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 422104c

Please sign in to comment.