From 0219b361b8a9c7dbab12fbfcbe07b8bc8228b274 Mon Sep 17 00:00:00 2001 From: Matthew Zhou Date: Wed, 8 Jan 2025 10:12:11 -1000 Subject: [PATCH] fix: Pass back and parse composio errors correctly (#547) --- letta/functions/helpers.py | 8 +++++--- letta/services/tool_execution_sandbox.py | 3 ++- tests/integration_test_tool_execution_sandbox.py | 8 ++++++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/letta/functions/helpers.py b/letta/functions/helpers.py index fe86ad93..c03751a2 100644 --- a/letta/functions/helpers.py +++ b/letta/functions/helpers.py @@ -16,14 +16,16 @@ def generate_composio_tool_wrapper(action_name: str) -> tuple[str, str]: wrapper_function_str = f""" def {func_name}(**kwargs): - from composio import Action, App, Tag from composio_langchain import ComposioToolSet import os entity_id = os.getenv('{COMPOSIO_ENTITY_ENV_VAR_KEY}', '{DEFAULT_ENTITY_ID}') composio_toolset = ComposioToolSet(entity_id=entity_id) - tool = {tool_instantiation_str} - return tool.func(**kwargs)['data'] + response = composio_toolset.execute_action(action='{action_name}', params=kwargs) + + if response["error"]: + raise RuntimeError(response["error"]) + return response["data"] """ # Compile safety check diff --git a/letta/services/tool_execution_sandbox.py b/letta/services/tool_execution_sandbox.py index 9eca9fcb..93e3e265 100644 --- a/letta/services/tool_execution_sandbox.py +++ b/letta/services/tool_execution_sandbox.py @@ -306,7 +306,8 @@ class ToolExecutionSandbox: if execution.results: func_return, agent_state = self.parse_best_effort(execution.results[0].text) elif execution.error: - logger.error(f"Executing tool {self.tool_name} failed with {execution.error}") + logger.error(f"Executing tool {self.tool_name} raised a {execution.error.name} with message: \n{execution.error.value}") + logger.error(f"Traceback from e2b sandbox: \n{execution.error.traceback}") func_return = get_friendly_error_msg( function_name=self.tool_name, exception_name=execution.error.name, exception_message=execution.error.value ) diff --git a/tests/integration_test_tool_execution_sandbox.py b/tests/integration_test_tool_execution_sandbox.py index 0f34110e..55881f7c 100644 --- a/tests/integration_test_tool_execution_sandbox.py +++ b/tests/integration_test_tool_execution_sandbox.py @@ -382,6 +382,10 @@ def test_local_sandbox_e2e_composio_star_github(mock_e2b_api_key_none, check_com result = ToolExecutionSandbox(composio_github_star_tool.name, {"owner": "letta-ai", "repo": "letta"}, user=test_user).run() assert result.func_return["details"] == "Action executed successfully" + # Missing args causes error + result = ToolExecutionSandbox(composio_github_star_tool.name, {}, user=test_user).run() + assert "Invalid request data provided" in result.func_return + @pytest.mark.local_sandbox def test_local_sandbox_multiple_composio_entities( @@ -624,6 +628,10 @@ def test_e2b_e2e_composio_star_github(check_e2b_key_is_set, check_composio_key_s result = ToolExecutionSandbox(composio_github_star_tool.name, {"owner": "letta-ai", "repo": "letta"}, user=test_user).run() assert result.func_return["details"] == "Action executed successfully" + # Missing args causes error + result = ToolExecutionSandbox(composio_github_star_tool.name, {}, user=test_user).run() + assert "Invalid request data provided" in result.func_return + @pytest.mark.e2b_sandbox def test_e2b_multiple_composio_entities(