Architecture
There are three participants in the cart flow:SDK Widget
Receives
cart_changed events via WebSocket to update the UI. Never talks to your backend directly for cart operations.VIZOCHOK Backend
AI Agent decides what to add/remove. Calls your webhooks server-to-server for validation.
Your Backend
Source of truth for cart state. Validates operations, checks stock, persists the real cart.
Cart Operation Flow
AI Agent calls your cart webhook
The agent calls
add_to_selection(sku="milk-001", qty=1) which sends a POST to your cart_url:Your backend confirms or rejects
Success:
{"ok": true}Failure: {"ok": false, "reason": "out_of_stock"}Agent updates state and responds
Agent updates internal cart state, generates a confirmation message, and sends via WebSocket:
text_delta/text_end(AI message)event {type: "item_selected", sku, name, ...}cart_changed {action, items[], total}
Initial Cart Loading
The
session_id parameter matches the userId you pass to the SDK widget config, or an auto-generated identifier if userId is not provided. Use this to look up the correct cart on your side.Handling the onCartChanged Event
In your frontend, register theonCartChanged callback to keep your cart UI in sync:
CartItem Structure
Each item incart.items contains:
Handling Rejections
When your backend rejects a cart operation (e.g., product is out of stock), the AI handles it gracefully:| Reason | When to Return |
|---|---|
out_of_stock | Product is not available |
product_not_found | SKU does not exist in your system |
quantity_exceeded | Requested quantity exceeds stock |
missing_sku | No SKU provided in the request |
missing_params | Required parameters are missing |
Cart Operations
The AI can perform four cart operations through your webhook:| Action | Description | Required Fields |
|---|---|---|
add | Add a product to the cart | sku, name, quantity, price |
remove | Remove a product from the cart | sku |
update_quantity | Change the quantity of an existing item | sku, quantity |
clear | Remove all items from the cart | (none) |
Without Webhooks
If you do not configure cart webhooks, VIZOCHOK still tracks the cart internally during the conversation. However:- Cart state is session-only (not persisted to your backend)
- No stock validation on add
- The
onCartChangedevent still fires in the SDK - Your frontend would need to reconcile the AI cart with your real cart