Entity Partitioning Playbook Fresh
Isolate memories across users, agents, apps, and sessions to prevent data leakage.
The Four Scoping Identifiers
| Scope | Purpose | Example |
|---|---|---|
user_id | Individual preferences | "traveler_cam" |
agent_id | Different AI roles | "travel_planner" |
app_id | White-label deployments | "enterprise_portal" |
run_id | Temporary sessions | "support_ticket_9234" |
Why It Matters
Without proper scoping, a recruiter's nut allergy could appear in a traveler's dinner reservation.
Storing Scoped Memories
python
client.add(
messages,
user_id="traveler_cam",
agent_id="travel_planner",
app_id="concierge_app",
run_id="tokyo-2025-weekend"
)Retrieving with Filters
python
user_scope = {
"AND": [
{"user_id": "traveler_cam"},
{"app_id": "concierge_app"}
]
}
results = client.search("dining preferences", filters=user_scope)Cleanup Operations
python
# Delete all memories for an app
client.delete_all(app_id="sports_brand_portal")
# Delete a specific session
client.delete_all(user_id="customer_123", run_id="ticket_456")Production Patterns
- Nightly audits via
get_all()with app scope - Session cleanup after ticket closure using
run_id - Compliance exports with scoped filters
- Consistent naming conventions for identifiers