Skip to content

Commit

Permalink
Handle cases when agent from settings was removed
Browse files Browse the repository at this point in the history
  • Loading branch information
VRSEN committed Apr 11, 2024
1 parent 194c0e6 commit d921b64
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions agency_swarm/agents/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from typing import List

from deepdiff import DeepDiff
from openai import NotFoundError

from agency_swarm.tools import BaseTool, ToolFactory
from agency_swarm.tools import Retrieval, CodeInterpreter
Expand Down Expand Up @@ -147,14 +148,17 @@ def init_oai(self):
# iterate settings and find the assistant with the same name
for assistant_settings in settings:
if assistant_settings['name'] == self.name:
self.assistant = self.client.beta.assistants.retrieve(assistant_settings['id'])
self.id = assistant_settings['id']
# update assistant if parameters are different
if not self._check_parameters(self.assistant.model_dump()):
print("Updating assistant... " + self.name)
self._update_assistant()
self._update_settings()
return self
try:
self.assistant = self.client.beta.assistants.retrieve(assistant_settings['id'])
self.id = assistant_settings['id']
# update assistant if parameters are different
if not self._check_parameters(self.assistant.model_dump()):
print("Updating assistant... " + self.name)
self._update_assistant()
self._update_settings()
return self
except NotFoundError:
continue

# create assistant if settings.json does not exist or assistant with the same name does not exist
self.assistant = self.client.beta.assistants.create(
Expand Down

0 comments on commit d921b64

Please sign in to comment.