Skip to content

armgit / letta

Public Imported from GitHub
0

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 Zhou15cc7d1a8f0f
diff --git a/letta/functions/helpers.py b/letta/functions/helpers.py
index 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, 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 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.py
index 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_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(