fix: 为 search_spu_products 工具注入 user_token 参数
## 问题
即使更新了 Product Agent prompt,LLM 仍然调用 search_products 而非 search_spu_products
## 根本原因
search_spu_products 工具需要 user_token 参数(Mall API 认证必需),
但 product_agent 函数中没有注入此参数,导致工具调用失败或被忽略
## 修改内容
### agent/agents/product.py:169-173
在工具调用前注入 user_token、user_id、account_id 参数:
```python
# Inject context for SPU product search (Mall API)
if result["tool_name"] == "search_spu_products":
arguments["user_token"] = state.get("user_token")
arguments["user_id"] = state["user_id"]
arguments["account_id"] = state["account_id"]
```
## 参数来源
- user_token: 从 Chatwoot webhook 提取(contact.custom_attributes.jwt_token)
- user_id: 从 AgentState 获取
- account_id: 从 AgentState 获取
## 预期效果
LLM 现在可以成功调用 search_spu_products 工具,
返回 Mall API 商品数据并以 Chatwoot cards 格式展示
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -165,12 +165,18 @@ async def product_agent(state: AgentState) -> AgentState:
|
||||
|
||||
if action == "call_tool":
|
||||
arguments = result.get("arguments", {})
|
||||
|
||||
|
||||
# Inject context for SPU product search (Mall API)
|
||||
if result["tool_name"] == "search_spu_products":
|
||||
arguments["user_token"] = state.get("user_token")
|
||||
arguments["user_id"] = state["user_id"]
|
||||
arguments["account_id"] = state["account_id"]
|
||||
|
||||
# Inject context for recommendation
|
||||
if result["tool_name"] == "recommend_products":
|
||||
arguments["user_id"] = state["user_id"]
|
||||
arguments["account_id"] = state["account_id"]
|
||||
|
||||
|
||||
# Inject context for quote
|
||||
if result["tool_name"] == "get_quote":
|
||||
arguments["account_id"] = state["account_id"]
|
||||
|
||||
Reference in New Issue
Block a user