Assistants API - best way to get the reply to a given user message?

Hey! I’m trying to build a chatbot using the Assistants API, and have a few questions regarding “best practices” of using the API.

  1. What is the intended way to get the assistant’s reply to a given message?

The current flow we have is:

  • Create a new user message in the thread
  • Create a new run for the thread
  • Wait until the run status is “completed”
  • Query the messages in the thread, and filter to the ones where run_id matches the ID of the run we created earlier

This seems to work mostly, but sometimes leads to a case where the run is in a completed state but we get an empty array of messages as the assistant’s response. Is there something wrong with our flow, would there be a better way to get the assistant response?

  1. Is it possible for the assistant to respond to a given user message with more than one assistant message?

Seems like so far the assistant has always responded with just a single Message object to any given user message. Couldn’t find in the documentation anything about this, so is it safe to assume that this is always the case? And if the assistant response would be in multiple parts, this would be reflected in the message.content array, correct? Also appreciated if anyone can give some practical example cases where the message.content array would have multiple items in it :slight_smile:

Your approach seems like it should work; I don’t think I’ve encountered empty messages once Run is Completed, and sometimes even back-to-back messages from the Assistant. Content can contain both text and images.

Thanks, yeah you’re right! The messages array actually wasn’t ever empty for a completed run, there was just an issue in another part of our implementation.

So to be clear, you’re saying that you have seen a case where a single run produces more than one message from the assistant? And not just a message where message.content has more than 1 item?

Glad it was helpful. Yes, if you ask the assistant to do something complex you might have multiple messages from it. I took a break from developing with the API for a few days with hopes OpenAI will make it more fluid so who knows today, but yes last week you could have encountered such a case. Let me know if you have more questions.

1 Like

Hey, bharadwaj here! I’ve just started exploring the assistants api. I couldn’t find a method to create an interactive conversation using this. Is there a way to print the assistant’s response as soon as the user queries?

Hey, as of June 4th, I also want a faster and more fluid conversation type. Here is a topic I created on how I do it right now: