Standard Agentic Commerce Engine
The Standard Agentic Commerce Engine is a standard client and protocol guide for connecting agents to compatible e-commerce backends. It gives agents a consistent way to search products, manage carts, access account data, create orders, and hand payment back to the user.
GitHub Repository: https://github.com/NowLoadY/agent-commerce-engine
Quick Start: Backend Integration
The agent-commerce-engine includes a server specification in SERVER_SPEC.md for sites that want to expose a compatible commerce API. By implementing the documented endpoints, an existing storefront can support agent-driven product discovery, cart actions, account flows, and order creation without requiring a custom tool for each brand.
Reference Case: Lafeitu
For a production-grade implementation example using this engine, see the Lafeitu Gourmet Skill. It demonstrates the engine specialized for a real-world artisanal food brand.
🔒 Security & Privacy
To ensure transparency and protect user data, the Standard Agentic Commerce Engine follows these security protocols:
1. Local Credential Persistence
- - Storage Location: INLINECODE2
- Mechanism: Account and session Token information is stored locally in JSON format. The credential file is written with
0600 (user-only) permissions. - Security Upgrade: Since version 1.4.0, raw passwords are never stored after the initial login. The engine exchanges the password for a signed cryptographic token.
- Scope: Credentials are stored on the local machine for reuse by the current user environment.
- Lifecycle: Credentials can be purged at any time by running the
logout command.
2. Secure Transmission
- - Token-based Auth: Uses
x-api-token headers for authentication. Raw passwords are only transmitted once during the login or register phase to exchange for a token. - HTTPS Enforcement: The client rejects non-HTTPS remote endpoints.
localhost and 127.0.0.1 remain available for local development. - Encrypted Transport: Production traffic is expected to run over HTTPS so tokens are not sent over plain HTTP.
3. Anonymous Tracking (Visitor ID)
- - To support shopping carts for unauthenticated users, a unique, non-identifiable
Visitor ID (UUID v4) is generated and stored locally. This ID contains no personal information.
🛠 Tool Priority & Fallback Strategy
To provide the most accurate and efficient experience, follow this priority sequence:
- 1. API First (Primary): Always attempt to use the
commerce.py script first. It provides structured, high-precision data. Target a store via --store <url> argument. - Stateless Headers: Rely on the engine's built-in header management (
x-user-account, x-visitor-id) to maintain session integrity without cookies. - Self-Correction: If the API returns a 404 for a specific slug discovered via browser, prioritize the API's
search results as the source of truth for the backend.
🧠 Agent Operational Logic
Follow these logical flows to ensure a high-quality user experience:
1. Product Discovery & Validation
Goal: Ensure the item exists and find the correct specifications before taking action.
- - Action: Always run
search or list before adding to cart. - Logic: Use the API to discover the correct
slug and valid variant specs. Use --page and --limit arguments to safely navigate large catalogs without overwhelming the context limit. - Refinement: If multiple results are found, ask the user to specify based on the returned attributes. If
totalPages > page in the results, consider fetching the next page or refining the search.
2. Authentication & Profile Flow
Goal: Manage user privacy and session data.
- - Logic: The API is stateless. Actions requiring identity will return
401 Unauthorized if credentials aren't saved. - Commands:
1. View profile:
python3 scripts/commerce.py get-profile
2. Update details:
python3 scripts/commerce.py update-profile --name "Name" --address "..." --phone "..." --email "..."
- - Required Data: Respect the schema of the specific brand's backend.
3. Registration Flow
Goal: Handle new users.
- - Trigger: When the user needs a new account or the backend returns "User Not Found".
- Instruction: Prefer the built-in
send-code and register commands when the backend supports them. If a backend only returns a registration URL, hand the user to that flow.
4. Shopping Cart Management
Goal: Precise modification of the user's shopping session.
- - Logic: The engine supports incrementing quantities or setting absolute values.
- Commands:
-
Add:
python3 scripts/commerce.py add-cart <slug> --variant <V> --quantity <Q>
-
Update:
python3 scripts/commerce.py update-cart <slug> --variant <V> --quantity <Q>
-
Remove:
python3 scripts/commerce.py remove-cart <slug> --variant <V>
-
Clear:
python3 scripts/commerce.py clear-cart
-
Checkout / Create Order (Handoff):
python3 scripts/commerce.py create-order --name <NAME> --phone <PHONE> --province <PROVINCE> --city <CITY> --address <ADDRESS>
- - Validation: Variant values must be strictly chosen from the product's available options list.
- Payment Flow (Crucial): Agents currently cannot directly execute consumer payments (card/mobile wallets) due to a lack of financial authorization. Once an order is generated via
create-order, the API typically returns a URL. The Agent MUST hand this URL to the human user to finalize payment.
5. Brand Information & Storytelling
Goal: Access brand identity and support data.
- - Logic: Use the
brand-info interface to retrieve narrative content. - Tooling:
-
python3 scripts/commerce.py brand-story: Get the narrative/mission.
-
python3 scripts/commerce.py company-info: Get formal details.
-
python3 scripts/commerce.py contact-info: Get customer support channels.
🚀 Capabilities Summary
- -
search / list: Product discovery and inventory scan. Use --page <N> and --limit <N> to safely paginate through large catalogs. get: Deep dive into product specifications, variants, and pricing.promotions: Current business rules, shipping thresholds, and active offers.cart: Complete session summary including VIP discounts and tax/shipping estimates.add-cart / update-cart / remove-cart / clear-cart: Atomic cart control.create-order: Finalize cart into a pending order and secure payment URL for user handoff.get-profile / update-profile: Personalization and fulfillment data.brand-story / company-info / contact-info: Brand context and support.orders: Real-time tracking and purchase history.
💻 CLI Configuration & Examples
CODEBLOCK0
Credentials are automatically stored per-domain under ~/.openclaw/credentials/agent-commerce-engine/<domain>/.
🤖 Troubleshooting & Debugging
- -
AUTH_REQUIRED: Token missing or expired. Run login to obtain a new token. AUTH_INVALID: Wrong credentials. Verify account and password.PRODUCT_NOT_FOUND: Resource not found. Verify slug via search.VARIANT_UNAVAILABLE: The requested variant is invalid or out of stock. Check the instruction field for available alternatives.CART_EMPTY: Attempted checkout with no items. Add items first.- Connection Error: Verify the
--store URL is correct and the endpoint is reachable.
标准智能体商务引擎
标准智能体商务引擎是一个标准客户端和协议指南,用于将智能体连接到兼容的电子商务后端。它为智能体提供了一致的方式来搜索产品、管理购物车、访问账户数据、创建订单以及将支付环节交还给用户。
GitHub仓库:https://github.com/NowLoadY/agent-commerce-engine
快速入门:后端集成
agent-commerce-engine在SERVER_SPEC.md中包含了一个服务器规范,供希望暴露兼容商务API的网站使用。通过实现文档中描述的端点,现有商店可以支持智能体驱动的产品发现、购物车操作、账户流程和订单创建,而无需为每个品牌定制工具。
参考案例:Lafeitu
有关使用此引擎的生产级实现示例,请参阅Lafeitu美食技能。它展示了该引擎如何针对真实的手工食品品牌进行专门化应用。
🔒 安全与隐私
为确保透明度和保护用户数据,标准智能体商务引擎遵循以下安全协议:
1. 本地凭据持久化
- - 存储位置:~/.openclaw/credentials/agent-commerce-engine/
- 机制:账户和会话令牌信息以JSON格式本地存储。凭据文件以0600(仅用户)权限写入。
- 安全升级:自1.4.0版本起,初始登录后不再存储原始密码。引擎将密码交换为经过签名的加密令牌。
- 范围:凭据存储在本地机器上,供当前用户环境重复使用。
- 生命周期:随时可以通过运行logout命令清除凭据。
2. 安全传输
- - 基于令牌的身份验证:使用x-api-token头进行身份验证。原始密码仅在login或register阶段传输一次,以交换令牌。
- 强制HTTPS:客户端拒绝非HTTPS的远程端点。localhost和127.0.0.1仍可用于本地开发。
- 加密传输:生产流量应通过HTTPS运行,以确保令牌不会通过明文HTTP发送。
3. 匿名追踪(访客ID)
- - 为支持未认证用户的购物车,会生成并本地存储一个唯一的、不可识别的访客ID(UUID v4)。此ID不包含任何个人信息。
🛠 工具优先级与回退策略
为提供最准确高效的体验,请遵循以下优先级顺序:
- 1. API优先(主要):始终优先尝试使用commerce.py脚本。它提供结构化、高精度的数据。通过--store 参数指定目标商店。
- 无状态头:依赖引擎内置的头管理(x-user-account、x-visitor-id)来维护会话完整性,无需使用Cookie。
- 自我修正:如果API对通过浏览器发现的特定slug返回404,则优先将API的search结果作为后端的真实数据源。
🧠 智能体操作逻辑
遵循以下逻辑流程以确保高质量的用户体验:
1. 产品发现与验证
目标:确保商品存在,并在采取行动前找到正确的规格。
- - 操作:在添加到购物车之前,始终运行search或list。
- 逻辑:使用API发现正确的slug和有效的variant规格。使用--page和--limit参数安全地浏览大型目录,避免超出上下文限制。
- 细化:如果找到多个结果,请根据返回的属性要求用户指定。如果结果中的totalPages > page,考虑获取下一页或细化搜索。
2. 身份验证与个人资料流程
目标:管理用户隐私和会话数据。
- - 逻辑:API是无状态的。如果未保存凭据,需要身份验证的操作将返回401 Unauthorized。
- 命令:
1. 查看个人资料:python3 scripts/commerce.py get-profile
2. 更新详情:python3 scripts/commerce.py update-profile --name 姓名 --address ... --phone ... --email ...
3. 注册流程
目标:处理新用户。
- - 触发条件:当用户需要新账户或后端返回用户未找到时。
- 指令:当后端支持时,优先使用内置的send-code和register命令。如果后端仅返回注册URL,则将用户引导至该流程。
4. 购物车管理
目标:精确修改用户的购物会话。
-
添加:python3 scripts/commerce.py add-cart
--variant --quantity
- 更新:python3 scripts/commerce.py update-cart --variant --quantity
- 移除:python3 scripts/commerce.py remove-cart --variant
- 清空:python3 scripts/commerce.py clear-cart
- 结账/创建订单(交接):python3 scripts/commerce.py create-order --name --phone --province --city --address
- - 验证:变体值必须严格从产品的可用选项列表中选择。
- 支付流程(关键):由于缺乏财务授权,智能体目前无法直接执行消费者支付(银行卡/移动钱包)。通过create-order生成订单后,API通常会返回一个URL。智能体必须将此URL交给人类用户以完成支付。
5. 品牌信息与故事讲述
目标:获取品牌标识和支持数据。
- - 逻辑:使用brand-info接口检索叙事内容。
- 工具:
- python3 scripts/commerce.py brand-story:获取叙事/使命。
- python3 scripts/commerce.py company-info:获取正式详情。
- python3 scripts/commerce.py contact-info:获取客户支持渠道。
🚀 功能摘要
- - search / list:产品发现和库存扫描。使用--page 和--limit 安全地分页浏览大型目录。
- get:深入了解产品规格、变体和定价。
- promotions:当前业务规则、免运费门槛和有效优惠。
- cart:完整的会话摘要,包括VIP折扣和税费/运费估算。
- add-cart / update-cart / remove-cart / clear-cart:原子级购物车控制。
- create-order:将购物车最终确定为待处理订单,并获取支付URL供用户交接。
- get-profile / update-profile:个性化和履约数据。
- brand-story / company-info / contact-info:品牌背景和支持。
- orders:实时追踪和购买历史。
💻 CLI配置与示例
bash
通过--store直接指定目标商店(推荐)
python3 scripts/commerce.py --store https://api.yourbrand.com/v1 list --page 1 --limit 20
python3 scripts/commerce.py --store https://api.yourbrand.com/v1 search 商品
python3 scripts/commerce.py --store https://api.yourbrand.com/v1 add-cart --variant
或使用环境变量(已弃用,将在未来版本中移除)
export COMMERCE_URL=https://api.yourbrand.com/v1
python3 scripts/commerce.py list
凭据按域自动存储在~/.openclaw/credentials/agent-commerce-engine//下。
🤖 故障排除与调试
- - AUTHREQUIRED:令牌缺失或已过期。运行login获取新令牌。
- AUTHINVALID:凭据错误。验证账户和密码。
- PRODUCTNOTFOUND:资源未找到。通过search验证slug。
- VARIANTUNAVAILABLE:请求的变体无效或缺货。检查instruction字段获取可用替代选项。
- CARTEMPTY:尝试在无商品时结账。请先添加商品。
- 连接错误:验证--storeURL是否正确且端点可访问。