Assistants API Multi Assistant Agentic Workflow

Hey @andres_santos

I was l doing something similar to you and here is what I’ve done to overcome this issue.

You have 1 ProxyAssistant (or whatever you wanna call it) who is responsible for delegating the tasks to other agents/assistants.

When the user q comes in - he calls the method ‘choose_agent’ and with that goes into a state ‘requires_action’

When I call the appropriate agent he selected (lets say he selected SubAssistant), I copy over the messages from ProxyAssistant Thread onto a new thread and this new agent calls a bunch of methods and let’s say that it generates a response. This response is now in the SubAssistant thread.

So I copy over the response from the SubAssistant but I can’t attach it to the thread of the ProxyAssistant because it is locked.

I did the following:

  1. Submit tools - I called the submit_tools endpoint to try and finish the original ProxyAssistant thread
  2. I then take the run_id that ProxyAssistant used to call the agent and I call the ‘cancel’ run endpoint on that run.
  3. I can now add the response from the SubAssistant to the ProxyAssistant thread and initiate a new run.
    NOTE: When cancelling a thread it can go into a state ‘cancelling’ before it is ‘cancelled’. And also, there could be some race condition because I encountered this today:
148 if self.decider_run and self.decider_run.status == "requires_action":
--> 149   self.client.beta.threads.runs.cancel(thread_id=self.decider_thread.id, run_id=self.decider_run.id)
  150   self.logger.info(f"Cancelled a run with ID: {self.decider_run.id}")


BadRequestError: Error code: 400 - {'error': {'message': "Cannot cancel run with status 'cancelled'.", 'type': 'invalid_request_error', 'param': None, 'code': None}}

I ended up doing some hacky while checks to ensure it was cancelled before I proceed

I agree this is not a perfect or even production-quality solution, but does the trick for now. Would love to hear how have you resolved this