fix: Pass back and parse composio errors correctly (#547)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
)
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user