fix: propagate error on tool failure (#2281)
Co-authored-by: Caren Thomas <caren@caren-mac.local>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import asyncio
|
||||
import json
|
||||
import os
|
||||
import threading
|
||||
import time
|
||||
@@ -382,6 +383,39 @@ def test_function_return_limit(client: Union[LocalClient, RESTClient]):
|
||||
client.delete_agent(agent_id=agent.id)
|
||||
|
||||
|
||||
def test_function_always_error(client: Union[LocalClient, RESTClient]):
|
||||
"""Test to see if function that errors works correctly"""
|
||||
|
||||
def always_error():
|
||||
"""
|
||||
Always throw an error.
|
||||
"""
|
||||
return 5/0
|
||||
|
||||
tool = client.create_or_update_tool(func=always_error)
|
||||
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")
|
||||
print(response.messages)
|
||||
|
||||
response_message = None
|
||||
for message in response.messages:
|
||||
if isinstance(message, FunctionReturn):
|
||||
response_message = message
|
||||
break
|
||||
|
||||
assert response_message, "FunctionReturn message not found in response"
|
||||
assert response_message.status == "error"
|
||||
if isinstance(client, RESTClient):
|
||||
assert response_message.function_return == "Error executing function always_error: ZeroDivisionError: division by zero"
|
||||
else:
|
||||
response_json = json.loads(response_message.function_return)
|
||||
assert response_json['status'] == "Failed"
|
||||
assert response_json['message'] == "Error executing function always_error: ZeroDivisionError: division by zero"
|
||||
|
||||
client.delete_agent(agent_id=agent.id)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_send_message_parallel(client: Union[LocalClient, RESTClient], agent: AgentState, request):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user