diff --git a/agency_swarm/agents/agent.py b/agency_swarm/agents/agent.py index 51368be6..8ac6a77a 100644 --- a/agency_swarm/agents/agent.py +++ b/agency_swarm/agents/agent.py @@ -547,12 +547,35 @@ def _check_parameters(self, assistant_settings, debug=False): print(f"Instructions mismatch: {self.instructions} != {assistant_settings['instructions']}") return False - tools_diff = DeepDiff(self.get_oai_tools(), assistant_settings['tools'], ignore_order=True) + def sort_tool(tool): + return json.dumps(tool, sort_keys=True) + + # Sort the tools in both local and assistant settings + local_tools = sorted(self.get_oai_tools(), key=sort_tool) + assistant_tools = sorted(assistant_settings['tools'], key=sort_tool) + + # Remove 'strict' from all assistant tools if it's set to False + for tool in assistant_tools: + if isinstance(tool, dict) and 'function' in tool: + if 'strict' in tool['function'] and tool['function']['strict'] is False: + tool['function'].pop('strict', None) + + # Ignore specific differences in file_search tool + for tool in assistant_tools: + if isinstance(tool, dict) and tool.get('type') == 'file_search': + if 'file_search' in tool: + tool['file_search'].pop('ranking_options', None) + for tool in local_tools: + if isinstance(tool, dict) and tool.get('type') == 'file_search': + if 'file_search' in tool: + tool['file_search'].pop('ranking_options', None) + + tools_diff = DeepDiff(local_tools, assistant_tools, ignore_order=True) if tools_diff != {}: if debug: print(f"Tools mismatch: {tools_diff}") - print("local tools: ", self.get_oai_tools()) - print("assistant tools: ", assistant_settings['tools']) + print("local tools: ", local_tools) + print("assistant tools: ", assistant_tools) return False if self.temperature != assistant_settings['temperature']: diff --git a/agency_swarm/tools/BaseTool.py b/agency_swarm/tools/BaseTool.py index 9595245a..fd6fd6a6 100644 --- a/agency_swarm/tools/BaseTool.py +++ b/agency_swarm/tools/BaseTool.py @@ -72,9 +72,6 @@ def openai_schema(cls): if "$defs" in schema["parameters"]: for def_ in schema["parameters"]["$defs"].values(): def_["additionalProperties"] = False - else: - if "strict" in schema: - del schema["strict"] return schema diff --git a/agency_swarm/tools/oai/FileSearch.py b/agency_swarm/tools/oai/FileSearch.py index 1b02c5cc..03274d5b 100644 --- a/agency_swarm/tools/oai/FileSearch.py +++ b/agency_swarm/tools/oai/FileSearch.py @@ -1,23 +1,8 @@ -from typing import Optional -from pydantic import BaseModel, field_validator, Field -from typing import Dict, Union, Optional +from openai.types.beta.file_search_tool import FileSearchTool +from openai.types.beta.file_search_tool import FileSearch as OpenAIFileSearch -class FileSearchConfig(BaseModel): - max_num_results: int = Field(50, description="Optional override for the maximum number of results") - ranking_options: Optional[Dict[str, Union[str, float]]] = Field( - {'ranker': 'default_2024_08_21', 'score_threshold': 0.0}, - description="The ranking options for the file search. If not specified, the file search tool will use the auto ranker and a score_threshold of 0." - ) +class FileSearchConfig(OpenAIFileSearch): + pass - @field_validator('max_num_results') - def check_max_num_results(cls, v): - if not 1 <= v <= 50: - raise ValueError('file_search.max_num_results must be between 1 and 50 inclusive') - return v -class FileSearch(BaseModel): - type: str = "file_search" - - file_search: Optional[FileSearchConfig] = None - - class Config: - exclude_none = True +class FileSearch(FileSearchTool): + type: str = "file_search" \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 89458b32..d1a36b45 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -openai==1.41.0 +openai==1.51.2 docstring_parser==0.16 pydantic==2.8.2 datamodel-code-generator==0.25.8 diff --git a/tests/demos/demo_gradio.py b/tests/demos/demo_gradio.py index 4a1cdeaf..cb8d3afd 100644 --- a/tests/demos/demo_gradio.py +++ b/tests/demos/demo_gradio.py @@ -41,7 +41,7 @@ def run(self, **kwargs): agency = Agency([ ceo, [ceo, test_agent, test_agent2], -], shared_instructions="", async_tool_calls=False) +], shared_instructions="", settings_path="./test_settings.json") # agency.demo_gradio()