Open Assistants API with multi user chat

How can I utilize the Open Assistants API to enable multi-user functionality in the chat conversation, including the involvement of third persons?

I want a third person who also can chat,
means I want it’s look like a group chat

You can look at my implementation for the Teams AI Library:

You basically have to create a virtual Mutex that blocks until the assistant is finished answering each user. It’s not perfect as there’s a small window where two users could get released by the mutex at the same time but it’s the best you can do short of putting a queue between the users and the assistant.

In every message You have a additional key value array for information (I think is a 16 row Array). You can put there for example id of user, another IDs (for example id of team, any other information). The information shoul be resend in AI response, so - You should probabbly know for who AI answering (and for example pin reply to this user).

The tricky part is an assistant for a given conversation can only process a single request at a time so if you try to send two request simultaneously to an assistant the second one will fail. You have to poll (which sucks) and for the assistant to finish processing the current request so you need some way of blocking the other users until the current request finishes. The best way to do that would be to put a message queue between the users and the assistant. I couldn’t do that so I created a virtual mutex. It works

1 Like

can you please give me a brief about this I am not understnd

For each chat room, you will need one thread.

To identify which message is sent by which user, use the metadata.

const metadata = {user_id: 'USER_ID', user_name: 'John Doe'}
const thread_messages = await openai.beta.threads.messages.create(
                role: 'user',
                content: message,

The challenge is, what kind of interaction do you want? One user sends a message and the AI will answer? Or it will be a normal chat which human users are talking and the AI will only be invoked when asked in the conversation.

I would like to create a chat system where users and an AI can engage in a conversation. Additionally, when a third person joins the meeting, they should be able to view the entire chat history as well as receive live messages from both the user and the AI. At the moment, the third person’s role is limited to observing the ongoing conversation in real-time.

Like stevenic mentioned, you need a way to block the other users from engaging until the assistant is done. You can easily do this with web socket.

I do not know why in your current implementation the third person’s role is limited to observing. Use the metadata in the message to set which person is sending the message.

Here is a sample convo of my implementation using socket io.

Thanks for the clear explanation and the fitting response!

I get that using WebSockets can make things happen in real time. But, I’m wondering if the OpenAI assistance API can also help the third person see live updates, or if WebSockets are the only way. I’m a bit short on time; I’ve got the user and AI chatting sorted out. Right now, we just want the third person to watch, and in the next step, I’ll be working on letting them join the chat.

I noticed something in your screenshot and have a question: How does the AI decide when to respond to a question?

If you have the thread id and you do polling, I cannot see why not?

do {

     const thread_messages = await openai.beta.threads.messages.list(

    // process messages

   await sleep(1000)

} while(!isAborted)

Every time a user sends a message, the AI will respond, the rest will wait until the AI finishes.

how you implemented this , using web socket (e.g or connection pooling(getting message list using thread id in some time).

Question 1:

Consider this scenario: I’m employing web polling, making an API call every 2000 milliseconds (2 seconds). Do you think this could potentially burden our server, especially since there are over 1000 users on my web application?

Question 2:

I noticed a chat conversation in your screenshot. Could you share how you implemented this chat feature? Did you use WebSockets ( or web polling?

It is just a simple chat room sample using socket io with Assistants API added.

1 Like

I am not sure about Question 1. It depends on your server. If you want this kind of functionality, web socket is the way to go. But perhaps for the meantime it is probably okay.

As for Question 2, I used socket io. You can also use the generic web socket. I just tweaked some chat room sample for socket io. Here is the repository for the project: Multi-User Chat using Assistants API.

Thanks, @supershaneski , for the support! I’ll check out the GitHub. Much appreciated!