Openai assistant api how to maintain context

In the communication with OpenAI’s Assistant API, how does the Assistant API maintain the context of the conversation?

Part of Assistants is the built in storage of a chat history, which is then passed along with the latest user message. This feature is called threads.

It contains the user question, and also the AI response after it is generated. That allows the contextual followup question that otherwise would not be clear.

Threads also contains the messages the AI sent to and received from tools, so, for example, if a web search was done on “fun things in Reno”, that knowlege will also persist until it expires by the conversation growing too long.

The Assistants operates by you placing a user message at the end of a thread. Then starting a “run”. Then retrieving the AI assistant message that has been placed following that as the response.

You can refer to this quick start example in the docs.

You’ll have to use threads!