From dc6514876d5c768cedf665faa3ad15d77dcf261c Mon Sep 17 00:00:00 2001 From: Arsenii Shatokhin Date: Thu, 17 Oct 2024 11:06:13 +0400 Subject: [PATCH] Add refresh from id parameter --- agency_swarm/agents/agent.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/agency_swarm/agents/agent.py b/agency_swarm/agents/agent.py index cf94745b..381969f8 100644 --- a/agency_swarm/agents/agent.py +++ b/agency_swarm/agents/agent.py @@ -92,6 +92,7 @@ def __init__( examples: List[ExampleMessage] = None, file_search: FileSearchConfig = None, parallel_tool_calls: bool = True, + refresh_from_id: bool = True, ): """ Initializes an Agent with specified attributes, tools, and OpenAI client. @@ -120,6 +121,7 @@ def __init__( examples (List[Dict], optional): A list of example messages for the agent. Defaults to None. file_search (FileSearchConfig, optional): A dictionary containing the file search tool configuration. Defaults to None. parallel_tool_calls (bool, optional): Whether to enable parallel function calling during tool use. Defaults to True. + refresh_from_id (bool, optional): Whether to load and update the agent from the OpenAI assistant ID when provided. Defaults to True. This constructor sets up the agent with its unique properties, initializes the OpenAI client, reads instructions if provided, and uploads any associated files. """ @@ -151,6 +153,7 @@ def __init__( self.examples = examples self.file_search = file_search self.parallel_tool_calls = parallel_tool_calls + self.refresh_from_id = refresh_from_id self.settings_path = './settings.json' @@ -187,7 +190,7 @@ def init_oai(self): path = self.get_settings_path() # load assistant from id - if self.id: + if self.id and self.refresh_from_id: self.assistant = self.client.beta.assistants.retrieve(self.id) # Assign attributes to self if they are None @@ -211,9 +214,9 @@ def init_oai(self): if tool.type == "retrieval": self.client.beta.assistants.update(self.id, tools=self.get_oai_tools()) - # # update assistant if parameters are different - # if not self._check_parameters(self.assistant.model_dump()): - # self._update_assistant() + # update assistant if parameters are different + if not self._check_parameters(self.assistant.model_dump()): + self._update_assistant() return self