Memory that is never cleared becomes a liability: an old preference, an outdated price, or a fact from a finished project steers the new session wrong. The OpenAI Agents SDK gives you the tools to clear a session outright, and to remove the most recent item when a correction is needed. At the start of a new session, decide what carries over and what does not: keep the durable preferences that are still true, and clear the session history and any facts you know are stale. A fresh session with a stale memory is not fresh.
What you need
- An agent with sessions that persist across turns
- A list of facts you know are stale or finished
- A new session to start after the clear
Step 1: List what is stale before clearing
Write down the facts that are outdated or tied to a finished task. Clearing without a list risks deleting a preference that is still true.
Step 2: Clear the session or remove the stale items
Clear the session for a full fresh start, or pop the recent items that carry the stale facts when only the tail is wrong. Confirm the clear took effect by reading the session back.
Step 3: Start the new session and test for the stale fact
Start the new session and ask a question the stale fact would have answered. The agent should say it does not know or ask, not repeat the old fact.
Worked example: synthetic memory clear
The table below is a synthetic example. It shows the expected result of clearing stale memory; no agent was run.
| Check | Expected | Result |
|---|---|---|
| Stale facts listed first | Yes | Pass |
| Session cleared | Yes | Pass |
| New session repeats the stale fact | No | Pass |
| True preferences still apply | Yes | Pass |
Expected result (UNTESTED). the stale facts are listed and cleared, the new session does not repeat them, and true preferences still apply. This check was not run live; the table shows the expected result for the synthetic example.
Limits
- Clearing a session deletes its history, so keep a copy of anything you may need later.
- A cleared session cannot be undone, so list what is stale before you clear.
- Long-term memory in a vector store is separate from session history, so clearing the session may not clear it.
- A preference that is still true should be re-stated after a full clear.
