业务痛点:用户上月购买 Stage 1 奶粉(0-6月龄),宝宝即将 6 个月,需要升阶
Shopping Companion — 跨会话偏好记忆购物助手(4B≈GPT-5,Lazada真实数据)
Skill-Shopping-Companion-Agent
10万
待企业数据验证 · 缺失:样本、基线、时间窗、币种、计算方法、证据来源
1. 解决的问题
业务痛点:用户上月购买 Stage 1 奶粉(0-6月龄),宝宝即将 6 个月,需要升阶
2. 核心算法逻辑
核心思想
传统推荐系统的致命缺陷:每次会话从零开始——用户上周告诉导购"我要有机配方奶",下次进来又要重新解释,累计咨询成本极高,转化率低。Shopping Companion 的创新在于构建跨会话长期偏好记忆,将用户偏好结构化存储,Agent 可在后续会话中直接调用,像"私人导购"一样记住每位用户的长期喜好。
两阶段架构
阶段 1 — 偏好识别(Preference Identification):
- 输入:当前对话轮次 + 历史记忆
- 目标:从用户自然语言中提取结构化偏好维度(品牌偏好、功能需求、预算范围、过滤条件)
- 关键设计:偏好以结构化 key-value 存储(非向量),确保可解释可编辑;同时维护置信度和时间戳,过期偏好自动降权
阶段 2 — 商品验证(Product Verification):
- 输入:结构化偏好 + 商品搜索工具调用结果
- 目标:对候选商品逐条验证是否满足偏好约束,输出排序结果 + 匹配解释
- 工具调用链:
search(keyword)→filter(attribute)→verify(product, preference)→explain(match_reason)
双奖励 RL 训练机制
Agent 用强化学习训练,设计了两类奖励,解决传统 RLHF 只看最终结果忽略过程的问题:
R_{total} = R_{tool} + \lambda \cdot R_{result}- $R_{tool}$(工具使用奖励):每次工具调用的质量奖励——搜索关键词是否精准、过滤条件是否正确使用。惩罚无效的重复搜索、无关工具调用。
- $R_{result}$(结果奖励):最终推荐的商品是否命中用户真实偏好。用 Precision@K 计算。
- $\lambda = 0.5$:平衡过程质量与结果质量,避免 Agent 走捷径(工具滥用或结果幻觉)。
为什么 4B 能逼近 GPT-5
关键不是模型大小,而是训练数据质量:
- Lazada 120万真实商品 + 用户真实购买历史 → 偏好信号真实可信
- 双奖励 RL 在商品推荐这个窄任务上高度定向优化
- 任务分解为两个简单子任务(偏好识别 + 工具调用),降低了对模型通用推理能力的要求
结论:领域专用小模型(4B)> 通用大模型(GPT-5 on zero-shot)在垂直任务上的性能。
3. 业务应用场景
业务痛点:用户上月购买 Stage 1 奶粉(0-6月龄),宝宝即将 6 个月,需要升阶。传统推荐系统没有记忆——用户进来需要重新搜索,极易被竞品截流。
Shopping Companion 的工作方式:
| 时间节点 | Agent 行为 | 业务价值 | |---------|-----------|---------| | 会话 1(购买 Stage 1) | 偏好识别:`brand=Aptamil, organic=True, stage=1, price_max=80` | 写入偏好记忆 | | 会话 2(6周后) | 调出记忆 → 搜索 Stage 2 同品牌有机配方 → 验证符合偏好 → 推荐 | 主动推荐,无需用户重复说明 | | 会话 3(添加辅食) | 偏好扩展:`category_history=[formula], allergies=dairy_sensitive` →
4. 输入数据要求
- 当前对话轮次 + 历史记忆
- 结构化偏好 + 商品搜索工具调用结果
5. 输出结果
未提取到输出条目;请核对原始 Skill 卡片与代码。
6. 业务价值与 ROI
- 导购成本节省:60% × 5人导购 × 年薪 15万 = 45万元/年
- 复购率提升 20%:年复购 GMV 假设 2000万 × 20% = 400万元/年
- 合计潜在 ROI:445万元/年
- 基础版(规则偏好提取 + 结构化存储):1 周内可落地
- 进阶版(微调 4B 模型):需要 1-3 个月的业务对话数据标注
- 基础设施:Redis/数据库存储偏好记忆,无需复杂 MLOps
7. 代码模板
代码块数量:2
"""
Shopping Companion Agent — 跨会话偏好记忆购物助手
论文: Shopping Companion: Benchmarking and Training LLM Agents
for Long-Horizon Preference-Grounded E-Commerce Tasks
arXiv:2603.14864 | 2026年3月 | 基于 Lazada.com 120万真实商品
核心结论: 4B 小模型 72.5% ≈ GPT-5 74.0%(双奖励 RL 定向训练)
"""
from dataclasses import dataclass, field
from typing import List, Optional, Dict, Any
from datetime import datetime
import numpy as np
@dataclass
class UserPreference:
"""用户偏好维度数据类"""
brand: Optional[str] = None # 偏好品牌
organic: Optional[bool] = None # 有机认证需求
price_range: tuple = (0, 999) # 价格区间 (min, max)
category_history: List[str] = field(default_factory=list) # 购买品类历史
certifications: List[str] = field(default_factory=list) # 证书偏好 (EU-organic, DIN EN)
allergies: List[str] = field(default_factory=list) # 过敏/排除成分
no_added_sugar: Optional[bool] = None # 无添加糖需求
stage: Optional[int] = None # 婴儿月龄阶段 (1/2/3)
last_updated: str = field(default_factory=lambda: datetime.now().isoformat())
@dataclass
class Product:
"""商品数据类"""
product_id: str
name: str
brand: str
price: float
category: str
organic: bool = False
certifications: List[str] = field(default_factory=list)
ingredients: List[str] = field(default_factory=list)
stage: Optional[int] = None
rating: float = 4.0
@dataclass
class RecommendationResult:
"""推荐结果"""
products: List[Product]
match_explanations: List[str]
tool_reward: float
result_reward: float
total_reward: float
class PreferenceMemory:
"""
跨会话用户偏好存储/更新/检索
核心设计:结构化 key-value 存储(非向量),可解释可编辑
"""
def __init__(self):
self._store: Dict[str, UserPreference] = {}
self._update_log: Dict[str, List[str]] = {}
def store(self, user_id: str, preference: UserPreference):
self._store[user_id] = preference
if user_id not in self._update_log:
self._update_log[user_id] = []
self._update_log[user_id].append(
f"[{preference.last_updated[:10]}] 更新偏好: brand={preference.brand}, "
f"organic={preference.organic}, stage={preference.stage}"
)
def retrieve(self, user_id: str) -> Optional[UserPreference]:
return self._store.get(user_id)
def update_partial(self, user_id: str, updates: dict):
"""部分更新偏好(不覆盖已有字段)"""
pref = self._store.get(user_id, UserPreference())
for key, value in updates.items():
if hasattr(pref, key) and value is not None:
setattr(pref, key, value)
pref.last_updated = datetime.now().isoformat()
self.store(user_id, pref)
def get_history(self, user_id: str) -> List[str]:
return self._update_log.get(user_id, [])
def has_preference(self, user_id: str) -> bool:
return user_id in self._store
class ProductSearchTool:
"""商品搜索工具(模拟 Lazada 商品库)"""
def __init__(self, catalog: List[Product]):
self.catalog = catalog
self.search_count = 0
self.filter_count = 0
def search(self, keyword: str) -> List[Product]:
"""关键词搜索"""
self.search_count += 1
keyword_lower = keyword.lower()
return [p for p in self.catalog
if keyword_lower in p.name.lower()
or keyword_lower in p.category.lower()
or keyword_lower in p.brand.lower()]
def filter(self, products: List[Product],
max_price: float = None,
organic: bool = None,
stage: int = None,
exclude_ingredients: List[str] = None) -> List[Product]:
"""属性过滤"""
self.filter_count += 1
result = products[:]
if max_price is not None:
result = [p for p in result if p.price <= max_price]
if organic is not None:
result = [p for p in result if p.organic == organic]
if stage is not None:
result = [p for p in result if p.stage is None or p.stage == stage]
if exclude_ingredients:
result = [p for p in result
if not any(ing in p.ingredients for ing in exclude_ingredients)]
return result
class ShoppingCompanionAgent:
"""
两阶段 Shopping Companion Agent
Stage 1: 偏好识别 (preference_stage)
Stage 2: 商品验证 + 推荐 (search_stage)
双奖励: R_total = R_tool + lambda * R_result
"""
LAMBDA = 0.5 # 工具奖励 vs 结果奖励平衡系数
def __init__(self, memory: PreferenceMemory, search_tool: ProductSearchTool):
self.memory = memory
self.search_tool = search_tool
def preference_stage(self, user_id: str, user_input: str) -> UserPreference:
"""
阶段 1: 从用户输入中识别并更新偏好
生产环境:用微调后的 LLM 做 NER + 偏好抽取
此处用规则模拟
"""
updates = {}
if "有机" in user_input or "organic" in user_input.lower():
updates["organic"] = True
if "欧标" in user_input or "EU" in user_input:
updates["certifications"] = ["EU-organic"]
if "无糖" in user_input or "无添加糖" in user_input:
updates["no_added_sugar"] = True
if "stage 2" in user_input.lower() or "2段" in user_input:
updates["stage"] = 2
if "stage 1" in user_input.lower() or "1段" in user_input:
updates["stage"] = 1
if "hipp" in user_input.lower():
updates["brand"] = "HiPP"
if "holle" in user_input.lower():
updates["brand"] = "Holle"
if "$" in user_input or "价格" in user_input:
updates["price_range"] = (0, 80)
if updates:
self.memory.update_partial(user_id, updates)
return self.memory.retrieve(user_id) or UserPreference()
def search_stage(self, preference: UserPreference,
query_keyword: str) -> tuple:
"""
阶段 2: 商品搜索 + 偏好验证 + 推荐解释
返回: (products, explanations, tool_reward)
"""
# 工具调用链
results = self.search_tool.search(query_keyword)
tool_calls = 1 # 记录工具调用次数
filtered = self.search_tool.filter(
results,
max_price=preference.price_range[1] if preference.price_range else None,
organic=preference.organic,
stage=preference.stage,
exclude_ingredients=preference.allergies,
)
tool_calls += 1
# 工具奖励:有效调用 vs 无效
tool_reward = 1.0 if len(filtered) > 0 else 0.3
tool_reward -= max(0, tool_calls - 2) * 0.1 # 惩罚过多工具调用
# 为每个商品生成匹配解释
explanations = []
for p in filtered[:5]: # Top 5
reasons = []
if preference.organic and p.organic:
reasons.append("✓ 有机认证")
if preference.brand and preference.brand.lower() in p.brand.lower():
reasons.append(f"✓ 偏好品牌 {p.brand}")
if preference.certifications:
matched_certs = [c for c in preference.certifications
if c in p.certifications]
if matched_certs:
reasons.append(f"✓ {'/'.join(matched_certs)} 认证")
if preference.stage and p.stage == preference.stage:
reasons.append(f"✓ 适合 {preference.stage} 段宝宝")
if not reasons:
reasons.append("符合价格区间")
explanations.append(f"{p.name}: {', '.join(reasons)}")
return filtered[:5], explanations, max(0.0, tool_reward)
def _result_reward(self, recommended: List[Product],
ground_truth_ids: List[str]) -> float:
"""结果奖励:Precision@K"""
if not recommended or not ground_truth_ids:
return 0.5
hits = sum(1 for p in recommended if p.product_id in ground_truth_ids)
return hits / len(recommended)
def chat(self, user_id: str, user_input: str,
query_keyword: str,
ground_truth_ids: List[str] = None) -> RecommendationResult:
"""完整对话轮次:偏好识别 + 搜索推荐 + 奖励计算"""
# Stage 1: 偏好识别
preference = self.preference_stage(user_id, user_input)
# Stage 2: 搜索验证
products, explanations, tool_reward = self.search_stage(preference, query_keyword)
# 结果奖励
result_rwd = self._result_reward(products, ground_truth_ids or [])
total_reward = tool_reward + self.LAMBDA * result_rwd
return RecommendationResult(
products=products,
match_explanations=explanations,
tool_reward=round(tool_reward, 3),
result_reward=round(result_rwd, 3),
total_reward=round(total_reward, 3),
)
def _build_catalog() -> List[Product]:
"""构造模拟母婴商品目录"""
return [
Product("P001", "HiPP Stage 1 有机配方奶粉", "HiPP", 45.99, "奶粉",
organic=True, certifications=["EU-organic"], stage=1),
Product("P002", "HiPP Stage 2 有机配方奶粉", "HiPP", 48.99, "奶粉",
organic=True, certifications=["EU-organic"], stage=2),
Product("P003", "Holle Goat 有机山羊奶粉 Stage 1", "Holle", 52.99, "奶粉",
organic=True, certifications=["EU-organic", "Demeter"], stage=1),
Product("P004", "Holle 有机米粉 辅食", "Holle", 12.99, "辅食",
organic=True, certifications=["EU-organic"],
ingredients=["有机大米", "维生素"]),
Product("P005", "Lebenswert Stage 2 有机奶粉", "Lebenswert", 39.99, "奶粉",
organic=True, certifications=["EU-organic"], stage=2),
Product("P006", "普通配方奶粉 Stage 1", "Generic", 19.99, "奶粉",
organic=False, stage=1, ingredients=["棕榈油", "葡萄糖"]),
Product("P007", "Aptamil 进口奶粉 Stage 2", "Aptamil", 55.00, "奶粉",
organic=False, certifications=["DIN EN"], stage=2),
Product("P008", "有机果泥 苹果泥 4+ 月龄", "HiPP", 3.99, "辅食",
organic=True, ingredients=["有机苹果"]),
]
def main():
"""测试:3 个用户对话场景,验证偏好记忆跨会话保持"""
print("=" * 65)
print("Shopping Companion Agent — 母婴出海跨会话偏好记忆测试")
print("arXiv:2603.14864 | 4B 模型 72.5% ≈ GPT-5 74.0%")
print("=" * 65)
memory = PreferenceMemory()
catalog = _build_catalog()
search_tool = ProductSearchTool(catalog)
agent = ShoppingCompanionAgent(memory, search_tool)
scenarios = [
{
"name": "场景一:跨会话母婴复购推荐(3轮对话)",
"user_id": "user_001",
"turns": [
("买1段奶粉,要有机的,欧标认证", "奶粉", ["P001", "P003"]),
("宝宝6个月了,推荐2段奶粉", "2段奶粉", ["P002", "P005"]),
("还需要辅食", "辅食", ["P004", "P008"]),
],
},
{
"name": "场景二:TikTok Shop 导购(有机/欧标/无糖偏好积累)",
"user_id": "user_002",
"turns": [
("推荐6个月宝宝奶粉", "奶粉 stage 2", ["P002", "P005"]),
("要有机的,最好欧标", "有机欧标奶粉", ["P002", "P005"]),
("还有什么好的辅食推荐", "有机辅食", ["P004", "P008"]),
],
},
{
"name": "场景三:新用户冷启动(无偏好历史)",
"user_id": "user_003",
"turns": [
("推荐奶粉", "奶粉", ["P001", "P002"]),
],
},
]
for scenario in scenarios:
print(f"\n{'─' * 55}")
print(f"🛒 {scenario['name']}")
uid = scenario["user_id"]
for turn_idx, (user_msg, keyword, ground_truth) in enumerate(scenario["turns"], 1):
result = agent.chat(uid, user_msg, keyword, ground_truth)
pref = memory.retrieve(uid)
print(f"\n [轮次 {turn_idx}] 用户: {user_msg}")
if pref:
print(f" 记忆状态: organic={pref.organic}, stage={pref.stage}, "
f"certifications={pref.certifications}")
print(f" 推荐结果 ({len(result.products)} 款):")
for exp in result.match_explanations[:3]:
print(f" · {exp}")
print(f" 奖励: R_tool={result.tool_reward} + "
f"0.5×R_result({result.result_reward}) = {result.total_reward}")
# 验证偏好记忆跨会话持久化
print(f"\n{'─' * 55}")
print("📊 偏好记忆持久化验证:")
for uid in ["user_001", "user_002"]:
pref = memory.retrieve(uid)
history = memory.get_history(uid)
if pref:
print(f" {uid}: organic={pref.organic}, stage={pref.stage}, "
f"certifications={pref.certifications}, 更新次数={len(history)}")
print(f"\n{'=' * 65}")
print("✅ 测试通过 — 跨会话偏好记忆保持正常")
if __name__ == "__main__":
main()
print("[✓] Shopping Companion Agent 测试通过")8. 论文来源
论文链接用于核验方法来源,不自动证明本页商业结果。