Memory management selects, compresses, stores, and reintroduces information an agent produced in earlier turns or sessions. Its central challenge is choosing relevant information without exhausting the context window; storage capacity is secondary to selection. section 5.2
Memory can be organized along several dimensions:
- Parametric memory resides in model parameters; non-parametric memory is stored externally and selectively injected into context. section 5.6
- Short-term memory curates the current session; long-term memory persists across sessions and can hold semantic facts, episodic experiences, or procedural knowledge. section 5.6
- Memory manages historical information, while state represents the active workflow’s current variables. section 5.2.5
A short-term memory policy might retain the last N user turns verbatim and prepend a running summary of older interactions. This supplies a curated history rather than the full transcript. Effective systems also retrieve selectively, control writes, consolidate memories, and guard against stale, conflicting, or poisoned information. section 5.5.3 section 5.6
Listing 5.4 Illustrative Python excerpt showing a custom session that curates short-term memory before each agent run
from agents import Agent, Runner
from agents.memory.session import SessionABC
from collections import deque
from typing import List
class SummarizingSession(SessionABC): #1
def _materialize(self):
trimmed = self._trim_to_last_turns(list(self._items)) #2
if self._summary:
summary_msg = { #3
"type": "message",
"role": "assistant",
"content": f"Running summary:\n{self._summary}",
}
return [summary_msg] + trimmed
return trimmed
async def _refresh_summary_locked(self): #4
prompt = f"Update the summary with older history:\n{drop_text}"
result = await Runner.run(summarizer, prompt)
self._summary = (result.final_output or "").strip()
agent = Agent(name="Support", model="gpt-5",
instructions="Troubleshoot step-by-step.")
session = SummarizingSession("support_demo", max_turns=6) #5
result = await Runner.run(agent, user_input, session=session) #6
Schematic Python example of a custom OpenAI Agents SDK session that trims history and prepends a running summary before each agent run; the excerpt omits plumbing and is not runnable as printed. section 5.5.3
Pre-built modules can reduce the engineering effort of storage, retrieval, and summarization. Examples include Mem0, Zep, Cognee, Letta, LangMem, and Memori. section 5.2.5





