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
35 changes: 10 additions & 25 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,4 @@
repos:
- repo: local
hooks:
- id: pytest-check
name: pytest-check
entry: coverage run --source=. -m pytest tests/unit
language: python
pass_filenames: false
types: [python]
always_run: true

- repo: https://github.com/psf/black
rev: 25.1.0
hooks:
- id: black
language_version: python3
args: # arguments to configure black
- --line-length=128

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0 # Use the latest version
hooks:
Expand All @@ -25,16 +7,19 @@ repos:
- id: check-merge-conflict
- id: check-added-large-files

- repo: https://github.com/pycqa/flake8
rev: 7.2.0
hooks:
- id: flake8
args: # arguments to configure flake8
- --ignore=E402,E501,E203,W503

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.12.12
hooks:
- id: ruff
args: [--fix]
- id: ruff-format

- repo: local
hooks:
- id: pytest-check
name: pytest-check
entry: coverage run --source=. -m pytest tests/unit
language: python
pass_filenames: false
types: [python]
always_run: true
58 changes: 50 additions & 8 deletions tests/functional/team_agent/evolver_test.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
"""Tests for team agent evolver functionality."""

import pytest
from aixplain.enums.function import Function
from aixplain.enums.supplier import Supplier
from aixplain.enums import ResponseStatus
from aixplain.factories.agent_factory import AgentFactory
from aixplain.factories.team_agent_factory import TeamAgentFactory
import time
import uuid


team_dict = {
Expand All @@ -18,7 +21,8 @@
"agent_name": "Text Translation agent",
"llm_id": "6646261c6eb563165658bbb1",
"llm_name": "GPT4o",
"description": "## ROLE\nText Translator\n\n## GOAL\nTranslate the text supplied into the users desired language.\n\n## BACKSTORY\nYou are a text translation agent. You will be provided a text in the source language and expected to translate in the target language.",
"description": "Text Translator",
"instructions": "You are a text translation agent. You will be provided a text in the source language and expected to translate in the target language.",
"tasks": [
{
"name": "Text translation",
Expand All @@ -32,7 +36,8 @@
"agent_name": "Test Speech Synthesis agent",
"llm_id": "6646261c6eb563165658bbb1",
"llm_name": "GPT4o",
"description": "## ROLE\nSpeech Synthesizer\n\n## GOAL\nTranscribe the translated text into speech.\n\n## BACKSTORY\nYou are a speech synthesizing agent. You will be provided a text to synthesize into audio and return the audio link.",
"description": "Speech Synthesizer",
"instructions": "You are a speech synthesizing agent. You will be provided a text to synthesize into audio and return the audio link.",
"tasks": [
{
"name": "Speech synthesis",
Expand All @@ -48,6 +53,7 @@


def parse_tools(tools_info):
"""Parse tool information into AgentFactory model tools."""
tools = []
for tool in tools_info:
function_enum = Function[tool["function"].upper().replace(" ", "_")]
Expand All @@ -57,13 +63,15 @@ def parse_tools(tools_info):


def build_team_agent_from_json(team_config: dict):
"""Build a team agent from JSON configuration."""
agents_data = team_config["agents"]
tasks_data = team_config.get("tasks", [])

agent_objs = []
for agent_entry in agents_data:
agent_name = agent_entry["agent_name"]
agent_description = agent_entry["description"]
agent_instructions = agent_entry["instructions"]
agent_llm_id = agent_entry.get("llm_id", None)

agent_tasks = []
Expand All @@ -88,8 +96,9 @@ def build_team_agent_from_json(team_config: dict):
agent_obj = AgentFactory.create(
name=agent_name.replace("_", " "),
description=agent_description,
instructions=agent_instructions,
tools=agent_tools,
tasks=agent_tasks,
workflow_tasks=agent_tasks,
llm_id=agent_llm_id,
)
agent_objs.append(agent_obj)
Expand All @@ -104,12 +113,40 @@ def build_team_agent_from_json(team_config: dict):
)


@pytest.fixture(scope="function")
def delete_agents_and_team_agents():
"""Fixture to clean up agents and team agents before and after tests."""
from tests.test_deletion_utils import safe_delete_all_agents_and_team_agents

# Clean up before test
safe_delete_all_agents_and_team_agents()

yield True

# Clean up after test
safe_delete_all_agents_and_team_agents()


@pytest.fixture
def team_agent():
return build_team_agent_from_json(team_dict)
def team_agent(delete_agents_and_team_agents):
"""Create a team agent with unique names to avoid conflicts."""
assert delete_agents_and_team_agents
# Create unique names to avoid conflicts
unique_suffix = str(uuid.uuid4())[:8]
team_config = team_dict.copy()
team_config["team_agent_name"] = f"Test Text Speech Team {unique_suffix}"

# Update agent names to be unique as well
agents = team_config["agents"].copy()
for agent in agents:
agent["agent_name"] = f"{agent['agent_name']} {unique_suffix}"
team_config["agents"] = agents

return build_team_agent_from_json(team_config)


def test_evolver_output(team_agent):
"""Test that evolver produces expected output structure."""
response = team_agent.evolve_async()
poll_url = response["url"]
result = team_agent.poll(poll_url)
Expand All @@ -123,12 +160,15 @@ def test_evolver_output(team_agent):
assert "evaluation_report" in result["data"], "Data should contain 'evaluation_report'"
assert "criteria" in result["data"], "Data should contain 'criteria'"
assert "archive" in result["data"], "Data should contain 'archive'"
assert isinstance(result.data["evolved_agent"], type(team_agent)), "Evolved agent should be an instance of the team agent"
assert isinstance(result.data["evolved_agent"], type(team_agent)), (
"Evolved agent should be an instance of the team agent"
)


def test_evolver_with_custom_llm_id(team_agent):
"""Test evolver functionality with custom LLM ID"""
"""Test evolver functionality with custom LLM ID."""
from aixplain.factories.model_factory import ModelFactory

custom_llm_id = "6646261c6eb563165658bbb1" # GPT-4o ID
model = ModelFactory.get(model_id=custom_llm_id)

Expand All @@ -138,4 +178,6 @@ def test_evolver_with_custom_llm_id(team_agent):
assert response is not None
assert response.data["evolved_agent"] is not None
assert response.data["evolved_agent"].llm_id == custom_llm_id
assert isinstance(response.data["evolved_agent"], type(team_agent)), "Evolved agent should be an instance of the team agent"
assert isinstance(response.data["evolved_agent"], type(team_agent)), (
"Evolved agent should be an instance of the team agent"
)