From 7ce5ef6704aeef2291b074cd4cc8af290b868699 Mon Sep 17 00:00:00 2001 From: Abdelrahman Elsheikh Date: Tue, 14 Oct 2025 14:30:00 +0300 Subject: [PATCH 1/2] Move deprecated params to kwargs --- aixplain/factories/agent_factory/__init__.py | 15 +++- aixplain/modules/agent/__init__.py | 27 ++++++-- aixplain/modules/team_agent/__init__.py | 73 +++++++++++++++++--- aixplain/modules/team_agent/inspector.py | 2 - 4 files changed, 99 insertions(+), 18 deletions(-) diff --git a/aixplain/factories/agent_factory/__init__.py b/aixplain/factories/agent_factory/__init__.py index 05ef1f2b..ebadcc31 100644 --- a/aixplain/factories/agent_factory/__init__.py +++ b/aixplain/factories/agent_factory/__init__.py @@ -63,7 +63,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", @@ -72,6 +71,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. @@ -85,7 +85,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". @@ -93,6 +92,7 @@ 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 """ @@ -100,6 +100,16 @@ def create( 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: @@ -113,7 +123,6 @@ def create( warnings.warn( "Use `llm` to define the large language model (aixplain.modules.model.llm_model.LLM) to be used as agent. " - "Use `llm_id` to provide the model ID of the large language model to be used as agent. " "Note: In upcoming releases, `llm` will become a required parameter.", UserWarning, ) diff --git a/aixplain/modules/agent/__init__.py b/aixplain/modules/agent/__init__.py index 33d0a7fb..2c373b8d 100644 --- a/aixplain/modules/agent/__init__.py +++ b/aixplain/modules/agent/__init__.py @@ -304,9 +304,8 @@ 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, + **kwargs, ) -> AgentResponse: """Runs an agent call. @@ -322,13 +321,33 @@ 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. + **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.") diff --git a/aixplain/modules/team_agent/__init__.py b/aixplain/modules/team_agent/__init__.py index 58c19cd4..0cb30e79 100644 --- a/aixplain/modules/team_agent/__init__.py +++ b/aixplain/modules/team_agent/__init__.py @@ -26,6 +26,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 @@ -86,14 +87,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 @@ -104,15 +114,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, @@ -122,6 +129,38 @@ def __init__( **additional_info, ) -> None: + # 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 + super().__init__(id, name, description, api_key, supplier, version, cost=cost) self.additional_info = additional_info self.agents = agents @@ -198,9 +237,8 @@ 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, + **kwargs, ) -> AgentResponse: """Runs a team agent call. @@ -216,12 +254,29 @@ 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. 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: diff --git a/aixplain/modules/team_agent/inspector.py b/aixplain/modules/team_agent/inspector.py index d0a10932..0fe311e5 100644 --- a/aixplain/modules/team_agent/inspector.py +++ b/aixplain/modules/team_agent/inspector.py @@ -16,8 +16,6 @@ name="team" agents=agents, description="team description", - llm_id="xyz", - use_mentalist=True, inspectors=[inspector], ) """ From 32af3d4462f15416a3bc021d7f308cf06e142a0d Mon Sep 17 00:00:00 2001 From: Abdelrahman Elsheikh Date: Wed, 15 Oct 2025 16:55:54 +0300 Subject: [PATCH 2/2] TeamAgent .create params deprecation --- .../factories/team_agent_factory/__init__.py | 45 ++++++++++++++++--- .../factories/team_agent_factory/utils.py | 2 +- 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/aixplain/factories/team_agent_factory/__init__.py b/aixplain/factories/team_agent_factory/__init__.py index 60050813..a56489a2 100644 --- a/aixplain/factories/team_agent_factory/__init__.py +++ b/aixplain/factories/team_agent_factory/__init__.py @@ -23,6 +23,7 @@ import json import logging +import warnings from typing import Dict, List, Optional, Text, Union from urllib.parse import urljoin @@ -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, @@ -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( diff --git a/aixplain/factories/team_agent_factory/utils.py b/aixplain/factories/team_agent_factory/utils.py index edbef6d4..c10b6baa 100644 --- a/aixplain/factories/team_agent_factory/utils.py +++ b/aixplain/factories/team_agent_factory/utils.py @@ -349,6 +349,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 )