I'm building a personal assistant that needs to remember user preferences over several weeks. While the handles sessions, I'm not sure how to implement a more permanent memory. Should I be looking at a vector database integration, or does the SDK have a built-in way to "save" and "load" agent state across different days?
3 answers
For long-term memory that spans beyond a single session, you'll want to use the 'context_variables' and an external database. The OpenAI Agents SDK doesn't have a built-in "long-term" persistent store, but it makes it very easy to inject data at the start of a run. You can fetch user preferences from your own DB (like PostgreSQL or MongoDB) and pass them into the Runner.run() call. This ensures the agent has that context immediately. For more complex "memory," you can give the agent a tool that allows it to query a vector store whenever it needs to recall a specific past event.
Can we use the SDK's 'handoff' feature to send data to a "memory manager" agent?
Using the context variables is the cleanest way to keep the prompt size down while still giving the agent what it needs.
Definitely. It prevents the context window from getting cluttered with irrelevant historical data.
That’s actually a very clever architecture! You could have a specialist agent whose only job is to decide what information is "important" enough to be saved permanently. When the main agent identifies a key preference, it hands off to the Memory Agent, which then uses a tool to write that data to your database. This keeps the main agent’s instructions focused on the conversation, while the Memory Agent handles the heavy lifting of data categorization and storage logic.