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: revert sandbox error message (#904)

cthomas7bc5fab2b1de
diff --git a/letta/agent.py b/letta/agent.py
index c84f80e91..bb082fbf7 100644
--- a/letta/agent.py
+++ b/letta/agent.py
@@ -505,8 +505,9 @@ class Agent(BaseAgent):
function_response, sandbox_run_result = self.execute_tool_and_persist_state(function_name, function_args, target_letta_tool)
if sandbox_run_result and sandbox_run_result.status == "error":
- error_msg = f"Error calling function {function_name} with args {function_args}: {sandbox_run_result.stderr}"
- messages = self._handle_function_error_response(error_msg, tool_call_id, function_name, function_response, messages)
+ messages = self._handle_function_error_response(
+ function_response, tool_call_id, function_name, function_response, messages
+ )
return messages, False, True # force a heartbeat to allow agent to handle error
# handle trunction
diff --git a/tests/test_client.py b/tests/test_client.py
index c9cfae4a0..b727f77af 100644
--- a/tests/test_client.py
+++ b/tests/test_client.py
@@ -458,16 +458,16 @@ def test_function_return_limit(client: Union[LocalClient, RESTClient]):
def test_function_always_error(client: Union[LocalClient, RESTClient]):
"""Test to see if function that errors works correctly"""
- def always_error():
+ def testing_method():
"""
Always throw an error.
"""
return 5 / 0
- tool = client.create_or_update_tool(func=always_error)
+ tool = client.create_or_update_tool(func=testing_method)
agent = client.create_agent(tool_ids=[tool.id])
# get function response
- response = client.send_message(agent_id=agent.id, message="call the always_error function", role="user")
+ response = client.send_message(agent_id=agent.id, message="call the testing_method function and tell me the result", role="user")
print(response.messages)
response_message = None
@@ -480,14 +480,11 @@ def test_function_always_error(client: Union[LocalClient, RESTClient]):
assert response_message.status == "error"
if isinstance(client, RESTClient):
- assert (
- response_message.tool_return.startswith("Error calling function always_error")
- and "ZeroDivisionError" in response_message.tool_return
- )
+ assert response_message.tool_return == "Error executing function testing_method: ZeroDivisionError: division by zero"
else:
response_json = json.loads(response_message.tool_return)
assert response_json["status"] == "Failed"
- assert "Error calling function always_error" in response_json["message"] and "ZeroDivisionError" in response_json["message"]
+ assert response_json["message"] == "Error executing function testing_method: ZeroDivisionError: division by zero"
client.delete_agent(agent_id=agent.id)
diff --git a/tests/test_sdk_client.py b/tests/test_sdk_client.py
index f01f431ec..7c2325bd2 100644
--- a/tests/test_sdk_client.py
+++ b/tests/test_sdk_client.py
@@ -410,13 +410,13 @@ def test_function_return_limit(client: LettaSDKClient, agent: AgentState):
def test_function_always_error(client: LettaSDKClient, agent: AgentState):
"""Test to see if function that errors works correctly"""
- def always_error():
+ def testing_method():
"""
- Always throw an error.
+ A method that has test functionalit.
"""
return 5 / 0
- tool = client.tools.upsert_from_function(func=always_error, return_char_limit=1000)
+ tool = client.tools.upsert_from_function(func=testing_method, return_char_limit=1000)
client.agents.tools.attach(agent_id=agent.id, tool_id=tool.id)
@@ -426,10 +426,9 @@ def test_function_always_error(client: LettaSDKClient, agent: AgentState):
messages=[
MessageCreate(
role="user",
- content="call the always_error function",
+ content="call the testing_method function and tell me the result",
),
],
- use_assistant_message=False,
)
response_message = None
@@ -441,10 +440,7 @@ def test_function_always_error(client: LettaSDKClient, agent: AgentState):
assert response_message, "ToolReturnMessage message not found in response"
assert response_message.status == "error"
- # TODO try and get this format back, need to fix e2b return parsing
- # assert response_message.tool_return == "Error executing function always_error: ZeroDivisionError: division by zero"
-
- assert response_message.tool_return.startswith("Error calling function always_error")
+ assert response_message.tool_return == "Error executing function testing_method: ZeroDivisionError: division by zero"
assert "ZeroDivisionError" in response_message.tool_return