mirror of
https://github.com/cpacker/MemGPT.git
synced 2025-06-03 04:30:22 +00:00
fix: revert sandbox error message (#904)
This commit is contained in:
parent
ea55cc6bdb
commit
0b34ee468a
@ -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)
|
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":
|
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(
|
||||||
messages = self._handle_function_error_response(error_msg, tool_call_id, function_name, function_response, messages)
|
function_response, tool_call_id, function_name, function_response, messages
|
||||||
|
)
|
||||||
return messages, False, True # force a heartbeat to allow agent to handle error
|
return messages, False, True # force a heartbeat to allow agent to handle error
|
||||||
|
|
||||||
# handle trunction
|
# handle trunction
|
||||||
|
@ -458,16 +458,16 @@ def test_function_return_limit(client: Union[LocalClient, RESTClient]):
|
|||||||
def test_function_always_error(client: Union[LocalClient, RESTClient]):
|
def test_function_always_error(client: Union[LocalClient, RESTClient]):
|
||||||
"""Test to see if function that errors works correctly"""
|
"""Test to see if function that errors works correctly"""
|
||||||
|
|
||||||
def always_error():
|
def testing_method():
|
||||||
"""
|
"""
|
||||||
Always throw an error.
|
Always throw an error.
|
||||||
"""
|
"""
|
||||||
return 5 / 0
|
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])
|
agent = client.create_agent(tool_ids=[tool.id])
|
||||||
# get function response
|
# 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)
|
print(response.messages)
|
||||||
|
|
||||||
response_message = None
|
response_message = None
|
||||||
@ -480,14 +480,11 @@ def test_function_always_error(client: Union[LocalClient, RESTClient]):
|
|||||||
assert response_message.status == "error"
|
assert response_message.status == "error"
|
||||||
|
|
||||||
if isinstance(client, RESTClient):
|
if isinstance(client, RESTClient):
|
||||||
assert (
|
assert response_message.tool_return == "Error executing function testing_method: ZeroDivisionError: division by zero"
|
||||||
response_message.tool_return.startswith("Error calling function always_error")
|
|
||||||
and "ZeroDivisionError" in response_message.tool_return
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
response_json = json.loads(response_message.tool_return)
|
response_json = json.loads(response_message.tool_return)
|
||||||
assert response_json["status"] == "Failed"
|
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)
|
client.delete_agent(agent_id=agent.id)
|
||||||
|
|
||||||
|
@ -410,13 +410,13 @@ def test_function_return_limit(client: LettaSDKClient, agent: AgentState):
|
|||||||
def test_function_always_error(client: LettaSDKClient, agent: AgentState):
|
def test_function_always_error(client: LettaSDKClient, agent: AgentState):
|
||||||
"""Test to see if function that errors works correctly"""
|
"""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
|
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)
|
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=[
|
messages=[
|
||||||
MessageCreate(
|
MessageCreate(
|
||||||
role="user",
|
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
|
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, "ToolReturnMessage message not found in response"
|
||||||
assert response_message.status == "error"
|
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 testing_method: ZeroDivisionError: division by zero"
|
||||||
# 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 "ZeroDivisionError" in response_message.tool_return
|
assert "ZeroDivisionError" in response_message.tool_return
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user