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.05k stars 537 forks source link

Duplicate call_ids Submitted When Calling Tool Multiple Times Causes openai.BadRequestError #151

Open bonk1t opened 5 days ago

bonk1t commented 5 days ago

This issue occurs when the agent is asked to call a tool multiple times in parallel. No similar issues were found on the Internet.

Traceback:

Exception in thread Thread-11 (get_completion_stream):
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/threading.py", line 1045, in _bootstrap_inner
    self.run()
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/threading.py", line 982, in run
    self._target(*self._args, **self._kwargs)
  File "/Users/nick/PycharmProjects/.../venv/lib/python3.11/site-packages/agency_swarm/agency/agency.py", line 196, in get_completion_stream
    next(res)
  File "/Users/nick/PycharmProjects/.../venv/lib/python3.11/site-packages/agency_swarm/threads/thread.py", line 190, in get_completion
    self._submit_tool_outputs(tool_outputs, event_handler)
  File "/Users/nick/PycharmProjects/.../venv/lib/python3.11/site-packages/agency_swarm/threads/thread.py", line 304, in _submit_tool_outputs
    with self.client.beta.threads.runs.submit_tool_outputs_stream(
  File "/Users/nick/PycharmProjects/.../venv/lib/python3.11/site-packages/openai/lib/streaming/_assistants.py", line 444, in __enter__
    self.__stream = self.__api_request()
                    ^^^^^^^^^^^^^^^^^^^^
  File "/Users/nick/PycharmProjects/.../venv/lib/python3.11/site-packages/openai/_base_client.py", line 1240, in post
    return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nick/PycharmProjects/.../venv/lib/python3.11/site-packages/openai/_base_client.py", line 921, in request
    return self._request(
           ^^^^^^^^^^^^^^
  File "/Users/nick/PycharmProjects/.../venv/lib/python3.11/site-packages/openai/_base_client.py", line 1020, in _request
    raise self._make_status_error_from_response(err.response) from None
openai.BadRequestError: Error code: 400 - {'error': {'message': "Duplicate call_ids submitted: ['call_jByezqWjNlzHp9wEs4WGKChN', 'call_jByezqWjNlzHp9wEs4WGKChN', 'call_jByezqWjNlzHp9wEs4WGKChN', 'call_jByezqWjNlzHp9wEs4WGKChN', 'call_jByezqWjNlzHp9wEs4WGKChN', 'call_jByezqWjNlzHp9wEs4WGKChN', 'call_jByezqWjNlzHp9wEs4WGKChN', 'call_jByezqWjNlzHp9wEs4WGKChN', 'call_jByezqWjNlzHp9wEs4WGKChN', 'call_jByezqWjNlzHp9wEs4WGKChN', 'call_jByezqWjNlzHp9wEs4WGKChN']", 'type': 'invalid_request_error', 'param': None, 'code': None}}
VRSEN commented 1 day ago

Rare bug when agent calls the same tool multiple times and the request times out, should be fixed now. Thanks