Agent Memory for E-commerce Personalization
The Problem: Why Stateless Shopping Fails
Traditional e-commerce AI systems treat every customer session as isolated. When a customer returns:
- Repeated recommendations: AI recommends the same shoes the customer bought 2 weeks ago.
- Lost context: AI doesn't know customer browsed winter coats for 10 minutes, then bounced—showing summer items instead.
- Forgotten preferences: AI doesn't remember customer always buys brand X over brand Y, so it pushes competitors.
- Missed upsells: AI doesn't know which accessories the customer typically pairs with purchases—zero cross-sell suggestions.
- Promotion fatigue: AI shows the same 20% off offer the customer ignored last week.
Result: Lower cart conversion, fewer repeat purchases, customer frustration, and wasted recommendation inventory.
Agent memory solves this by storing customer purchase history, preferences, and behavior patterns—enabling smarter, more personal recommendations.
Memory Types for E-commerce
A shopping agent needs four types of memory:
| Type | Content | Example | Retrieval |
|---|---|---|---|
| Purchase History | Orders, products bought, prices paid, dates | "Bought: Air Jordan 1 Low (2026-04-20), Nike Pro shorts (2026-05-01)" | Temporal (recent-first) + semantic |
| Preference Facts | Favorite brands, price range, size, colors | "Prefers Nike over Adidas", "Size 11 shoe", "Budget max $150" | Keyword (brand, size) |
| Browsing Patterns | Session history, dwell time, categories viewed | "Browsed: winter coats (8 min), boots (5 min), gloves (1 min)" | Temporal + semantic (interest strength) |
| Promotions Seen | Discounts offered, abandoned, accepted | "Shown 20% off Feb 2026 (ignored)", "Accepted SUMMER25 code (used)" | Temporal (recency) |
Retrieval Pattern: "Shopping Context Stack"
When a customer lands or searches, retrieve in order:
1. Purchase history (temporal + semantic)
→ Agent knows what customer owns, avoids recommending dupes, identifies gaps
2. Preference facts (keyword)
→ Agent knows favorite brands, price sensitivity, size/color preferences
3. Browsing patterns from this session (temporal)
→ Agent knows what customer is interested in RIGHT NOW, customizes recs accordingly
4. Browsing patterns from past sessions (semantic)
→ Agent identifies seasonal or category interests, predicts next purchaseExample:
import { Brain } from "brain-ai";
const memory = new Brain({
namespace: "ecommerce",
});
// When customer lands or searches:
async function recommendProducts(customerId: string, currentAction: string) {
// 1. Get purchase history
const purchases = await memory.retrieve({
agentId: `customer-${customerId}`,
query: "What has this customer bought before?",
topK: 10,
filters: { type: "purchase_history" },
});
// 2. Get preference facts
const preferences = await memory.retrieve({
agentId: `customer-${customerId}`,
query: "favorite brand price range size color preferences",
topK: 5,
filters: { type: "preference_fact" },
});
// 3. Get current session browsing
const currentBrowsing = await memory.retrieve({
agentId: `customer-${customerId}`,
query: currentAction, // Semantic: what category is customer looking at now?
topK: 5,
filters: { type: "browsing_pattern", metadata: { session: "current" } },
});
// 4. Get past browsing patterns (seasonal/category trends)
const pastPatterns = await memory.retrieve({
agentId: `customer-${customerId}`,
query: currentAction,
topK: 5,
filters: { type: "browsing_pattern", metadata: { session: "past" } },
});
// Build recommendation context
const context = {
alreadyOwns: purchases.map(p => p.productId),
preferredBrands: preferences.find(p => p.category === "brand")?.content,
priceRange: preferences.find(p => p.category === "price_range")?.content,
currentInterest: currentBrowsing,
seasonalTrends: pastPatterns,
};
// Agent generates personalized recommendations
const recommendations = await recommendationEngine.generate(context);
// Log this browsing session
await memory.store({
agentId: `customer-${customerId}`,
content: `Session browsing: ${currentAction}`,
type: "browsing_pattern",
metadata: {
customerId,
timestamp: new Date().toISOString(),
session: "current",
action: currentAction,
dwell_seconds: getCurrentDwellTime(),
category: extractCategory(currentAction),
},
});
return recommendations;
}
// When customer completes purchase:
async function logPurchase(customerId: string, orderId: string, items: any[]) {
// Store purchase
for (const item of items) {
await memory.store({
agentId: `customer-${customerId}`,
content: `Purchased: ${item.name} ($${item.price})`,
type: "purchase_history",
metadata: {
customerId,
orderId,
timestamp: new Date().toISOString(),
productId: item.id,
productName: item.name,
price: item.price,
category: item.category,
brand: item.brand,
},
});
}
// Move session to past
await memory.store({
agentId: `customer-${customerId}`,
content: "Session completed, converted",
type: "browsing_pattern",
metadata: {
customerId,
timestamp: new Date().toISOString(),
session: "past",
converted: true,
},
});
}Example: Shopping Agent Remembers
Customer returns 1 week after purchase:
Customer lands on homepage, browses "winter gear"
Agent Memory Lookup:
1. Purchase history:
- Air Jordan 1 Low (2026-04-20, $150)
- Nike Pro shorts (2026-05-01, $60)
- White crew socks pack (2026-03-15, $15)
2. Preference facts:
- "Prefers Nike over Adidas"
- "Price range: $50–$200"
- "Size: 11 (shoes), Medium (apparel)"
- "Colors: white, black, grey"
3. Current session:
- Browsing: winter coats (7 min dwell time)
4. Past patterns:
- May 2026: Browsed shorts + shoes → bought both
- March 2026: Browsed socks + boots → bought socks only
- January 2026: Browsed winter jackets → no purchase
- Pattern: Customer shops by season, slow adoption of winter items
Agent Recommendation Logic:
"Customer already owns shoes (Air Jordans) and shorts. Currently browsing winter coats—high intent signal (7 min dwell). Prefers Nike. Previous winter browsing in Jan didn't convert, so don't push expensive parkas. Instead:
1. Nike winter running jacket ($120, preferred brand, in price range)
2. Thermal base layer ($40, complements running jacket, hadn't seen before)
3. Winter boots ($180, similar to March browsing when browsed but didn't buy—now shows higher intent)
Avoid: Adidas (brand preference), Expensive puffy parka ($400, outside price range), Shorts (already owns)"
Recommendations shown:
- Nike Therma-FIT Running Jacket ($120) — matches preference, price, intent
- Therma Base Layer top ($40) — complements jacket, new category
- Nike Winter Trail Boots ($180) — price point, fills gap from past interestWithout memory: Agent shows customer the same Air Jordan 1 they bought last week. Shows Adidas alternatives (wrong brand). Pushes $400 designer parka (outside budget). Recommends summer shorts (wrong season). Customer leaves, frustrated. No second purchase.
With memory: Agent knows purchase history (avoids dupes), knows preferences (Nike not Adidas), knows price sensitivity (no $400 items), knows current intent (winter coat browsing), knows past patterns (slow on winter adoption = moderate initial recs). Customer sees 3 relevant items, buys the jacket. Second purchase in 1 week. Higher lifetime value.
Memory Schema for E-commerce
Design your memory schema for fast, flexible recommendations:
interface EcommerceMemory {
agentId: string; // "customer-{customerId}"
namespace: "ecommerce";
// What was stored
content: string; // The action or fact
// How to retrieve it
type: "purchase_history" | "preference_fact" | "browsing_pattern" | "promotion_seen";
metadata: {
customerId: string;
// For purchase_history
productId?: string;
productName?: string;
category?: string;
brand?: string;
price?: number; // In cents or dollars
orderId?: string;
// For preference_fact
category?: string; // "brand", "price_range", "size", "color"
value?: string; // "Nike", "$50-$200", "size 11"
strength?: "strong" | "weak"; // Inferred from frequency
// For browsing_pattern
action?: string; // Category or product page
dwell_seconds?: number; // How long customer looked
session?: "current" | "past";
converted?: boolean; // Did this session lead to purchase?
// For promotion_seen
promotionCode?: string;
discountPercent?: number;
status?: "shown" | "ignored" | "used";
timestamp: string;
};
}Use-Case Decision Table
When should you use structured vs. unstructured memory for e-commerce?
| Decision | Structured (Typed Fields) | Unstructured (Free Text) | Example |
|---|---|---|---|
| Purchase history | Yes, include product ID, category, brand, price | Optionally include review text | { productId: "aj1-low-blk", category: "shoes", brand: "Nike", price: 15000 } |
| Preferences | Yes, include category (brand, size, etc.) and strength | No, structure enables filtering | { category: "brand", value: "Nike", strength: "strong" } |
| Browsing patterns | Yes, include category, dwell time, session flag | Optionally include search query | { action: "winter_coats", dwell_seconds: 420, session: "current", converted: true } |
| Promotions seen | Yes, include code, discount %, and status | No, structure enables exclusion logic | { promotionCode: "SUMMER25", discountPercent: 20, status: "used" } |
Rule of thumb: Typed fields for data that filters recommendations (brands, prices, categories) or prevent redundancy (already owned, already shown discount). Unstructured for browsing narratives.
Metrics: Impact of Agent Memory
E-commerce merchants using agent memory see:
- 25% higher cart conversion: Personalized recs match customer intent, not random suggestions
- 40% fewer irrelevant recommendations: Memory avoids dupes and brand mismatches
- 35% increase in repeat purchase rate: Recommendations anticipate next buy, not generic items
- 30% higher average order value: Better cross-sell and upsell when agent knows preferences
- 45% reduction in recommendation dismissals: Customers see items they actually want
Implementation Checklist
- Design memory schema with product ID, category, brand, price, and dwell tracking
- Implement retrieval pipeline (purchase history → preferences → current browsing → past patterns)
- Log all purchases and browsing actions to memory (add tracking to product pages and checkout)
- Filter recommendations: exclude already-owned products, respect brand preferences, honor price range
- Test with historical customer data: does recommendation engine avoid dupes and match preferences?
- Monitor metrics: conversion rate, repeat purchase rate, recommendation acceptance rate
Next Steps
- Learn more: Check Memory Architectures for session-scoped vs. customer-lifetime memory
- Reference: See Brain vs. Vector Databases for when to use semantic search vs. metadata filtering
- Build: Start with Brain open-source for recommendation prototypes, or try Managed Cloud for e-commerce scale