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
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,10 @@ repos:
- 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
13 changes: 13 additions & 0 deletions aixplain/enums/evolve_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,18 @@


class EvolveType(str, Enum):
"""Enumeration of evolution types for team agents.

This enum defines the available evolution strategies that can be applied
to team agents during the evolution process. Each type represents a
different approach to improving agent performance.

Attributes:
TEAM_TUNING (str): Evolution strategy focused on tuning team-level
configurations and interactions between agents.
INSTRUCTION_TUNING (str): Evolution strategy focused on refining
individual agent instructions and prompts.

"""
TEAM_TUNING = "team_tuning"
INSTRUCTION_TUNING = "instruction_tuning"
71 changes: 71 additions & 0 deletions aixplain/modules/team_agent/evolver_response_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@


class EvolverResponseData:
"""Container for team agent evolution response data.

This class encapsulates all the data returned from a team agent evolution
process, including the evolved agent, code, evaluation reports, and
historical archive information.

Attributes:
evolved_agent (TeamAgent): The evolved team agent instance.
current_code (str): The current YAML code representation of the agent.
evaluation_report (str): Report containing evaluation results.
comparison_report (str): Report comparing different agent versions.
criteria (str): Criteria used for evolution evaluation.
archive (List[str]): Historical archive of previous versions.
current_output (str): Current output from the agent.

"""
def __init__(
self,
evolved_agent: "TeamAgent",
Expand All @@ -15,6 +31,19 @@ def __init__(
archive: List[Text],
current_output: Text = "",
) -> None:
"""Initialize the EvolverResponseData instance.

Args:
evolved_agent (TeamAgent): The evolved team agent instance.
current_code (str): The current YAML code representation.
evaluation_report (str): Report containing evaluation results.
comparison_report (str): Report comparing different versions.
criteria (str): Criteria used for evolution evaluation.
archive (List[str]): Historical archive of previous versions.
current_output (str, optional): Current output from the agent.
Defaults to empty string.

"""
self.evolved_agent = evolved_agent
self.current_code = current_code
self.evaluation_report = evaluation_report
Expand All @@ -25,6 +54,17 @@ def __init__(

@classmethod
def from_dict(cls, data: Dict[str, Any], llm_id: Text, api_key: Text) -> "EvolverResponseData":
"""Create an EvolverResponseData instance from a dictionary.

Args:
data (Dict[str, Any]): Dictionary containing the response data.
llm_id (str): The LLM identifier for building the team agent.
api_key (str): API key for accessing the LLM service.

Returns:
EvolverResponseData: A new instance created from the dictionary data.

"""
from aixplain.factories.team_agent_factory.utils import build_team_agent_from_yaml

yaml_code = data.get("current_code", "")
Expand All @@ -40,6 +80,12 @@ def from_dict(cls, data: Dict[str, Any], llm_id: Text, api_key: Text) -> "Evolve
)

def to_dict(self) -> Dict[str, Any]:
"""Convert the EvolverResponseData instance to a dictionary.

Returns:
Dict[str, Any]: Dictionary representation of the instance data.

"""
return {
"evolved_agent": self.evolved_agent,
"current_code": self.current_code,
Expand All @@ -51,15 +97,40 @@ def to_dict(self) -> Dict[str, Any]:
}

def __getitem__(self, key: str) -> Any:
"""Get an attribute value using dictionary-style access.

Args:
key (str): The attribute name to retrieve.

Returns:
Any: The value of the requested attribute, or None if not found.

"""
return getattr(self, key, None)

def __setitem__(self, key: str, value: Any) -> None:
"""Set an attribute value using dictionary-style access.

Args:
key (str): The attribute name to set.
value (Any): The value to assign to the attribute.

Raises:
KeyError: If the key is not a valid attribute of the class.

"""
if hasattr(self, key):
setattr(self, key, value)
else:
raise KeyError(f"{key} is not a valid attribute of {self.__class__.__name__}")

def __repr__(self) -> str:
"""Return a string representation of the EvolverResponseData instance.

Returns:
str: A string representation showing key attributes of the instance.

"""
return (
f"{self.__class__.__name__}("
f"evolved_agent='{self.evolved_agent}', "
Expand Down
27 changes: 27 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
line-length = 120
indent-width = 4
exclude = []

[format]
# Like Black, use double quotes for strings.
quote-style = "double"

# Like Black, indent with spaces, rather than tabs.
indent-style = "space"

# Like Black, respect magic trailing commas.
skip-magic-trailing-comma = false

# Like Black, automatically detect the appropriate line ending.
line-ending = "auto"

[lint]
select = ["D"]
ignore = []
extend-safe-fixes = []

[lint.isort]
known-first-party = ["src"]

[lint.pydocstyle]
convention = "google"