使用 BuyWhere + LlamaIndex 构建价格比较代理

Dev.to AI 2026-07-16T03:17:07.248852

如果你正在用 LlamaIndex 构建 AI 代理,现在这些代理可以查询 BuyWhere,获取 9 个国家的结构化价格对比数据,返回可直接用于下游处理的 JSON。

典型场景:代理帮用户找到笔记本电脑的最优价格,然后引导用户前往零售商,并预填好结账信息。

集成方式

集成很简单——将 BuyWhere 的搜索接口封装成 LlamaIndex 的 FunctionTool

from llama_index.core.tools import FunctionTool
import requests

def buywhere_search(product: str) -> dict:
    response = requests.get(f"https://buywhere.ai/api/search?q={product}")
    return response.json()

price_tool = FunctionTool.from_defaults(
    fn=buywhere_search,
    description="Search BuyWhere for product prices across 9 countries"
)

就这么简单——你的 LlamaIndex 代理现在可以搜索价格、跨市场比较,并基于实时数据给出推荐。

BuyWhere 返回的数据

每次搜索返回标准化的产品结构:

{
  "title": "MacBook Air M4 13-inch",
  "brand": "Apple",
  "price": 1299.00,
  "currency": "SGD",
  "merchant": "Lazada",
  "country": "SG",
  "in_stock": true,
  "url": "https://..."
}

你的代理得到的是结构化数据,可以直接用于推理——无需 HTML 抓取,无需正则解析。

这对代理电商的意义

大多数 AI 购物代理缺少的正是可靠、结构化的产品数据。BuyWhere 提供:

快速上手

  1. buywhere.ai/api-keys 获取 API 密钥
  2. 安装 LlamaIndex:pip install llama-index
  3. 按上述方式封装 API 调用
  4. 将其添加到代理的工具列表中

或者直接使用 MCP 服务器:

npx @buywhere/mcp-server --api-key YOUR_KEY

下一步计划

我们看到早期采用者正在构建:

用 BuyWhere + LlamaIndex 打造价格对比代理

如果你也在做类似的事情,欢迎和我们聊聊。

查看原文