Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
50cc085
Introduction to evolver
thiago-aixplain Feb 28, 2025
819a1d0
Build from yaml
thiago-aixplain Mar 18, 2025
9460356
Addin website-crawl
thiago-aixplain Mar 19, 2025
2b556ab
Adding Wallet on v2
thiago-aixplain Jan 19, 2025
94923d3
Fix syntax of metadata
thiago-aixplain Mar 24, 2025
4e88aeb
Objectify Evolver Response
OsujiCC Mar 28, 2025
9ce6e36
debug agent response on poll
OsujiCC Mar 28, 2025
64b12e7
Fixing test model IDs test
thiago-aixplain Mar 31, 2025
cc28aea
Merge branch 'ENG-1568-evolver' of https://github.com/aixplain/aiXpla…
thiago-aixplain Mar 31, 2025
288f3d9
Update Agent Response to take Evolved Data into account
thiago-aixplain Apr 6, 2025
dad8a4a
Merge branch 'development' into ENG-1568-evolver
thiago-aixplain Apr 6, 2025
90f7e96
Adding current output
thiago-aixplain Apr 7, 2025
70fc987
Merge branch 'ENG-1568-evolver' of https://github.com/aixplain/aiXpla…
thiago-aixplain Apr 7, 2025
f54a8f3
evolver functional test (#483)
OsujiCC Apr 16, 2025
73ca19a
Merge remote-tracking branch 'origin/development' into ENG-1568-evolver
ahmetgunduz Jun 11, 2025
321d7a8
ENG-2225: Evolver Param Edded
ahmetgunduz Jun 12, 2025
6c6ebc6
evolve_type param corrected
ahmetgunduz Jun 13, 2025
87e2e67
Merge branch 'development' into ENG-1568-evolver
ahmetgunduz Jun 19, 2025
2646967
Implement async and sync evolve functionality
ahmetgunduz Jun 20, 2025
838e31d
updates of the coments
ahmetgunduz Jun 24, 2025
32195a9
Add evolver_llm parameter to evolve methods for Agent and TeamAgent
ahmetgunduz Jun 24, 2025
a240788
Changed the names of parameters to be more intuative
ahmetgunduz Jul 18, 2025
8ced6e5
Merge branch 'development' into ENG-1568-evolver
ahmetgunduz Aug 7, 2025
bcfd6c8
fix typo
ahmetgunduz Aug 7, 2025
49446ad
Merge branch 'development' into ENG-1568-evolver
ahmetgunduz Aug 14, 2025
4a2a07e
role to instructions
ahmetgunduz Aug 14, 2025
cc8a31a
updated from dict method
ahmetgunduz Aug 14, 2025
8791cb2
corrected response reading and updated inspectors key
ahmetgunduz Aug 14, 2025
7f2bdf4
added evolve type check
ahmetgunduz Aug 18, 2025
de029bf
added evolve type check
ahmetgunduz Aug 18, 2025
b90648a
Merge branch 'development' into ENG-1568-evolver
ahmetgunduz Aug 26, 2025
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
18 changes: 13 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,26 @@ repos:
pass_filenames: false
types: [python]
always_run: true

- repo: https://github.com/psf/black
rev: 22.10.0
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: v2.0.0 # Use the latest version
rev: v5.0.0 # Use the latest version
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- 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
- --ignore=E402,E501,E203,W503
1 change: 1 addition & 0 deletions aixplain/enums/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@
from .asset_status import AssetStatus
from .index_stores import IndexStores
from .function_type import FunctionType
from .evolve_type import EvolveType
from .code_interpreter import CodeInterpreterModel
6 changes: 6 additions & 0 deletions aixplain/enums/evolve_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from enum import Enum


class EvolveType(str, Enum):
TEAM_TUNING = "team_tuning"
INSTRUCTION_TUNING = "instruction_tuning"
2 changes: 1 addition & 1 deletion aixplain/factories/agent_factory/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def create(

Args:
name (Text): name of the agent
description (Text): description of the agent role.
description (Text): description of the agent instructions.
instructions (Text): instructions of the agent.
llm (Optional[Union[LLM, Text]], optional): LLM instance to use as an object or as an ID.
llm_id (Optional[Text], optional): ID of LLM to use if no LLM instance provided. Defaults to None.
Expand Down
166 changes: 162 additions & 4 deletions aixplain/factories/team_agent_factory/utils.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
__author__ = "lucaspavanelli"

import logging
from typing import Dict, Text, List
from typing import Dict, Text, List, Optional
from urllib.parse import urljoin

import aixplain.utils.config as config
from aixplain.enums.asset_status import AssetStatus
from aixplain.modules.agent import Agent
from aixplain.modules.agent.agent_task import AgentTask
from aixplain.modules.agent.tool.model_tool import ModelTool
from aixplain.modules.team_agent import TeamAgent, InspectorTarget
from aixplain.modules.team_agent.inspector import Inspector
from aixplain.factories.agent_factory import AgentFactory
Expand All @@ -29,7 +31,7 @@ def build_team_agent(payload: Dict, agents: List[Agent] = None, api_key: Text =
- name: Team agent name
- agents: List of agent configurations
- description: Optional description
- role: Optional instructions
- instructions: Optional instructions
- teamId: Optional supplier information
- version: Optional version
- cost: Optional cost information
Expand Down Expand Up @@ -112,7 +114,10 @@ def build_team_agent(payload: Dict, agents: List[Agent] = None, api_key: Text =
# Convert parameters list to dictionary format expected by ModelParameters
params_dict = {}
for param in tool["parameters"]:
params_dict[param["name"]] = {"required": False, "value": param["value"]}
params_dict[param["name"]] = {
"required": False,
"value": param["value"],
}
# Create ModelParameters and set it on the LLM
llm.model_params = ModelParameters(params_dict)

Expand Down Expand Up @@ -158,5 +163,158 @@ def build_team_agent(payload: Dict, agents: List[Agent] = None, api_key: Text =
if task_dependency:
team_agent.agents[idx].tasks[i].dependencies[j] = task_dependency
else:
raise Exception(f"Team Agent Creation Error: Task dependency not found - {dependency}")
team_agent.agents[idx].tasks[i].dependencies[j] = None

return team_agent


def parse_tool_from_yaml(tool: str) -> ModelTool:
from aixplain.enums import Function

tool_name = tool.strip()
if tool_name == "translation":
return ModelTool(
function=Function.TRANSLATION,
)
elif tool_name == "speech-recognition":
return ModelTool(
function=Function.SPEECH_RECOGNITION,
)
elif tool_name == "text-to-speech":
return ModelTool(
function=Function.SPEECH_SYNTHESIS,
)
elif tool_name == "llm":
return ModelTool(function=Function.TEXT_GENERATION)
elif tool_name == "serper_search":
return ModelTool(model="65c51c556eb563350f6e1bb1")
elif tool.strip() == "website_search":
return ModelTool(model="6736411cf127849667606689")
elif tool.strip() == "website_scrape":
return ModelTool(model="6748e4746eb5633559668a15")
elif tool.strip() == "website_crawl":
return ModelTool(model="6748d4cff12784b6014324e2")
else:
raise Exception(f"Tool {tool} in yaml not found.")


import yaml


def is_yaml_formatted(text):
"""
Check if a string is valid YAML format with additional validation.

Args:
text (str): The string to check

Returns:
bool: True if valid YAML, False otherwise
"""
if not text or not isinstance(text, str):
return False

# Strip whitespace
text = text.strip()

# Empty string is valid YAML
if not text:
return True

try:
parsed = yaml.safe_load(text)

# If it's just a plain string without YAML structure,
# we might want to consider it as non-YAML
# This is optional depending on your requirements
if isinstance(parsed, str) and "\n" not in text and ":" not in text:
return False

return True
except yaml.YAMLError:
return False


def build_team_agent_from_yaml(yaml_code: str, llm_id: str, api_key: str, team_id: Optional[str] = None) -> TeamAgent:
import yaml
from aixplain.factories import AgentFactory, TeamAgentFactory

# check if it is a yaml or just as string
if not is_yaml_formatted(yaml_code):
return None
team_config = yaml.safe_load(yaml_code)

agents_data = team_config["agents"]
tasks_data = team_config.get("tasks", [])
system_data = team_config["system"] if "system" in team_config else {"query": "", "name": "Test Team"}
team_name = system_data["name"]

# Create agent mapping by name for easier task assignment
agents_mapping = {}
agent_objs = []

# Parse agents
for agent_entry in agents_data:
agent_name = list(agent_entry.keys())[0]
agent_info = agent_entry[agent_name]
agent_instructions = agent_info["instructions"]
agent_goal = agent_info["goal"]
agent_backstory = agent_info["backstory"]

description = f"You are an expert {agent_instructions}. {agent_backstory} Your primary goal is to {agent_goal}. Use your expertise to ensure the success of your tasks."
agent_name = agent_name.replace("_", " ")
agent_name = f"{agent_name} agent" if not agent_name.endswith(" agent") else agent_name
agent_obj = Agent(
id="",
name=agent_name,
description=description,
instructions=description,
tasks=[], # Tasks will be assigned later
tools=[parse_tool_from_yaml(tool) for tool in agent_info.get("tools", []) if tool != "language_model"],
llmId=llm_id,
)
agents_mapping[agent_name] = agent_obj
agent_objs.append(agent_obj)

# Parse tasks and assign them to the corresponding agents
for task in tasks_data:
for task_name, task_info in task.items():
description = task_info["description"]
expected_output = task_info["expected_output"]
dependencies = task_info.get("dependencies", [])
agent_name = task_info["agent"]
agent_name = agent_name.replace("_", " ")
agent_name = f"{agent_name} agent" if not agent_name.endswith(" agent") else agent_name

task_obj = AgentTask(
name=task_name,
description=description,
expected_output=expected_output,
dependencies=dependencies,
)

# Assign the task to the corresponding agent
if agent_name in agents_mapping:
agent = agents_mapping[agent_name]
agent.tasks.append(task_obj)
else:
raise Exception(f"Agent '{agent_name}' referenced in tasks not found.")

for i, agent in enumerate(agent_objs):
agent_objs[i] = AgentFactory.create(
name=agent.name,
description=agent.instructions,
instructions=agent.instructions,
tools=agent.tools,
llm_id=llm_id,
tasks=agent.tasks,
)

return TeamAgentFactory.create(
name=team_name,
agents=agent_objs,
llm_id=llm_id,
api_key=api_key,
use_mentalist=True,
inspectors=[],
)
Loading