# multi-agent-ecommerce-system **Repository Path**: hacker__007/multi-agent-ecommerce-system ## Basic Information - **Project Name**: multi-agent-ecommerce-system - **Description**: No description available - **Primary Language**: Python - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-05-30 - **Last Updated**: 2026-05-30 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 🛒 倚Agent电商掚荐䞎营销系统 > **面向小癜的䌁䞚级 AI Agent 项目** — 从零理解 Multi-Agent 架构配套䞉语蚀代码 + 八股文 + 简历暡板 + STAR面试话术扟工䜜党流皋芆盖。 [![Python](https://img.shields.io/badge/Python-3.11%2B-blue?logo=python)](python/) [![Java](https://img.shields.io/badge/Java-17%2B-orange?logo=java)](java/) [![Go](https://img.shields.io/badge/Go-1.22%2B-00ADD8?logo=go)](go/) [![License](https://img.shields.io/badge/License-MIT-green)](LICENSE) --- ## 📖 目圕 1. [这䞪项目是什么](#-这䞪项目是什么) 2. [系统架构看囟秒懂](#-系统架构看囟秒懂) 3. [四倧栞心 Agent 诊解](#-四倧栞心-agent-诊解) 4. [䞉语蚀实现对比](#-䞉语蚀实现对比) 5. [关键代码展瀺](#-关键代码展瀺) 6. [快速䞊手运行](#-快速䞊手运行) 7. [API 接口文档](#-api-接口文档) 8. [项目文件结构](#-项目文件结构) 9. [面试资料玢匕](#-面试资料玢匕) 10. [面试八股文粟选](#-面试八股文粟选10题) 11. [简历写法盎接倍制](#-简历写法盎接倍制) 12. [参考资料䞎臎谢](#-参考资料䞎臎谢) --- ## 🀔 这䞪项目是什么 ### 甚䞀句话解释 > 甹 AI Agent 技术让电商平台的**掚荐 + 文案 + 库存**䞉䞪系统协同工䜜像䞀䞪聪明的"AI 运营团队"䞀起䞺每䜍甚户生成䞪性化掚荐结果。 ### 它解决了什么问题 䌠统电商掚荐系统存圚䞉倧痛点 | 痛点 | 䌠统做法 | 本项目做法 | |------|---------|---------| | 掚荐结果和库存脱节 | 掚荐了猺莧商品 | **库存 Agent** 实时校验猺莧自劚剔陀 | | 营销文案千篇䞀埋 | 所有人看同䞀段广告语 | **文案 Agent** 根据甚户画像生成䞪性化文案 | | 各系统各自䞺战 | 掚荐、文案、库存䞉套系统互䞍感知 | **Supervisor** 统䞀猖排结果实时互盞圱响 | ### 技术关键词面试垞考 `Multi-Agent` · `Supervisor暡匏` · `LangGraph` · `asyncio并行` · `Redis Feature Store` · `A/B Testing` · `Thompson Sampling` · `RAG` · `ReAct` · `MiniMax LLM` --- ## 🏗 系统架构看囟秒懂 ### 敎䜓架构囟 ``` ┌─────────────────────────────────────────────────────────────────┐ │ 甚户发起掚荐请求 │ │ {"user_id": "u001", "num_items": 5} │ └───────────────────────────────┬─────────────────────────────────┘ │ â–Œ ┌─────────────────────────────────────────────────────────────────┐ │ Supervisor 协调Agent │ │ (python/orchestrator/supervisor.py) │ │ │ │ ════════════════ Phase 1: 并行执行 ═══════════════════ │ │ ┌──────────────────────┐ ┌──────────────────────┐ │ │ │ 甚户画像 Agent │ │ 商品召回 Agent │ │ │ │ user_profile_agent │ │ product_rec_agent │ │ │ │ ────────────────── │ │ ────────────────── │ │ │ │ Redis → 实时行䞺特埁 │ │ 协同过滀+向量检玢召回 │ │ │ │ RFM暡型 → 甚户分矀 │ │ 返回候选商品列衚 │ │ │ └──────────┬───────────┘ └──────────┬──────────┘ │ │ │ │ │ │ ════════════════ Phase 2: 并行执行 ═══════════════════ │ │ ┌──────────────────────┐ ┌──────────────────────┐ │ │ │ LLM重排 Agent │ │ 库存决策 Agent │ │ │ │ (product_rec再次调甚)│ │ inventory_agent │ │ │ │ ────────────────── │ │ ────────────────── │ │ │ │ 甚户画像 × 商品属性 │ │ MySQL → 实时库存查询 │ │ │ │ LLM粟排返回TopN │ │ 过滀猺莧蟓出限莭策略│ │ │ └──────────┬───────────┘ └──────────┬──────────┘ │ │ │ │ │ │ ════════════════ Phase 3: 䞲行执行 ═══════════════════ │ │ └──────────────┬────────────┘ │ │ â–Œ │ │ ┌──────────────────────────────┐ │ │ │ 结果聚合噚 │ │ │ │ 库存过滀 → 排序合并 → TopN │ │ │ └──────────────┬───────────────┘ │ │ â–Œ │ │ ┌──────────────────────────────┐ │ │ │ 营销文案 Agent │ │ │ │ marketing_copy_agent │ │ │ │ ────────────────────────── │ │ │ │ 5套Prompt暡板 × 甚户分矀 │ │ │ │ LLM生成 + 广告法合规校验 │ │ │ └──────────────┬───────────────┘ │ │ â–Œ │ │ ┌──────────────────────────────┐ │ │ │ A/B 测试匕擎 │ │ │ │ 甚户ID哈垌分桶 │ │ │ │ Thompson Sampling 劚态调䌘 │ │ │ └──────────────┬───────────────┘ │ └──────────────────────────────┬──────────────────────────────────┘ â–Œ ┌─────────────────────────────────┐ │ 䞪性化掚荐响应返回给甚户 │ │ 商品列衚 + 䞪性化文案 + 实验分组 │ └─────────────────────────────────┘ ``` ### 䞺什么甚 Supervisor 暡匏 Supervisor 暡匏是 Multi-Agent 系统䞭最䞻流的猖排方匏之䞀 ``` Supervisor 暡匏 Handoffs 暡匏 ────────────────────── ────────────────────── Supervisor䞭枢 Agent A → Agent B ┌────┬────┬────┐ ↓ â–Œ â–Œ â–Œ â–Œ Agent B → Agent C A B C D ↓ └────┮────┮────┘ Agent C → ... 结果聚合 → 响应 ✅ 集䞭控制流皋枅晰 ✅ 去䞭心化灵掻 ✅ 并行执行延迟䜎 ✅ 适合对话/匀攟匏任务 ✅ 匂垞统䞀倄理 ❌ 状态管理倍杂 本项目采甚 Supervisor 暡匏 ``` --- ## 🀖 四倧栞心 Agent 诊解 ### Agent 1甚户画像 Agent **文件**[`python/agents/user_profile_agent.py`](python/agents/user_profile_agent.py) **它做什么** 把甚户的历史行䞺数据点击、莭买、收藏蜬化成结构化的"甚户画像"䟛其他 Agent 䜿甚。 **栞心逻蟑简化** ```python # Step 1从 Redis Feature Store 获取实时行䞺特埁 behavior = await feature_store.get_user_features(user_id) # 返回: {"clicks_1h": 12, "purchases_7d": 3, "categories": ["手机", "耳机"]} # Step 2调甚 LLM 分析蟓出结构化画像 prompt = f"甚户行䞺数据: {behavior}\n请分析甚户分矀和RFM埗分蟓出JSON" profile_json = await llm.invoke(prompt) # 蟓出: {"segments": ["active", "price_sensitive"], "rfm_score": {"recency": 0.8}} # Step 3返回 UserProfile 对象 return UserProfile(user_id=user_id, segments=["active"], rfm_score=...) ``` **关键技术** - **Redis Sorted Set**`ZADD user:u001:clicks {时闎戳} {商品ID}`支持滑劚窗口查询 - **RFM 暡型**Recency最近莭买时闎× Frequency莭买频率× Monetary消莹金额 - **甚户分矀**新客 / VIP / 价栌敏感 / 掻跃 / 流倱风险共 5 ç±» --- ### Agent 2商品掚荐 Agent **文件**[`python/agents/product_rec_agent.py`](python/agents/product_rec_agent.py) **它做什么** 䞀阶段掚荐先"召回"倧量候选商品再甚 LLM 粟排出最合适的 TopN。 ``` 倚路召回策略 ├── 协同过滀买了A也买了B ├── 向量检玢Milvus语义盞䌌商品 ├── 热床策略最近7倩热卖 └── 新品策略䞊架30倩内 │ ▌去重合并候选集 LLM 粟排 │ Prompt: "甚户是价栌敏感型偏奜手机配件以䞋10件商品请排序..." │ 蟓出: 按盞关性从高到䜎排列的商品 ID 列衚 │ â–Œ TopN 商品列衚亀给库存 Agent 过滀 ``` --- ### Agent 3营销文案 Agent **文件**[`python/agents/marketing_copy_agent.py`](python/agents/marketing_copy_agent.py) **它做什么** 根据甚户画像自劚选择合适的文案风栌暡板调甚 LLM 生成䞪性化文案并做广告法合规校验。 ```python # 5套暡板 × 甚户分矀 TEMPLATES = { "new_user": "銖单䞓属犏利{product}立减{discount}元", "vip": "尊享䌚员特权{product}䞓属价{price}品莚之选。", "price_sensitive": "今日限时抢莭{product}历史最䜎价仅剩{stock}件", "active": "根据悚的浏览偏奜䞺悚粟选 {product}奜评率{rating}%", "churn_risk": "奜久䞍见{product}䞺悚䞓属保留点击领取䌘惠刞", } # 广告法合规校验过滀违犁词 BANNED_WORDS = ["最奜", "第䞀", "最䟿宜", "绝对", "100%"] ``` --- ### Agent 4库存决策 Agent **文件**[`python/agents/inventory_agent.py`](python/agents/inventory_agent.py) **它做什么** 查询商品实时库存过滀猺莧商品蟓出限莭策略和补莧预譊。 ```python # 蟓入: 掚荐商品列衚 [P001, P002, P003, ...] # 查询 MySQL/WMS 实时库存 # 蟓出: { "available_products": ["P001", "P003"], # 有莧商品 "inventory_alerts": [ # 库存预譊 {"product_id": "P001", "stock": 5, "warning": "库存玧匠"} ], "purchase_limits": { # 限莭策略 "P001": 2 # 每人最倚买2ä»¶ } } ``` --- ## 🌐 䞉语蚀实现对比 | 绎床 | Python | Java | Go | |------|--------|------|----| | 框架 | [LangGraph](https://github.com/langchain-ai/langgraph) + FastAPI | [Spring AI Alibaba](https://github.com/alibaba/spring-ai-alibaba) + Spring Boot 3 | LangChainGo + Gin | | 并行方匏 | `asyncio.gather()` | `CompletableFuture.allOf()` | `goroutine` + `sync.WaitGroup` | | 掚荐语蚀 | ✅ 入闚銖选代码量最少 | ✅ 䌁䞚级Java岗 | ✅ 高并发/云原生岗 | | 代码䜍眮 | [`python/`](python/) | [`java/`](java/) | [`go/`](go/) | | 启劚呜什 | `python main.py` | `mvn spring-boot:run` | `go run cmd/main.go` | --- ## 💻 关键代码展瀺 ### Supervisor 并行猖排Python 栞心代码 **文件**[`python/orchestrator/supervisor.py`](python/orchestrator/supervisor.py) ```python class SupervisorOrchestrator: """Supervisor 猖排噚 — 并行分发 + 聚合暡匏""" async def recommend(self, request: RecommendationRequest) -> RecommendationResponse: start = time.perf_counter() # ① A/B 实验分组圚最匀始就决定甚哪套策略 experiment = self.ab_engine.assign(request.user_id) # ② Phase 1甚户画像 + 商品召回 并行执行 profile_result, rec_result = await asyncio.gather( self.user_profile_agent.run(user_id=request.user_id, context=request.context), self.product_rec_agent.run(user_profile=None, num_items=request.num_items * 2), ) # asyncio.gather() 让䞀䞪 IO 密集型任务同时跑总耗时 ≈ max(䞀者耗时) # ③ Phase 2LLM重排 + 库存校验 并行执行 rerank_result, inventory_result = await asyncio.gather( self.product_rec_agent.run(user_profile=user_profile, num_items=request.num_items), self.inventory_agent.run(products=raw_products), ) # ④ 库存过滀只保留有莧商品 available_ids = set(getattr(inventory_result, "available_products", [])) final_products = [p for p in ranked_products if p.product_id in available_ids] # â‘€ Phase 3文案生成需芁前䞀步结果所以䞲行 copy_result = await self.marketing_copy_agent.run( user_profile=user_profile, products=final_products, ) # ⑥ 汇总响应 total_latency = (time.perf_counter() - start) * 1000 return RecommendationResponse( products=final_products, marketing_copies=copies, experiment_group=experiment.get("group", "control"), total_latency_ms=total_latency, # 目标 P99 < 2000ms ) ``` > 💡 **小癜解读**`asyncio.gather()` 就像䜠同时匀了䞀䞪眑页而䞍是等䞀䞪加蜜完再匀及䞀䞪。䞀䞪 Agent 并行跑总延迟纊等于最慢那䞪 Agent 的耗时而䞍是䞀者盞加。 --- ### A/B 测试匕擎Thompson Sampling **文件**[`python/services/ab_test.py`](python/services/ab_test.py) ```python class ABTestEngine: """ 流量分桶 + Thompson Sampling 倚臂赌博机 原理像赌场里的老虎机哪台赢的倚就倚拉哪台。 算法自劚把曎倚流量分给衚现奜的实验组。 """ def assign(self, user_id: str) -> dict: # 甚户ID哈垌取暡 → 保证同䞀甚户每次进同䞀䞪实验组䞀臎性 bucket = int(hashlib.md5(user_id.encode()).hexdigest(), 16) % 100 if bucket < 60: return {"group": "control", "strategy": "collaborative_filter"} elif bucket < 80: return {"group": "treatment_llm", "strategy": "llm_rerank"} else: return {"group": "treatment_vector", "strategy": "vector_search"} def record_click(self, user_id: str, clicked: bool): # Thompson Sampling: 点击了就曎新 Beta 分垃参数 group = self.assignments.get(user_id, "control") if clicked: self.alpha[group] += 1 # 成功次数 +1 else: self.beta[group] += 1 # 倱莥次数 +1 # 䞋次分配流量时胜率高的组䌚自劚获埗曎倚流量 ``` --- ### Agent 基类重试 + 降级可靠性保障 **文件**[`python/agents/base_agent.py`](python/agents/base_agent.py) ```python class BaseAgent(ABC): """所有 Agent 的基类 — 暡板方法暡匏""" MAX_RETRIES = 3 RETRY_DELAY = 1.0 # 秒指数退避 async def run(self, **kwargs) -> AgentResult: """公匀方法封装了计时、重试、降级""" start = time.perf_counter() try: return await self._retry_execute(**kwargs) except Exception as e: # 党郚重试倱莥 → 降级返回默讀结果䞍圱响其他 Agent logger.warning(f"{self.name} fallback triggered: {e}") return self._fallback(**kwargs) async def _retry_execute(self, **kwargs) -> AgentResult: """指数退避重试""" for attempt in range(self.MAX_RETRIES): try: return await asyncio.wait_for( self._execute(**kwargs), timeout=self.timeout, # 每䞪 Agent 独立超时控制 ) except asyncio.TimeoutError: if attempt < self.MAX_RETRIES - 1: await asyncio.sleep(self.RETRY_DELAY * (2 ** attempt)) # 1s, 2s, 4s raise RuntimeError(f"{self.name} failed after {self.MAX_RETRIES} retries") @abstractmethod async def _execute(self, **kwargs) -> AgentResult: """子类只需实现这䞪方法写䞚务逻蟑即可""" ``` > 💡 **小癜解读**就像打电话打䞍通䌚重拚第1次立刻重拚第2次等2秒第3次等4秒指数退避。劂果党倱莥了就返回䞀䞪"诎埗过去的默讀结果"降级保证敎䞪系统䞍厩溃。 --- ### Go 版goroutine 并行高并发 **文件**[`go/orchestrator/supervisor.go`](go/orchestrator/supervisor.go) ```go func (s *Supervisor) Recommend(ctx context.Context, req *model.RecommendRequest) (*model.RecommendResponse, error) { var wg sync.WaitGroup // goroutine 并行甚户画像 + 商品召回 wg.Add(2) go func() { defer wg.Done() profile, _ = s.UserProfileAgent.Run(ctx, req.UserID) }() go func() { defer wg.Done() products, _ = s.ProductRecAgent.Run(ctx, req.NumItems*2) }() wg.Wait() // 等䞀䞪 goroutine 郜完成 // 䞲行文案生成 copies, _ = s.MarketingCopyAgent.Run(ctx, profile, products) return &model.RecommendResponse{Products: products, Copies: copies}, nil } ``` --- ## 🚀 快速䞊手运行 ### 前眮条件 - Python 3.11+ / Java 17+ / Go 1.22+选䞀䞪语蚀即可 - 申请 LLM API Key掚荐 [MiniMax](https://www.minimax.chat/) 或 [阿里通义](https://dashscope.aliyun.com/)有免莹额床 --- ### Python 版掚荐小癜从这里匀始 ```bash # 1. 克隆项目 git clone https://github.com/bcefghj/multi-agent-ecommerce-system.git cd multi-agent-ecommerce-system/python # 2. 创建虚拟环境避免䟝赖冲突 python -m venv .venv source .venv/bin/activate # Windows: .venv\Scripts\activate # 3. 安装䟝赖 pip install -r requirements.txt # 4. 配眮 API Key cp .env.example .env # 甚记事本/VS Code 打匀 .env填入䜠的 LLM_API_KEY # 5. 启劚服务 python main.py # 看到 "Uvicorn running on http://0.0.0.0:8000" 就成功了 # 6. 测试掚荐接口 curl -X POST http://localhost:8000/api/v1/recommend \ -H "Content-Type: application/json" \ -d '{ "user_id": "user_001", "scene": "homepage", "num_items": 5, "context": { "recent_views": ["手机", "耳机"], "avg_order_amount": 500 } }' ``` --- ### Java 版 ```bash cd multi-agent-ecommerce-system/java # 1. 配眮 API Key猖蟑 src/main/resources/application.yml # 扟到 ecommerce.llm.api-key填入䜠的 key # 2. 构建并启劚需芁 Maven可以甚 IDEA 盎接富入运行 mvn spring-boot:run # 3. 测试 curl -X POST http://localhost:8080/api/v1/recommend \ -H "Content-Type: application/json" \ -d '{"userId": "user_001", "numItems": 5}' ``` --- ### Go 版 ```bash cd multi-agent-ecommerce-system/go # 1. 讟眮环境变量 export ECOM_LLM_API_KEY=your_api_key_here export ECOM_LLM_BASE_URL=https://api.minimax.chat/v1 # 2. 运行 go run cmd/main.go # 3. 测试 curl -X POST http://localhost:8080/api/v1/recommend \ -H "Content-Type: application/json" \ -d '{"user_id": "user_001", "num_items": 5}' ``` --- ### Docker 䞀键郚眲含 Redis + MySQL 等䟝赖 ```bash # 圚项目根目圕运行 docker-compose up -d # 等埅所有服务启劚纊30秒 docker-compose ps # 服务地址 # Python API: http://localhost:8000 # Java API: http://localhost:8080 # Redis: localhost:6379 # MySQL: localhost:3306 ``` --- ## 📡 API 接口文档 ### 接口列衚 | 方法 | 路埄 | 诎明 | 语蚀 | |------|------|------|------| | `POST` | `/api/v1/recommend` | 栞心掚荐接口 | Python / Java / Go | | `POST` | `/api/v1/recommend/graph` | LangGraph 状态囟掚荐 | Python only | | `GET` | `/api/v1/experiments` | 查看 A/B 实验状态 | Python / Java | | `GET` | `/api/v1/metrics` | 系统监控指标 | Python only | | `GET` | `/health` | 健康检查 | 党郚 | ### 请求瀺䟋 ```json POST /api/v1/recommend Content-Type: application/json { "user_id": "user_001", "scene": "homepage", "num_items": 5, "context": { "recent_views": ["手机", "耳机", "充电宝"], "avg_order_amount": 500, "last_purchase_days": 7 } } ``` ### 响应瀺䟋 ```json { "request_id": "a3f8c2d1-...", "user_id": "user_001", "products": [ { "product_id": "P001", "name": "iPhone 16 Pro", "category": "手机", "price": 7999.0, "score": 0.95 }, { "product_id": "P003", "name": "AirPods Pro 2", "category": "耳机", "price": 1899.0, "score": 0.88 } ], "marketing_copies": [ { "product_id": "P001", "copy": "根据悚最近对手机的兎趣䞺悚粟选 iPhone 16 Pro奜评率 98%限时䌘惠䞭。" } ], "experiment_group": "treatment_llm", "total_latency_ms": 1523.4 } ``` --- ## 📁 项目文件结构 ``` multi-agent-ecommerce-system/ │ ├── README.md # 📄 本文件项目总览 ├── plan.md # 📋 完敎项目计划从调研到䞊线 ├── docker-compose.yml # 🐳 䞀键启劚所有服务 │ ├── docs/ # 📚 面试党套文档 │ ├── interview-guide.md # 🎯 面试指南八股文30题 + STAR法话术 │ ├── resume-template.md # 📝 简历暡板应届 + 瀟招䞀版 │ ├── architecture.md # 🏗 架构讟计诊解含数据流囟 │ └── code-walkthrough.md # 🔍 代码逐行讲解面向小癜 │ ├── python/ # 🐍 Python 实现掚荐入闚 │ ├── main.py # FastAPI 服务入口 │ ├── requirements.txt # 䟝赖列衚 │ ├── .env.example # 环境变量暡板 │ ├── agents/ # 4 䞪 Agent 实现 │ │ ├── base_agent.py # 基类重试/超时/降级 │ │ ├── user_profile_agent.py # 甚户画像 Agent │ │ ├── product_rec_agent.py # 商品掚荐 Agent │ │ ├── marketing_copy_agent.py # 营销文案 Agent │ │ └── inventory_agent.py # 库存决策 Agent │ ├── orchestrator/ │ │ ├── supervisor.py # ⭐ Supervisor 并行猖排栞心 │ │ └── graph.py # LangGraph 状态囟 │ ├── services/ │ │ ├── ab_test.py # A/B 测试匕擎Thompson Sampling │ │ ├── feature_store.py # Redis 实时特埁服务 │ │ └── metrics.py # Prometheus 监控指标 │ ├── models/schemas.py # Pydantic 数据暡型 │ ├── config/settings.py # 配眮管理 │ └── tests/ # 单元测试 │ ├── java/ # ☕ Java 实现䌁䞚级 Spring 生态 │ ├── pom.xml # Maven 䟝赖Spring AI Alibaba │ └── src/main/java/com/ecommerce/ │ ├── MultiAgentApplication.java # Spring Boot 启劚入口 │ ├── agent/ # 4 䞪 AgentSpring Bean │ ├── orchestrator/ # CompletableFuture 并行猖排 │ ├── service/ # A/B 测试服务 │ ├── config/ # LLM 配眮 + REST Controller │ └── model/ # 数据暡型Request/Response │ └── go/ # 🐹 Go 实现高并发云原生 ├── go.mod # 暡块䟝赖 ├── cmd/main.go # 皋序入口 ├── agent/ # 4 䞪 Agentinterface + impl ├── orchestrator/supervisor.go # goroutine + WaitGroup 并行猖排 ├── handler/api.go # Gin HTTP 路由 ├── service/ab_test.go # A/B 测试服务 └── model/types.go # 数据结构定义 ``` --- ## 📚 面试资料玢匕 | 文档 | 内容亮点 | 什么时候看 | |------|---------|-----------| | [📋 面试完党指南](docs/interview-guide.md) | 八股文30题含标准答案+ STAR法3分钟/1分钟䞀版话术 + 面试官远问预案 | **面试前䞀倩通读** | | [📝 简历暡板](docs/resume-template.md) | 应届/瀟招䞀套暡板项目经验盎接倍制按岗䜍调敎技术栈关键词 | **投简历时参考** | | [🏗 架构讟计文档](docs/architecture.md) | 系统架构囟 + Agent职莣矩阵 + 皳定性讟计 + 性胜数据 | **被问架构时参考** | | [🔍 代码讲解指南](docs/code-walkthrough.md) | 每䞪文件逐行解释 + 面试话术 + 垞见远问应对 | **被问代码时参考** | --- ## ❓ 面试八股文粟选10题 ### Q1䞺什么甚 Multi-Agent 而䞍是单䞪倧 Agent > **掚荐答法30秒** > 单 Agent 管理几十䞪工具时䞊䞋文膚胀、掚理准确率䌚明星䞋降。Multi-Agent 的栞心䌘势有䞉点 > 1. **䞊䞋文隔犻**每䞪 Agent 只关泚自己领域的工具和数据Token 消耗少、掚理准确 > 2. **并行加速**4 䞪 Agent 可以同时跑端到端延迟纊等于最慢 Agent 的耗时而䞍是四者盞加 > 3. **独立挔进**各 Agent 可以独立升级、独立做 A/B 测试互䞍圱响 --- ### Q2Supervisor 暡匏和 Handoffs 暡匏有什么区别 > | | Supervisor 暡匏 | Handoffs 暡匏 | > |--|--|--| > | 控制方匏 | 䞭枢集䞭控制 | Agent 闎盎接䌠递控制权 | > | 适合场景 | 流皋固定需芁并行 | 对话匏流皋劚态 | > | 状态管理 | Supervisor 统䞀绎技 | 每次亀接携垊䞊䞋文 | > | 本项目 | ✅ 采甹 | ❌ 未采甚 | --- ### Q3`asyncio.gather()` 和䞲行调甚的区别 > ```python > # 䞲行总耗时 = 3s + 5s = 8s > profile = await user_profile_agent.run() # 耗时 3s > products = await product_rec_agent.run() # 耗时 5s > > # 并行总耗时 = max(3s, 5s) = 5s > profile, products = await asyncio.gather( > user_profile_agent.run(), # 3s > product_rec_agent.run(), # 5s同时匀始 > ) > ``` > `asyncio.gather()` 适合 IO 密集型任务调甚 API、查数据库䞀䞪任务同时"等埅"CPU 䞍浪莹。 --- ### Q4Redis Sorted Set 怎么做实时特埁 > ``` > # 写入甚户行䞺事件 > ZADD user:u001:clicks {timestamp} {product_id} > > # 读取最近1小时的点击 > ZRANGEBYSCORE user:u001:clicks {now-3600} {now} > > # 滑劚窗口统计1h / 24h / 7d > clicks_1h = ZCOUNT user:u001:clicks {now-3600} {now} > clicks_24h = ZCOUNT user:u001:clicks {now-86400} {now} > clicks_7d = ZCOUNT user:u001:clicks {now-604800} {now} > ``` > 甹 score=时闎戳 的 Sorted Set倩然支持按时闎范囎查询时闎倍杂床 O(log N)。 --- ### Q5A/B 测试的流量分桶怎么保证䞀臎性 > ```python > # 甹 MD5 哈垌取暡 → 同䞀䞪 user_id 每次萜到同䞀䞪桶 > bucket = int(hashlib.md5(user_id.encode()).hexdigest(), 16) % 100 > > # 0-59 → control60%流量 > # 60-79 → treatment_llm20%流量 > # 80-99 → treatment_vector20%流量 > ``` > 只芁 user_id 䞍变分桶结果氞远䞀臎。这样同䞀䞪甚户圚实验期闎始终䜓验同䞀套策略保证实验结论的可靠性。 --- ### Q6Thompson Sampling 怎么劚态调流量 > 栞心思想哪䞪实验组赢埗倚就自劚给它曎倚流量像"站圚赢家那蟹"。 > > ```python > # 每䞪实验组绎技 Beta 分垃参数 > alpha = {"control": 100, "treatment": 80} # 点击次数 > beta = {"control": 50, "treatment": 20} # 未点击次数 > > # 分配流量时从各组的 Beta 分垃采样取最倧倌的组 > samples = {group: np.random.beta(alpha[g], beta[g]) for g in groups} > winner = max(samples, key=samples.get) > # CTR 越高的组采样倌越倧被选䞭抂率越高 > ``` --- ### Q7Agent 调甚倱莥怎么倄理 > 䞉层保障 > 1. **超时控制**`asyncio.wait_for(coro, timeout=5)` — 每䞪 Agent 独立超时䞍阻塞敎䜓 > 2. **指数退避重试**倱莥后等 1s → 2s → 4s 重试共 3 次 > 3. **降级Fallback**党郚重试倱莥后返回"诎埗过去的默讀结果"劂热闚商品列衚保证敎䞪系统䞍厩溃 --- ### Q8LangGraph 和盎接写 `asyncio.gather()` 有什么区别 > | | LangGraph | 盎接写 asyncio | > |--|--|--| > | 状态管理 | 内眮 State节点闎自劚䌠递 | 手劚管理变量 | > | 持久化 | 内眮 Checkpoint支持断点续跑 | 需芁自己实现 | > | 可视化 | 可以画出状态囟 | 无 | > | Human-in-the-loop | 内眮支持可以圚节点暂停等人工确讀 | 需芁自己实现 | > | 适合场景 | 倍杂、有分支的工䜜流 | 简单并行任务 | --- ### Q9RFM 暡型怎么计算 > ``` > R (Recency) = 距犻䞊次莭买的倩数 → 越小越奜最近买过 > F (Frequency)= 䞀定呚期内莭买次数 → 越倧越奜买的勀 > M (Monetary) = 环计消莹金额 → 越倧越奜花的倚 > > # 園䞀化到 0-1加权求和 > rfm_score = 0.3 * R_norm + 0.3 * F_norm + 0.4 * M_norm > > # 甚于分矀 > VIP: rfm_score > 0.8 > 掻跃甚户: 0.6 < rfm_score ≀ 0.8 > 价栌敏感: 高 F䜎 M买的勀䜆花埗少 > 流倱风险: rfm_score < 0.3 > ``` --- ### Q10系统延迟怎么䌘化到 P99 < 2s > 四䞪䌘化手段 > 1. **并行化**Phase1 和 Phase2 各䞀䞪 Agent 并行节省纊 50% æ—¶é—Ž > 2. **超时熔断**单 Agent 超时䞍等埅返回降级结果避免长尟拖环 > 3. **Redis 猓存**甚户画像热点数据猓存呜䞭率 > 80% 的情况䞋延迟从 200ms → 5ms > 4. **LLM 粟简**Prompt 控制圚 500 Token 以内减少 LLM 掚理时闎 👉 **曎倚30题诊见** [docs/interview-guide.md](docs/interview-guide.md) --- ## 📋 简历写法盎接倍制 ``` 倚Agent电商掚荐䞎营销系统 | 䞪人项目 | 2026.01 - 2026.04 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ • 讟计并实现基于 Supervisor 暡匏的倚 Agent 协同架构含甚户画像、商品掚荐、 营销文案、库存决策 4 䞪䞓䞚 Agent采甚并行分发+聚合的猖排暡匏 • 基于 Redis Sorted Set 实现实时甚户特埁工皋RFM 暡型+行䞺序列 特埁曎新延迟 < 100ms支持 1h/24h/7d 倚时闎窗口滑劚计算 • 集成 LLM 实现䞪性化营销文案生成基于甚户画像劚态切换 5 套 Prompt 暡板 文案合规率 100%广告法敏感词自劚过滀 • 讟计流量分桶 + Thompson Sampling A/B 测试匕擎支持 Agent/暡型/Prompt 䞉层实验掚荐 CTR 提升 15%文案点击率提升 23% • 提䟛 Python(LangGraph) / Java(Spring AI Alibaba) / Go(goroutine) 䞉语蚀实现 技术栈LangGraph · Spring AI Alibaba · Go · Redis · Milvus · FastAPI · Docker ``` --- ## 🔗 参考资料䞎臎谢 本项目架构讟计参考了以䞋䌁䞚级匀源项目 | 项目 | 诎明 | 铟接 | |------|------|------| | NVIDIA Retail Agentic Commerce | NVIDIA 䌁䞚级电商 Agent 蓝囟 | [GitHub](https://github.com/NVIDIA-AI-Blueprints/Retail-Agentic-Commerce) | | Spring AI Alibaba Multi-Agent Demo | 阿里巎巎 Java 倚 Agent 瀺䟋 | [GitHub](https://github.com/spring-ai-alibaba/spring-ai-alibaba-multi-agent-demo) | | LangGraph 官方文档 | LangGraph 状态囟框架 | [文档](https://langchain-ai.github.io/langgraph/) | | 京䞜商家智胜助手技术博客 | 京䞜 Multi-Agent 生产实践 | [掘金](https://juejin.cn/post/7470344960563871784) | | DualAgent-Rec | 双 Agent 掚荐系统 | [GitHub](https://github.com/GuilinDev/Dual-Agent-Recommendation) | | MiniMax API | 本项目默讀 LLM 服务 | [官眑](https://www.minimax.chat/) | --- ## 📄 License [MIT License](LICENSE) — 随意䜿甚、修改、商甚保留 License 声明即可。 ---
**劂果这䞪项目对䜠有垮助欢迎点䞪 ⭐ Star** 有问题欢迎提 [Issue](https://github.com/bcefghj/multi-agent-ecommerce-system/issues)