From the course: Build with AI: Building a Project with the ChatGPT API

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Engage in conversations with Threads

Engage in conversations with Threads

- [Narrator] One of the key features of the Open OpenAI Agents SDK is that it allows you to maintain memory across messages. Instead of treating every prompt as a brand new conversation, your AI remembers context and builds on past interactions. Just like a real conversation would. Let's look at how conversation threads work, and how to use them in code by updating our Asteroid Tracking Agent to remember your preferences across turns. I've navigated to the Jupyter Notebook. The first few sections of code you're familiar with. This is where I'm installing the necessary libraries. In this section here, I am pulling my OpenAI API key from my local environment file. Here, I'm throwing an error if the API key cannot be found. This is our Asteroid Tracking Agent from before. Let me quickly walk you through what this code is doing. Lines 8 through 17, this is where I'm setting up the dataclass that contains asteroid data. For example, the name of the asteroid, is it hazardous, the estimated…

Contents