VRSEN / agency-swarm

The only reliable agent framework built on top of the latest OpenAI Assistants API.
https://vrsen.github.io/agency-swarm/
MIT License
2.06k stars 539 forks source link

When Creating Agency Instance: 404 Error - No assistant found with id "xxx" #44

Closed hicknughes closed 5 months ago

hicknughes commented 5 months ago

I have experimented with many different swarms, which created a lot of assistants in my OpenAI account. I decided to start utilizing the 'id' parameter when creating the agents to avoid creating duplicates. To do so, I pulled up a commonly used swarm, added the 'id=' parameter to each Agent in the swarm. I also manually deleted all the agents from my previous swarms within the OpenAI Assistants interface.

I next tried to run my swarm Colab notebook and whether the Agents were created with an 'id' tag or not, I always encounter a 404 error as follows:


NotFoundError Traceback (most recent call last) in <cell line: 3>() 1 from agency_swarm import Agency 2 ----> 3 agency = Agency([ 4 tool_coordinator, 5 [tool_coordinator, tool_coder],

6 frames /usr/local/lib/python3.10/dist-packages/agency_swarm/agency/agency.py in init(self, agency_chart, shared_instructions) 41 self._parse_agency_chart(agency_chart) 42 self._create_send_message_tools() ---> 43 self._init_agents() 44 self._init_threads() 45

/usr/local/lib/python3.10/dist-packages/agency_swarm/agency/agency.py in _init_agents(self) 379 agent.id = None 380 agent.add_shared_instructions(self.shared_instructions) --> 381 agent.init_oai() 382 383 def _init_threads(self):

/usr/local/lib/python3.10/dist-packages/agency_swarm/agents/agent.py in init_oai(self) 102 for assistant_settings in settings: 103 if assistant_settings['name'] == self.name: --> 104 self.assistant = self.client.beta.assistants.retrieve(assistant_settings['id']) 105 self.id = assistant_settings['id'] 106 # update assistant if parameters are different

/usr/local/lib/python3.10/dist-packages/openai/resources/beta/assistants/assistants.py in retrieve(self, assistant_id, extra_headers, extra_query, extra_body, timeout) 137 """ 138 extra_headers = {"OpenAI-Beta": "assistants=v1", **(extra_headers or {})} --> 139 return self._get( 140 f"/assistants/{assistant_id}", 141 options=make_request_options(

/usr/local/lib/python3.10/dist-packages/openai/_base_client.py in get(self, path, cast_to, options, stream, stream_cls) 1029 # cast is required because mypy complains about returning Any even though 1030 # it understands the type variables -> 1031 return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls)) 1032 1033 @overload

/usr/local/lib/python3.10/dist-packages/openai/_base_client.py in request(self, cast_to, options, remaining_retries, stream, stream_cls) 851 stream_cls: type[_StreamT] | None = None, 852 ) -> ResponseT | _StreamT: --> 853 return self._request( 854 cast_to=cast_to, 855 options=options,

/usr/local/lib/python3.10/dist-packages/openai/_base_client.py in _request(self, cast_to, options, remaining_retries, stream, stream_cls) 928 err.response.read() 929 --> 930 raise self._make_status_error_from_response(err.response) from None 931 932 return self._process_response(

NotFoundError: Error code: 404 - {'error': {'message': "No assistant found with id 'asst_SCFT4gCy2JTX9VysOnxgGD8G'.", 'type': 'invalid_request_error', 'param': None, 'code': None}}

VRSEN commented 5 months ago

Thanks @hicknughes, should be fixed now. Added test as well.

hicknughes commented 5 months ago

I seem to still be getting the same error. It happens after I manually delete (in OpenAI) the assistants belonging to the current swarm being ran. After deletion, I re-run the script to create the agency and get the error:


NotFoundError Traceback (most recent call last) in <cell line: 3>() 1 from agency_swarm import Agency 2 ----> 3 agency = Agency([ 4 tool_coder, 5 [tool_coder, api_researcher]

6 frames /usr/local/lib/python3.10/dist-packages/agency_swarm/agency/agency.py in init(self, agency_chart, shared_instructions, shared_files) 43 self._parse_agency_chart(agency_chart) 44 self._create_send_message_tools() ---> 45 self._init_agents() 46 self._init_threads() 47

/usr/local/lib/python3.10/dist-packages/agency_swarm/agency/agency.py in _init_agents(self) 395 agent.files_folder += self.shared_files 396 --> 397 agent.init_oai() 398 399 def _init_threads(self):

/usr/local/lib/python3.10/dist-packages/agency_swarm/agents/agent.py in init_oai(self) 94 # load assistant from id 95 if self.id: ---> 96 self.assistant = self.client.beta.assistants.retrieve(self.id) 97 self.instructions = self.assistant.instructions 98 self.name = self.assistant.name

/usr/local/lib/python3.10/dist-packages/openai/resources/beta/assistants/assistants.py in retrieve(self, assistant_id, extra_headers, extra_query, extra_body, timeout) 137 """ 138 extra_headers = {"OpenAI-Beta": "assistants=v1", **(extra_headers or {})} --> 139 return self._get( 140 f"/assistants/{assistant_id}", 141 options=make_request_options(

/usr/local/lib/python3.10/dist-packages/openai/_base_client.py in get(self, path, cast_to, options, stream, stream_cls) 1029 # cast is required because mypy complains about returning Any even though 1030 # it understands the type variables -> 1031 return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls)) 1032 1033 @overload

/usr/local/lib/python3.10/dist-packages/openai/_base_client.py in request(self, cast_to, options, remaining_retries, stream, stream_cls) 851 stream_cls: type[_StreamT] | None = None, 852 ) -> ResponseT | _StreamT: --> 853 return self._request( 854 cast_to=cast_to, 855 options=options,

/usr/local/lib/python3.10/dist-packages/openai/_base_client.py in _request(self, cast_to, options, remaining_retries, stream, stream_cls) 928 err.response.read() 929 --> 930 raise self._make_status_error_from_response(err.response) from None 931 932 return self._process_response(

NotFoundError: Error code: 404 - {'error': {'message': "No assistant found with id 'tool_coder'.", 'type': 'invalid_request_error', 'param': None, 'code': None}}

agrimsingh commented 2 months ago

was this issue ever resolved @hicknughes @VRSEN ? i cant even run examples without getting the error "openai.NotFoundError: Error code: 404 - {'error': {'message': "No assistant found with id 'asst_c4kFrflNHuo1uwhtin67iL4l'.", 'type': 'invalid_request_error', 'param': None, 'code': None}}"

hicknughes commented 2 months ago

@agrimsingh It all relies on your settings.json file being correct. If you are keeping track of the assistants listed there then you can avoid creating duplicate assistants by ensuring that file is in your working directory every time you create/update an assistant. If you manually delete an agent, then you have to delete that agent from the settings.json, or at least thats what I would do. Hope that helps