Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.
fix: Pass back and parse composio errors correctly (#547)
Matthew Zhou0219b361b8a9
diff --git a/letta/functions/helpers.py b/letta/functions/helpers.pyindex fe86ad93a..c03751a21 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, Tagfrom composio_langchain import ComposioToolSetimport osentity_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 checkdiff --git a/letta/services/tool_execution_sandbox.py b/letta/services/tool_execution_sandbox.pyindex 9eca9fcbf..93e3e265e 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.pyindex 0f34110e3..55881f7cd 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_comresult = 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_sandboxdef 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_sresult = 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_sandboxdef test_e2b_multiple_composio_entities(