Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions aixplain/modules/agent/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,14 @@ def delete(self) -> None:
headers = {"x-api-key": config.TEAM_API_KEY, "Content-Type": "application/json"}
logging.debug(f"Start service for DELETE Agent - {url} - {headers}")
r = _request_with_retry("delete", url, headers=headers)
logging.debug(f"Result of request for DELETE Agent - {r.status_code}")
if r.status_code != 200:
raise Exception()
except Exception:
try:
response_json = r.json()
message = f"Agent Deletion Error (HTTP {r.status_code}): {response_json.get('message')}."
message = f"Agent Deletion Error (HTTP {r.status_code}): {response_json.get('message', '').strip('{{}}')}."
except ValueError:
message = f"Agent Deletion Error (HTTP {r.status_code}): There was an error in deleting the agent."
logging.error(message)
raise Exception(message)
raise Exception(message)
34 changes: 32 additions & 2 deletions tests/functional/agent/agent_functional_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from dotenv import load_dotenv

load_dotenv()
from aixplain.factories import AgentFactory
from aixplain.factories import AgentFactory, TeamAgentFactory
from aixplain.enums.function import Function
from aixplain.enums.supplier import Supplier

Expand All @@ -36,11 +36,23 @@ def read_data(data_path):
def run_input_map(request):
return request.param

@pytest.fixture(scope="function")
def delete_agents_and_team_agents():
for team_agent in TeamAgentFactory.list()["results"]:
team_agent.delete()
for agent in AgentFactory.list()["results"]:
agent.delete()

yield True

def test_end2end(run_input_map):
for team_agent in TeamAgentFactory.list()["results"]:
team_agent.delete()
for agent in AgentFactory.list()["results"]:
agent.delete()


def test_end2end(run_input_map, delete_agents_and_team_agents):
assert delete_agents_and_team_agents
tools = []
if "model_tools" in run_input_map:
for tool in run_input_map["model_tools"]:
Expand Down Expand Up @@ -88,3 +100,21 @@ def test_fail_non_existent_llm():
tools=[AgentFactory.create_model_tool(function=Function.TRANSLATION)],
)
assert str(exc_info.value) == "Large Language Model with ID 'non_existent_llm' not found."

def test_delete_agent_in_use(delete_agents_and_team_agents):
assert delete_agents_and_team_agents
agent = AgentFactory.create(
name="Test Agent",
description="Test description",
tools=[AgentFactory.create_model_tool(function=Function.TRANSLATION)],
)
TeamAgentFactory.create(
name="Test Team Agent",
agents=[agent],
description="Test description",
use_mentalist_and_inspector=True,
)

with pytest.raises(Exception) as exc_info:
agent.delete()
assert str(exc_info.value) == "Agent Deletion Error (HTTP 403): err.agent_is_in_use."
19 changes: 16 additions & 3 deletions tests/functional/team_agent/team_agent_functional_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,28 @@
def read_data(data_path):
return json.load(open(data_path, "r"))

@pytest.fixture(scope="function")
def delete_agents_and_team_agents():
for team_agent in TeamAgentFactory.list()["results"]:
team_agent.delete()
for agent in AgentFactory.list()["results"]:
agent.delete()

yield True

for team_agent in TeamAgentFactory.list()["results"]:
team_agent.delete()
for agent in AgentFactory.list()["results"]:
agent.delete()


@pytest.fixture(scope="module", params=read_data(RUN_FILE))
def run_input_map(request):
return request.param


def test_end2end(run_input_map):
for agent in AgentFactory.list()["results"]:
agent.delete()
def test_end2end(run_input_map, delete_agents_and_team_agents):
assert delete_agents_and_team_agents

agents = []
for agent in run_input_map["agents"]:
Expand Down