---
title:
OpenAI Guide to Context Personalization
date:
2026-01-15
draft:
false
---
https://cookbook.openai.com/examples/agents_sdk/context_personalization
OpenAI has released its framework and algorithm for building personalization. The core idea is the separation of data types combined with a specific processing algorithm. This method allows for the accumulation of behavioral data and ensures response consistency across multiple sessions. It’s a valuable example of how to address agent-related challenges.
Here is the summary.
Memory Architecture
- State Components:
- Profile: Structured user data in YAML format.
- Global Notes: Long-term preferences in Markdown format.
- Session Data: Temporary notes and current dialogue history.
- Injection: Relevant parts of the profile and notes are dynamically inserted into the system prompt before each model call.
- Distillation: The agent uses the
save_memory_notetool to automatically capture new facts and preferences during the conversation. - Context Management (Trimming): When the token limit is reached, recent message history is preserved, and important session notes are re-injected into the prompt to maintain coherence.
- Consolidation: At the end of a session, asynchronous data processing is performed: deduplication, conflict resolution, and removal of outdated information.
Principles of Operation
Priority Hierarchy
When data conflicts occur, the following priority order is applied:
- Latest user message.
- Session-specific refinements.
- Global profile settings.
Technical Implementation
- Formatting: Using YAML for profiles and bulleted lists for notes ensures high predictability in model interpretation.
- Tooling: Explicit tool calls for memory recording allow for controlled agent learning.
Evaluation and Safety
Efficiency Metrics
- Extraction Accuracy: Correctness and completeness of capturing new facts (Precision/Recall).
- Injection Quality: Impact of memory on responses without compromising current task performance.
- Consistency: Absence of duplicates and contradictory data after consolidation.
Safety (Guardrails)
- Data Filtering: Excluding personally identifiable information (PII) and passwords from memory.
- Injection Protection: Preventing attempts to alter system instructions via user notes.
- Lifecycle: Mechanisms for automatic expiration and deletion of irrelevant data.