diff --git a/ai21/clients/common/agents/agents.py b/ai21/clients/common/agents/agents.py index ffb45150..bc8be40e 100644 --- a/ai21/clients/common/agents/agents.py +++ b/ai21/clients/common/agents/agents.py @@ -13,7 +13,7 @@ ) from ai21.models.agents.agent import ResponseLanguage from ai21.types import NOT_GIVEN, NotGiven -from ai21.utils.typing import remove_not_given +from ai21.utils.typing import remove_not_given, warn_if_tool_resources_in_kwargs class BaseAgents(ABC): @@ -26,19 +26,19 @@ def _create_body( description: str | NotGiven, models: List[str] | NotGiven, tools: List[Dict[str, Any]] | NotGiven, - tool_resources: Dict[str, Any] | NotGiven, requirements: List[AgentRequirement] | NotGiven, budget: BudgetLevel | NotGiven, response_language: ResponseLanguage | NotGiven, **kwargs, ) -> dict: + warn_if_tool_resources_in_kwargs(kwargs) + return remove_not_given( { "name": name, "description": description, "models": models, "tools": tools, - "tool_resources": tool_resources, "requirements": requirements, "budget": budget, "response_language": response_language, @@ -53,20 +53,20 @@ def _modify_body( description: str | NotGiven, models: List[str] | NotGiven, tools: List[Dict[str, Any]] | NotGiven, - tool_resources: Dict[str, Any] | NotGiven, requirements: List[AgentRequirement] | NotGiven, budget: BudgetLevel | NotGiven, visibility: Visibility | NotGiven, response_language: ResponseLanguage | NotGiven, **kwargs, ) -> dict: + warn_if_tool_resources_in_kwargs(kwargs) + return remove_not_given( { "name": name, "description": description, "models": models, "tools": tools, - "tool_resources": tool_resources, "requirements": requirements, "budget": budget, "visibility": visibility, @@ -85,7 +85,6 @@ def create( avatar: str | NotGiven = NOT_GIVEN, models: List[str] | NotGiven = NOT_GIVEN, tools: List[Dict[str, Any]] | NotGiven = NOT_GIVEN, - tool_resources: Dict[str, Any] | NotGiven = NOT_GIVEN, requirements: List[AgentRequirement] | NotGiven = NOT_GIVEN, budget: BudgetLevel | NotGiven = NOT_GIVEN, response_language: ResponseLanguage | NotGiven = NOT_GIVEN, @@ -110,7 +109,6 @@ def modify( description: str | NotGiven = NOT_GIVEN, models: List[str] | NotGiven = NOT_GIVEN, tools: List[Dict[str, Any]] | NotGiven = NOT_GIVEN, - tool_resources: Dict[str, Any] | NotGiven = NOT_GIVEN, requirements: List[AgentRequirement] | NotGiven = NOT_GIVEN, budget: BudgetLevel | NotGiven = NOT_GIVEN, visibility: Visibility | NotGiven = NOT_GIVEN, diff --git a/ai21/clients/common/agents/run.py b/ai21/clients/common/agents/run.py index f0237079..8573cd49 100644 --- a/ai21/clients/common/agents/run.py +++ b/ai21/clients/common/agents/run.py @@ -4,7 +4,7 @@ from ai21.models.agents import Agent from ai21.models.agents.agent import AgentRequirement from ai21.models.maestro.run import Requirement -from ai21.utils.typing import remove_not_given +from ai21.utils.typing import remove_not_given, warn_if_tool_resources_in_kwargs class BaseAgentRun(ABC): @@ -31,11 +31,12 @@ def convert_agent_to_maestro_run_payload( agent: Agent, **kwargs, ): + warn_if_tool_resources_in_kwargs(kwargs) + return remove_not_given( { "models": agent.models, "tools": agent.tools, - "tool_resources": agent.tool_resources, "requirements": self._convert_requirements(agent.requirements), "budget": agent.budget, "response_language": agent.response_language, diff --git a/ai21/clients/common/maestro/run.py b/ai21/clients/common/maestro/run.py index 255987f7..22e18ffe 100644 --- a/ai21/clients/common/maestro/run.py +++ b/ai21/clients/common/maestro/run.py @@ -11,11 +11,10 @@ OutputOptions, Requirement, RunResponse, - ToolResources, ToolDefinition, ) from ai21.types import NOT_GIVEN, NotGiven -from ai21.utils.typing import remove_not_given +from ai21.utils.typing import remove_not_given, warn_if_tool_resources_in_kwargs class BaseMaestroRun(ABC): @@ -27,19 +26,19 @@ def _create_body( input: str | List[MaestroMessage], models: List[str] | NotGiven, tools: List[ToolDefinition] | NotGiven, - tool_resources: ToolResources | NotGiven, requirements: List[Requirement] | NotGiven, budget: Budget | NotGiven, include: List[OutputOptions] | NotGiven, response_language: str | NotGiven, **kwargs, ) -> dict: + warn_if_tool_resources_in_kwargs(kwargs) + return remove_not_given( { "input": input, "models": models, "tools": tools, - "tool_resources": tool_resources, "requirements": requirements, "budget": budget, "include": include, @@ -55,7 +54,6 @@ def create( input: str | List[MaestroMessage], models: List[str] | NotGiven = NOT_GIVEN, tools: List[ToolDefinition] | NotGiven = NOT_GIVEN, - tool_resources: ToolResources | NotGiven = NOT_GIVEN, requirements: List[Requirement] | NotGiven = NOT_GIVEN, budget: Budget | NotGiven = NOT_GIVEN, include: List[OutputOptions] | NotGiven = NOT_GIVEN, @@ -79,7 +77,6 @@ def create_and_poll( input: str | List[MaestroMessage], models: List[str] | NotGiven = NOT_GIVEN, tools: List[ToolDefinition] | NotGiven = NOT_GIVEN, - tool_resources: ToolResources | NotGiven = NOT_GIVEN, requirements: List[Requirement] | NotGiven = NOT_GIVEN, budget: Budget | NotGiven = NOT_GIVEN, include: List[OutputOptions] | NotGiven = NOT_GIVEN, diff --git a/ai21/clients/studio/resources/agents/agents.py b/ai21/clients/studio/resources/agents/agents.py index 4a12088e..9584044b 100644 --- a/ai21/clients/studio/resources/agents/agents.py +++ b/ai21/clients/studio/resources/agents/agents.py @@ -83,7 +83,6 @@ def create( description: str | NotGiven = NOT_GIVEN, models: List[str] | NotGiven = NOT_GIVEN, tools: List[Dict[str, Any]] | NotGiven = NOT_GIVEN, - tool_resources: Dict[str, Any] | NotGiven = NOT_GIVEN, requirements: List[AgentRequirement] | NotGiven = NOT_GIVEN, budget: BudgetLevel | NotGiven = NOT_GIVEN, response_language: ResponseLanguage | NotGiven = NOT_GIVEN, @@ -95,7 +94,6 @@ def create( description=description, models=models, tools=tools, - tool_resources=tool_resources, requirements=requirements, budget=budget, response_language=response_language, @@ -120,7 +118,6 @@ def modify( description: str | NotGiven = NOT_GIVEN, models: List[str] | NotGiven = NOT_GIVEN, tools: List[Dict[str, Any]] | NotGiven = NOT_GIVEN, - tool_resources: Dict[str, Any] | NotGiven = NOT_GIVEN, requirements: List[AgentRequirement] | NotGiven = NOT_GIVEN, budget: BudgetLevel | NotGiven = NOT_GIVEN, visibility: Visibility | NotGiven = NOT_GIVEN, @@ -134,7 +131,6 @@ def modify( response_language=response_language, models=models, tools=tools, - tool_resources=tool_resources, requirements=requirements, budget=budget, visibility=visibility, diff --git a/ai21/clients/studio/resources/agents/async_agents.py b/ai21/clients/studio/resources/agents/async_agents.py index fb6636ba..a382c808 100644 --- a/ai21/clients/studio/resources/agents/async_agents.py +++ b/ai21/clients/studio/resources/agents/async_agents.py @@ -89,7 +89,6 @@ async def create( avatar: str | NotGiven = NOT_GIVEN, models: List[str] | NotGiven = NOT_GIVEN, tools: List[Dict[str, Any]] | NotGiven = NOT_GIVEN, - tool_resources: Dict[str, Any] | NotGiven = NOT_GIVEN, requirements: List[AgentRequirement] | NotGiven = NOT_GIVEN, budget: BudgetLevel | NotGiven = NOT_GIVEN, response_language: ResponseLanguage | NotGiven = NOT_GIVEN, @@ -103,7 +102,6 @@ async def create( avatar=avatar, models=models, tools=tools, - tool_resources=tool_resources, requirements=requirements, budget=budget, response_language=response_language, @@ -128,7 +126,6 @@ async def modify( description: str | NotGiven = NOT_GIVEN, models: List[str] | NotGiven = NOT_GIVEN, tools: List[Dict[str, Any]] | NotGiven = NOT_GIVEN, - tool_resources: Dict[str, Any] | NotGiven = NOT_GIVEN, requirements: List[AgentRequirement] | NotGiven = NOT_GIVEN, budget: BudgetLevel | NotGiven = NOT_GIVEN, visibility: Visibility | NotGiven = NOT_GIVEN, @@ -141,7 +138,6 @@ async def modify( description=description, models=models, tools=tools, - tool_resources=tool_resources, requirements=requirements, budget=budget, visibility=visibility, diff --git a/ai21/clients/studio/resources/maestro/run.py b/ai21/clients/studio/resources/maestro/run.py index d934603a..58b0d6b7 100644 --- a/ai21/clients/studio/resources/maestro/run.py +++ b/ai21/clients/studio/resources/maestro/run.py @@ -15,7 +15,6 @@ Requirement, RunResponse, TERMINATED_RUN_STATUSES, - ToolResources, ToolDefinition, ) from ai21.types import NotGiven, NOT_GIVEN @@ -28,7 +27,6 @@ def create( input: str | List[MaestroMessage], models: List[str] | NotGiven = NOT_GIVEN, tools: List[ToolDefinition] | NotGiven = NOT_GIVEN, - tool_resources: ToolResources | NotGiven = NOT_GIVEN, requirements: List[Requirement] | NotGiven = NOT_GIVEN, budget: Budget | NotGiven = NOT_GIVEN, include: List[OutputOptions] | NotGiven = NOT_GIVEN, @@ -39,7 +37,6 @@ def create( input=input, models=models, tools=tools, - tool_resources=tool_resources, requirements=requirements, budget=budget, include=include, @@ -75,7 +72,6 @@ def create_and_poll( input: str | List[MaestroMessage], models: List[str] | NotGiven = NOT_GIVEN, tools: List[ToolDefinition] | NotGiven = NOT_GIVEN, - tool_resources: ToolResources | NotGiven = NOT_GIVEN, requirements: List[Requirement] | NotGiven = NOT_GIVEN, budget: Budget | NotGiven = NOT_GIVEN, include: List[OutputOptions] | NotGiven = NOT_GIVEN, @@ -88,7 +84,6 @@ def create_and_poll( input=input, models=models, tools=tools, - tool_resources=tool_resources, requirements=requirements, budget=budget, include=include, @@ -108,7 +103,6 @@ async def create( input: str | List[MaestroMessage], models: List[str] | NotGiven = NOT_GIVEN, tools: List[ToolDefinition] | NotGiven = NOT_GIVEN, - tool_resources: ToolResources | NotGiven = NOT_GIVEN, requirements: List[Requirement] | NotGiven = NOT_GIVEN, budget: Budget | NotGiven = NOT_GIVEN, include: List[OutputOptions] | NotGiven = NOT_GIVEN, @@ -119,7 +113,6 @@ async def create( input=input, models=models, tools=tools, - tool_resources=tool_resources, requirements=requirements, budget=budget, include=include, @@ -155,7 +148,6 @@ async def create_and_poll( input: str | List[MaestroMessage], models: List[str] | NotGiven = NOT_GIVEN, tools: List[ToolDefinition] | NotGiven = NOT_GIVEN, - tool_resources: ToolResources | NotGiven = NOT_GIVEN, requirements: List[Requirement] | NotGiven = NOT_GIVEN, budget: Budget | NotGiven = NOT_GIVEN, include: List[OutputOptions] | NotGiven = NOT_GIVEN, @@ -168,7 +160,6 @@ async def create_and_poll( input=input, models=models, tools=tools, - tool_resources=tool_resources, requirements=requirements, budget=budget, include=include, diff --git a/ai21/models/agents/agent.py b/ai21/models/agents/agent.py index a234f77a..9eb10e9f 100644 --- a/ai21/models/agents/agent.py +++ b/ai21/models/agents/agent.py @@ -5,7 +5,7 @@ from typing import List, Optional from ai21.models.ai21_base_model import AI21BaseModel -from ai21.models.maestro.run import Budget, ToolDefinition, ToolResources +from ai21.models.maestro.run import Budget, ToolDefinition class BudgetLevel(str, Enum): @@ -54,7 +54,6 @@ class Agent(AI21BaseModel): user_id: str models: Optional[List[str]] = None tools: Optional[List[ToolDefinition]] = None - tool_resources: Optional[ToolResources] = None requirements: Optional[List[AgentRequirement]] = None budget: Optional[Budget] = None visibility: Optional[Visibility] = None diff --git a/ai21/models/maestro/__init__.py b/ai21/models/maestro/__init__.py index 348000ee..3792a716 100644 --- a/ai21/models/maestro/__init__.py +++ b/ai21/models/maestro/__init__.py @@ -6,7 +6,6 @@ OutputOptions, Requirement, ToolDefinition, - ToolResources, WebSearchResult, HttpTool, McpTool, @@ -23,7 +22,6 @@ "OutputOptions", "Requirement", "ToolDefinition", - "ToolResources", "WebSearchResult", "HttpTool", "McpTool", diff --git a/ai21/models/maestro/run.py b/ai21/models/maestro/run.py index 6cfdab76..32e4fdd0 100644 --- a/ai21/models/maestro/run.py +++ b/ai21/models/maestro/run.py @@ -78,11 +78,6 @@ class WebSearch(TypedDict, total=False): use_cached_pages: Optional[bool] -class ToolResources(TypedDict, total=False): - file_search: Optional[FileSearch] - web_search: Optional[WebSearch] - - ToolDefinition = Annotated[ Union[ HttpTool, diff --git a/ai21/utils/typing.py b/ai21/utils/typing.py index be0244c7..6d47c661 100644 --- a/ai21/utils/typing.py +++ b/ai21/utils/typing.py @@ -1,3 +1,4 @@ +import warnings from typing import Any, Dict, get_args, cast from ai21.types import NotGiven @@ -30,3 +31,13 @@ def extract_type(type_to_extract: Any) -> type: raise RuntimeError( f"Expected type {type_to_extract} to have a type argument at index 0 but it did not" ) from err + + +def warn_if_tool_resources_in_kwargs(kwargs: Dict[str, Any], stacklevel: int = 3) -> None: + if "tool_resources" in kwargs: + warnings.warn( + "The 'tool_resources' parameter is deprecated and will be removed in a future version. " + "Use the 'tools' parameter instead.", + DeprecationWarning, + stacklevel=stacklevel, + )