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
15 changes: 12 additions & 3 deletions aixplain/factories/agent_factory/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ def create(
description: Text,
instructions: Optional[Text] = None,
llm: Optional[Union[LLM, Text]] = None,
llm_id: Optional[Text] = None,
tools: Optional[List[Union[Tool, Model]]] = None,
api_key: Text = config.TEAM_API_KEY,
supplier: Union[Dict, Text, Supplier, int] = "aiXplain",
Expand All @@ -84,6 +83,7 @@ def create(
workflow_tasks: Optional[List[WorkflowTask]] = None,
output_format: Optional[OutputFormat] = None,
expected_output: Optional[Union[BaseModel, Text, dict]] = None,
**kwargs,
) -> Agent:
"""Create a new agent in the platform.

Expand All @@ -97,7 +97,6 @@ def create(
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.
tools (List[Union[Tool, Model]], optional): list of tool for the agent. Defaults to [].
api_key (Text, optional): team/user API key. Defaults to config.TEAM_API_KEY.
supplier (Union[Dict, Text, Supplier, int], optional): owner of the agent. Defaults to "aiXplain".
Expand All @@ -106,14 +105,24 @@ def create(
workflow_tasks (List[WorkflowTask], optional): list of tasks for the agent. Defaults to [].
output_format (OutputFormat, optional): default output format for agent responses. Defaults to OutputFormat.TEXT.
expected_output (Union[BaseModel, Text, dict], optional): expected output. Defaults to None.

**kwargs: Additional keyword arguments.
Returns:
Agent: created Agent
"""
tools = [] if tools is None else list(tools)
workflow_tasks = [] if workflow_tasks is None else list(workflow_tasks)
from aixplain.utils.llm_utils import get_llm_instance

# Extract llm_id from kwargs if present (deprecated parameter)
llm_id = kwargs.get("llm_id", None)
if llm_id is not None:
warnings.warn(
"The 'llm_id' parameter is deprecated and will be removed in a future version. "
"Use the 'llm' parameter instead by passing the LLM ID or LLM instance directly.",
DeprecationWarning,
stacklevel=2,
)

if llm is None and llm_id is not None:
llm = get_llm_instance(llm_id, api_key=api_key, use_cache=True)
elif llm is None:
Expand Down
45 changes: 38 additions & 7 deletions aixplain/factories/team_agent_factory/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

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

Expand Down Expand Up @@ -54,15 +55,12 @@ def create(
cls,
name: Text,
agents: List[Union[Text, Agent]],
llm_id: Text = "669a63646eb56306647e1091",
llm: Optional[Union[LLM, Text]] = None,
supervisor_llm: Optional[Union[LLM, Text]] = None,
mentalist_llm: Optional[Union[LLM, Text]] = None,
description: Text = "",
api_key: Text = config.TEAM_API_KEY,
supplier: Union[Dict, Text, Supplier, int] = "aiXplain",
version: Optional[Text] = None,
use_mentalist: bool = True,
inspectors: List[Inspector] = [],
inspector_targets: List[Union[InspectorTarget, Text]] = [InspectorTarget.STEPS],
instructions: Optional[Text] = None,
Expand All @@ -75,24 +73,57 @@ def create(
Args:
name: The name of the team agent.
agents: A list of agents to be added to the team.
llm_id: The ID of the LLM to be used for the team agent.
llm (Optional[Union[LLM, Text]], optional): The LLM to be used for the team agent.
supervisor_llm (Optional[Union[LLM, Text]], optional): Main supervisor LLM. Defaults to None.
mentalist_llm (Optional[Union[LLM, Text]], optional): LLM for planning. Defaults to None.
description: The description of the team agent to be displayed in the aiXplain platform.
api_key: The API key to be used for the team agent.
supplier: The supplier of the team agent.
version: The version of the team agent.
use_mentalist: Whether to use the mentalist agent.
inspectors: A list of inspectors to be added to the team.
inspector_targets: Which stages to be inspected during an execution of the team agent. (steps, output)
use_mentalist_and_inspector: Whether to use the mentalist and inspector agents. (legacy)
instructions: The instructions to guide the team agent (i.e. appended in the prompt of the team agent).
output_format: The output format to be used for the team agent.
expected_output: The expected output to be used for the team agent.
Returns:
A new team agent instance.

Deprecated Args:
llm_id: DEPRECATED. Use 'llm' parameter instead. The ID of the LLM to be used for the team agent.
mentalist_llm: DEPRECATED. LLM for planning.
use_mentalist: DEPRECATED. Whether to use the mentalist agent.
"""
# Handle deprecated parameters from kwargs
if "llm_id" in kwargs:
llm_id = kwargs.pop("llm_id")
warnings.warn(
"Parameter 'llm_id' is deprecated and will be removed in a future version. "
"Please use 'llm' parameter instead.",
DeprecationWarning,
stacklevel=2,
)
else:
llm_id = "669a63646eb56306647e1091"

if "mentalist_llm" in kwargs:
mentalist_llm = kwargs.pop("mentalist_llm")
warnings.warn(
"Parameter 'mentalist_llm' is deprecated and will be removed in a future version.",
DeprecationWarning,
stacklevel=2,
)
else:
mentalist_llm = None

if "use_mentalist" in kwargs:
use_mentalist = kwargs.pop("use_mentalist")
warnings.warn(
"Parameter 'use_mentalist' is deprecated and will be removed in a future version.",
DeprecationWarning,
stacklevel=2,
)
else:
use_mentalist = True

# legacy params
if "use_mentalist_and_inspector" in kwargs:
logging.warning(
Expand Down
2 changes: 1 addition & 1 deletion aixplain/factories/team_agent_factory/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,6 @@ def build_team_agent_from_yaml(yaml_code: str, llm_id: str, api_key: str, team_i
agents=agent_objs,
llm=llm,
api_key=api_key,
use_mentalist=True,
inspectors=[],
use_mentalist=True, # Deprecated parameter
)
27 changes: 23 additions & 4 deletions aixplain/modules/agent/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,10 +577,9 @@ def run(
content: Optional[Union[Dict[Text, Text], List[Text]]] = None,
max_tokens: int = 4096,
max_iterations: int = 5,
output_format: Optional[OutputFormat] = None,
expected_output: Optional[Union[BaseModel, Text, dict]] = None,
trace_request: bool = False,
progress_verbosity: Optional[str] = "compact",
**kwargs,
) -> AgentResponse:
"""Runs an agent call.

Expand All @@ -596,15 +595,35 @@ def run(
content (Union[Dict[Text, Text], List[Text]], optional): Content inputs to be processed according to the query. Defaults to None.
max_tokens (int, optional): maximum number of tokens which can be generated by the agent. Defaults to 2048.
max_iterations (int, optional): maximum number of iterations between the agent and the tools. Defaults to 10.
output_format (OutputFormat, optional): response format. If not provided, uses the format set during initialization.
expected_output (Union[BaseModel, Text, dict], optional): expected output. Defaults to None.
trace_request (bool, optional): return the request id for tracing the request. Defaults to False.
progress_verbosity (Optional[str], optional): Progress display mode - "full" (detailed), "compact" (brief), or None (no progress). Defaults to "compact".
**kwargs: Additional keyword arguments.

Returns:
Dict: parsed output from model
"""
start = time.time()

# Extract deprecated parameters from kwargs
output_format = kwargs.get("output_format", None)
expected_output = kwargs.get("expected_output", None)

if output_format is not None:
warnings.warn(
"The 'output_format' parameter is deprecated and will be removed in a future version. "
"Set the output format during agent initialization instead.",
DeprecationWarning,
stacklevel=2,
)

if expected_output is not None:
warnings.warn(
"The 'expected_output' parameter is deprecated and will be removed in a future version. "
"Set the expected output during agent initialization instead.",
DeprecationWarning,
stacklevel=2,
)

if session_id is not None and history is not None:
raise ValueError("Provide either `session_id` or `history`, not both.")

Expand Down
73 changes: 64 additions & 9 deletions aixplain/modules/team_agent/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import time
import traceback
import re
import warnings
from enum import Enum
from typing import Dict, List, Text, Optional, Union, Any
from urllib.parse import urljoin
Expand Down Expand Up @@ -90,14 +91,23 @@ class TeamAgent(Model, DeployableMixin[Agent]):
name (Text): Name of the Team Agent
agents (List[Agent]): List of agents that the Team Agent uses.
description (Text, optional): description of the Team Agent. Defaults to "".
llm_id (Text, optional): large language model. Defaults to GPT-4o (6646261c6eb563165658bbb1).
llm (Optional[LLM]): Main LLM instance for the team agent.
supervisor_llm (Optional[LLM]): Supervisor LLM instance for the team agent.
api_key (str): The TEAM API key used for authentication.
supplier (Text): Supplier of the Team Agent.
version (Text): Version of the Team Agent.
cost (Dict, optional): model price. Defaults to None.
use_mentalist (bool): Use Mentalist agent for pre-planning. Defaults to True.
inspectors (List[Inspector]): List of inspectors that the team agent uses.
inspector_targets (List[InspectorTarget]): List of targets where the inspectors are applied. Defaults to [InspectorTarget.STEPS].
status (AssetStatus): Status of the Team Agent. Defaults to DRAFT.
instructions (Optional[Text]): Instructions to guide the team agent.
output_format (OutputFormat): Response format. Defaults to TEXT.
expected_output (Optional[Union[BaseModel, Text, dict]]): Expected output format.

Deprecated Attributes:
llm_id (Text): DEPRECATED. Use 'llm' parameter instead. Large language model ID.
mentalist_llm (Optional[LLM]): DEPRECATED. LLM for planning.
use_mentalist (bool): DEPRECATED. Whether to use Mentalist agent for pre-planning.
"""

is_valid: bool
Expand All @@ -108,15 +118,12 @@ def __init__(
name: Text,
agents: List[Agent] = [],
description: Text = "",
llm_id: Text = "6646261c6eb563165658bbb1",
llm: Optional[LLM] = None,
supervisor_llm: Optional[LLM] = None,
mentalist_llm: Optional[LLM] = None,
api_key: Optional[Text] = config.TEAM_API_KEY,
supplier: Union[Dict, Text, Supplier, int] = "aiXplain",
version: Optional[Text] = None,
cost: Optional[Dict] = None,
use_mentalist: bool = True,
inspectors: List[Inspector] = [],
inspector_targets: List[InspectorTarget] = [InspectorTarget.STEPS],
status: AssetStatus = AssetStatus.DRAFT,
Expand All @@ -127,6 +134,38 @@ def __init__(
) -> None:
"""Initialize a TeamAgent instance.

# Handle deprecated parameters from kwargs
if "llm_id" in additional_info:
llm_id = additional_info.pop("llm_id")
warnings.warn(
"Parameter 'llm_id' is deprecated and will be removed in a future version. "
"Please use 'llm' parameter instead.",
DeprecationWarning,
stacklevel=2,
)
else:
llm_id = "6646261c6eb563165658bbb1"

if "mentalist_llm" in additional_info:
mentalist_llm = additional_info.pop("mentalist_llm")
warnings.warn(
"Parameter 'mentalist_llm' is deprecated and will be removed in a future version.",
DeprecationWarning,
stacklevel=2,
)
else:
mentalist_llm = None

if "use_mentalist" in additional_info:
use_mentalist = additional_info.pop("use_mentalist")
warnings.warn(
"Parameter 'use_mentalist' is deprecated and will be removed in a future version.",
DeprecationWarning,
stacklevel=2,
)
else:
use_mentalist = True

Args:
id (Text): Unique identifier for the team agent.
name (Text): Name of the team agent.
Expand Down Expand Up @@ -515,10 +554,9 @@ def run(
content: Optional[Union[Dict[Text, Text], List[Text]]] = None,
max_tokens: int = 2048,
max_iterations: int = 30,
output_format: Optional[OutputFormat] = None,
expected_output: Optional[Union[BaseModel, Text, dict]] = None,
trace_request: bool = False,
progress_verbosity: Optional[str] = "compact",
**kwargs,
) -> AgentResponse:
"""Runs a team agent call.

Expand All @@ -534,14 +572,31 @@ def run(
content (Union[Dict[Text, Text], List[Text]], optional): Content inputs to be processed according to the query. Defaults to None.
max_tokens (int, optional): maximum number of tokens which can be generated by the agents. Defaults to 2048.
max_iterations (int, optional): maximum number of iterations between the agents. Defaults to 30.
output_format (OutputFormat, optional): response format. If not provided, uses the format set during initialization.
expected_output (Union[BaseModel, Text, dict], optional): expected output. Defaults to None.
trace_request (bool, optional): return the request id for tracing the request. Defaults to False.
progress_verbosity (Optional[str], optional): Progress display mode - "full" (detailed), "compact" (brief), or None (no progress). Defaults to "compact".

Returns:
AgentResponse: parsed output from model
"""
# Handle deprecated parameters from kwargs
output_format = kwargs.pop("output_format", None)
if output_format is not None:
warnings.warn(
"Parameter 'output_format' in run() is deprecated and will be removed in a future version. "
"Please set 'output_format' during TeamAgent initialization instead.",
DeprecationWarning,
stacklevel=2,
)

expected_output = kwargs.pop("expected_output", None)
if expected_output is not None:
warnings.warn(
"Parameter 'expected_output' in run() is deprecated and will be removed in a future version. "
"Please set 'expected_output' during TeamAgent initialization instead.",
DeprecationWarning,
stacklevel=2,
)

start = time.time()
result_data = {}
if session_id is not None and history is not None:
Expand Down
2 changes: 0 additions & 2 deletions aixplain/modules/team_agent/inspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
name="team"
agents=agents,
description="team description",
llm_id="xyz",
use_mentalist=True,
inspectors=[inspector],
)
"""
Expand Down