Multi-item cart management
Updated: Sep 4, 2026
Copy for LLM
A cart assembled over a conversation is harder than a cart assembled on a web page. There is no screen showing the current contents, the shopper refers to items by description rather than by line, and several turns can pass between choosing something and confirming it. Meta Business Agent can run this flow, but only if the cart lives in your system and every operation reads it fresh. This page covers the tools for adding, changing, and removing items, the quantity rules that stop bad writes, and the confirmation step that ends the basket phase.
The agent handles:
- Adding items across many turns without losing earlier ones
- Confirming quantity before writing, rather than assuming one
- Changing and removing items the shopper refers to by description
- Enforcing per-item and per-basket quantity limits before any write
- Applying a discount code and reporting whether it was accepted
- Reading the basket back for confirmation before checkout
Who this guide is for
The examples use a specialty grocer, but the pattern fits any business where a shopper buys several things in one conversation. The distinguishing feature is not the number of items but the number of turns: a basket that accumulates over a conversation needs state, and state needs rules.
| Organization type | What a basket looks like | The rule that matters most |
|---|---|---|
Specialty grocery | Ten to thirty lines, several with weights or quantities | Per-line limits, and substitutions when something is out |
Bakery and prepared food | Many small lines ordered against a collection time | Batch limits per line, and a hard cutoff before production |
Licensed and age-restricted retail | Mixed regulated and unregulated items | Per-item limits enforced by law, not by policy |
Restaurants and takeaway | Many small lines with modifiers | Modifier correctness, and a hard cutoff at order time |
Office and business supply | Repeat orders with occasional changes | Reordering a previous basket, then editing it |
This guide covers the basket phase only, and ends at confirmation. If the shopper buys one thing in one turn, see Single item purchase agent — a cart is unnecessary overhead there. For how items get into the conversation in the first place, see Smart product recommendations. For the availability layer underneath, see Catalog integration and real-time inventory checks.
Each step below notes how the API is used in other scenarios, then applies it to the grocery example.
Prerequisites
- An onboarded and enabled Meta Business Agent (
rollout.enabled: true) — see End-to-end setup - A valid system user access token (SUAT) or Business Integration System User (BISU) token with the
whatsapp_business_messagingpermission — see Generate an access token - Your WhatsApp Business phone number ID (
{entity_id}) — find it in WhatsApp Manager under Account tools > Phone numbers - A cart service exposing read, add, update, and remove operations over HTTPS
- A session identifier the cart is keyed on — see User login
- A live availability check, required by Validate before every write
Where the cart lives
The cart lives in your system. It is not held in the conversation, and it is not reconstructed by the agent from what was said earlier.
This is the single decision that determines whether the flow works. A conversation is not a reliable store: turns are summarized, quantities discussed and revised, and items mentioned hypothetically look much like items actually added. An agent asked to remember a basket will produce one that is plausible and subtly wrong — usually a quantity from two turns ago, or an item the shopper considered and rejected.
Three rules follow, and every tool below implements them.
Read before you write. Every mutation starts by reading the current cart, so the write is based on what is in it now rather than what was in it when the shopper last asked.
Read after you write. Every mutation ends by reading the cart back, and the agent reports from that read rather than from what it intended to do.
Never reuse an identifier across turns. Line identifiers, quantities, and prices from an earlier turn are stale. Take them from the read in the current turn.
These cost an extra round trip. Take the cost. Nearly every wrong-basket failure traces back to a write built from remembered state.
Add agent instructions
Agent instructions shape how the agent responds. The
title is a short identifier, description tells the agent when to apply the instruction, and skill contains the instruction text. Titles are limited to lowercase letters, numbers, and hyphens.curl -X POST "https://api.facebook.com/{entity_id}/agent_config/skills" \
-H "Authorization: Bearer {ACCESS_TOKEN}" \
-H "Content-Type: application/json" \
-H "X-API-Version: 2.0.0" \
-d '{
"title": "cart-management",
"description": "Applied whenever a shopper adds something to their basket, changes a quantity, removes an item, asks what is in the basket, or asks for the total.",
"skill": "Call get_cart before every change and again after it, and describe the basket only from the most recent read. Never state a quantity, price, or total from an earlier turn. Ask how many the shopper wants before adding anything, and never assume one. Confirm which item they mean when their words match more than one product, and never guess between two candidates. Take line identifiers from the current get_cart response only. When a change is rejected because of a limit, tell the shopper the limit and what is currently in the basket, and make no partial change. When the shopper asks for the total, read the cart and report the figure it returns rather than adding the items up yourself. Read the whole basket back for confirmation before checkout and wait for an explicit yes. Do not start checkout, take payment details, or promise a delivery date in this conversation."
}'
Forbidding the agent from computing the total is worth the line it takes. Given a list of prices and quantities an agent will happily produce a figure, and it will occasionally be wrong — before any discount, delivery charge, or tax rule your service applies. The total is a value your system computes and the agent reports.
Where else this applies. Any accumulating state managed through conversation needs the same three prohibitions: no remembered values, no computed aggregates, no guessed references. The domain changes; the failure mode does not.
Define connector tools
Connector tools define the operations the agent can invoke. Each tool needs a
name, a description, user_auth_required, and a request_definition describing the outbound HTTP call.A
name can contain only letters, numbers, and underscores. Spaces, hyphens, and other punctuation are rejected. It also cannot start or end with an underscore, or contain two underscores in a row, so check_order_status is accepted while _check_order, check_order_, and check__order are not. The same rules apply to a connector’s name.A cart needs five tools. Set
user_auth_required to true on all of them so the cart is bound to the session rather than passed around as a parameter — see User login.Read the cart
The most-called tool in the flow, and the one everything else depends on.
curl -X POST "https://api.facebook.com/{entity_id}/agent_connectors/{connector_id}/tools" \
-H "Authorization: Bearer {ACCESS_TOKEN}" \
-H "Content-Type: application/json" \
-H "X-API-Version: 2.0.0" \
-d '{
"name": "get_cart",
"description": "Returns the current basket: every line with its line ID, product name, SKU, unit price, quantity, and line total, plus the basket subtotal, any discount applied, and the number of items. Call this before every change and again after every change. This is the only source of truth for what is in the basket; never describe the basket from memory.",
"user_auth_required": true,
"request_definition": {
"method": "GET",
"path": "/cart"
}
}'
Return a stable
line_id per line and make it the only way to address a line. Position is not stable, and a SKU is not unique once the same product appears twice with different options.Return the subtotal and the item count with every read. Both are asked for constantly, and returning them removes the temptation for the agent to work them out.
Add an item
The parameter that causes the most trouble is
quantity, because “add” and “set” are different operations and an agent will conflate them if the description lets it.curl -X POST "https://api.facebook.com/{entity_id}/agent_connectors/{connector_id}/tools" \
-H "Authorization: Bearer {ACCESS_TOKEN}" \
-H "Content-Type: application/json" \
-H "X-API-Version: 2.0.0" \
-d '{
"name": "add_cart_item",
"description": "Adds units of one product to the basket and returns the updated basket. The quantity is the number of units to ADD, not the total the shopper should end up with; to set a total, use update_cart_item instead. Call get_cart first. Only call this after the shopper has stated a quantity and, where several products matched, confirmed which one they mean. The whole call is rejected if it would breach a limit, so nothing is partially added.",
"user_auth_required": true,
"request_definition": {
"method": "POST",
"path": "/cart/items",
"body": {
"content_type": "application/json",
"params": {
"sku": {
"type": "string",
"description": "The SKU of the product to add, exactly as it appears in the catalog."
},
"quantity": {
"type": "integer",
"description": "How many units to add to the existing quantity. Never send the desired total here."
}
},
"required": ["sku", "quantity"]
}
}
}'
Spell out the add-versus-set distinction in capitals in the description. It is the most common wrong write in a cart flow: a shopper says “make that three” when two are already in the basket, and an agent that reaches for
add_cart_item produces five.Change a quantity
curl -X POST "https://api.facebook.com/{entity_id}/agent_connectors/{connector_id}/tools" \
-H "Authorization: Bearer {ACCESS_TOKEN}" \
-H "Content-Type: application/json" \
-H "X-API-Version: 2.0.0" \
-d '{
"name": "update_cart_item",
"description": "Sets one basket line to a specific quantity and returns the updated basket. The quantity is the TOTAL the line should end up at, not an increment. Use this whenever the shopper says make it, change it to, or I only want. Call get_cart immediately before and take line_id from that response. Setting a quantity of zero is rejected; use remove_cart_item instead.",
"user_auth_required": true,
"request_definition": {
"method": "PUT",
"path": "/cart/items/{line_id}",
"path_parameters": {
"line_id": {
"type": "string",
"description": "The line to change, taken from the get_cart response in this turn. Never reuse a line ID from an earlier turn."
}
},
"body": {
"content_type": "application/json",
"params": {
"quantity": {
"type": "integer",
"description": "The total quantity this line should have after the change."
}
},
"required": ["quantity"]
}
}
}'
Path parameters are always required, so they take no
required flag. Body fields list their required keys in body.required.Rejecting a quantity of zero rather than treating it as a removal keeps the two intents distinct. “Make it zero” and “take it off” should reach the same outcome through the tool that means it.
Remove an item
curl -X POST "https://api.facebook.com/{entity_id}/agent_connectors/{connector_id}/tools" \
-H "Authorization: Bearer {ACCESS_TOKEN}" \
-H "Content-Type: application/json" \
-H "X-API-Version: 2.0.0" \
-d '{
"name": "remove_cart_item",
"description": "Removes one line from the basket entirely and returns the updated basket. Call get_cart immediately before and take line_id from that response. When the shopper words could match more than one line, ask which before removing. Never remove more than one line in a single turn without confirming each.",
"user_auth_required": true,
"request_definition": {
"method": "DELETE",
"path": "/cart/items/{line_id}",
"path_parameters": {
"line_id": {
"type": "string",
"description": "The line to remove, taken from the get_cart response in this turn."
}
}
}
}'
Removals deserve more caution than additions because they are the change a shopper is least likely to notice. An item incorrectly added shows up in the total; an item incorrectly removed is simply absent, and is usually discovered at delivery.
Apply a discount code
curl -X POST "https://api.facebook.com/{entity_id}/agent_connectors/{connector_id}/tools" \
-H "Authorization: Bearer {ACCESS_TOKEN}" \
-H "Content-Type: application/json" \
-H "X-API-Version: 2.0.0" \
-d '{
"name": "apply_discount_code",
"description": "Applies a discount code to the basket and returns the updated basket with the discount shown, or a reason the code was not accepted. Send the code exactly as the shopper typed it, without changing its case or removing characters. Report the reason the service gives; do not explain why a code might have failed or suggest other codes.",
"user_auth_required": true,
"request_definition": {
"method": "POST",
"path": "/cart/discount",
"body": {
"content_type": "application/json",
"params": {
"code": {
"type": "string",
"description": "The discount code the shopper gave, character for character as they typed it."
}
},
"required": ["code"]
}
}
}'
Send the code unmodified. An agent that helpfully uppercases or trims a code turns a rejection you can explain into one you cannot reproduce.
Do not let the agent speculate about why a code failed. Guesses about minimum spend or expiry become commitments, and shoppers hold you to them.
Where else this applies. The read-modify-read triple and the add-versus-set distinction generalize to any conversational collection: a list of passengers, a set of insured items, an appointment with several attendees. Where the platform differs from a web form is that there is no visible current state, so the read after the write is what the shopper sees instead of the screen.
Validate before every write
Availability changes while a basket is being assembled. An item added at the start of a ten-minute conversation may be gone by the end of it, and a basket confirmed with an unavailable line becomes a failed order or a short delivery.
Check availability in the same turn as the write, using the tools in Catalog integration and real-time inventory checks. Two moments need it: before adding or increasing a line, and again at confirmation for the whole basket.
Enforce limits in your service, before writing, and reject the whole operation rather than partially applying it:
| Limit | Where it comes from | What the agent should say |
|---|---|---|
Per-line maximum | Fair-use policy or stock | The maximum, and how many are already in the basket |
Basket maximum | Fulfilment or payment constraints | The limit, and the current item count |
Regulatory maximum | Law, for restricted products | That a limit applies, without inviting a workaround |
Available stock | Live inventory | How many can be supplied now |
Compute the headroom in your service and return it in the rejection. An agent given the maximum, the current quantity, and the requested quantity produces a useful sentence; an agent given only “rejected” produces an apology and a retry of the same call.
Never write part of a request. A shopper asking for twelve when eight are permitted should end up with the eight they already had and a clear message, not with eight new ones and an unclear one.
Where else this applies. All-or-nothing writes matter more in conversation than in a form, because the shopper cannot see what happened. A partial write in a chat thread is invisible, and the shopper discovers it at checkout or at delivery.
Confirm the basket
The basket phase ends with an explicit confirmation. Read the cart, present it in full, and wait for a yes.
Present it as text rather than as a UI component. A basket is a list of lines with quantities and prices, which reads better as text than as cards, and it needs to be scannable in the thread the shopper will scroll back to.
Include, from the read rather than from memory: every line with quantity and line total, the subtotal, any discount, and the item count. State anything that is not yet included — delivery, taxes applied at checkout — so the number the shopper agrees to is not smaller than the one they are later asked to pay.
Wait for an unambiguous yes. “That looks about right” is not a confirmation, and neither is silence. Ask again rather than proceeding.
Re-read and re-validate the basket at this point even if nothing has changed since the last read. Confirmation is the moment the basket becomes an order, and it should be based on the state at that moment.
Test the agent
Use Agent test to simulate conversations before going live. Pass
conversation_id to continue a multi-turn exchange.curl -X POST "https://api.facebook.com/{entity_id}/agent_test" \
-H "Authorization: Bearer {ACCESS_TOKEN}" \
-H "Content-Type: application/json" \
-H "X-API-Version: 2.0.0" \
-d '{
"user_msg": "Add two tins of the chopped tomatoes and a bag of the arborio rice"
}'
Cover these scenarios in your test plan:
| Scenario | Sample message |
|---|---|
Several items in one message | “Two tins of tomatoes and a bag of arborio rice” |
No quantity given | “Add the olive oil” |
Change quantity by setting | “Make the tomatoes three” |
Change quantity by adding | “Add two more tins” |
Ambiguous reference | “Take off the oil” with two oils in the basket |
Removal by description | “Get rid of the rice” |
Per-line limit exceeded | A quantity above your per-line maximum |
Basket limit exceeded | Enough lines to cross the basket maximum |
Item goes out of stock mid-basket | Make a line unavailable between turns |
Discount code accepted and rejected | Both paths |
Total requested mid-basket | “What’s that come to?” |
Long gap then a change | Resume after the session would expire |
Confirmation declined | “No, that’s not right” |
Rows three through seven are where cart flows actually break. Ambiguous references and the add-versus-set distinction account for most wrong baskets, and neither shows up if you only test a clean sequence of additions.
Where else this applies. Test a cart by trying to confuse it rather than by filling it. A basket built by adding five distinct items in five clear turns will work on the first attempt; the failures live in revisions, ambiguity, and time passing.
Example conversation
This exchange shows the configuration above in use: the agent asks for a quantity rather than assuming, distinguishes setting from adding, resolves an ambiguous product reference, reports a limit with the numbers, and confirms from a fresh read.
Shopper: Add two tins of chopped tomatoes and a bag of the arborio rice
Agent:(calls
get_cart, add_cart_item, get_cart, add_cart_item, get_cart)Added. Your basket is now two tins of chopped tomatoes at 1.20 each and one 500g arborio rice at 3.40 — 5.80 for three items.
Shopper: Make the tomatoes six
Agent:(calls
get_cart, update_cart_item, get_cart)Done — six tins of chopped tomatoes, 7.20. Basket total 10.60 for seven items.
Shopper: Add some olive oil
Agent: How many, and which one — the everyday 1L at 6.50 or the single estate 500ml at 11.00?
Shopper: One of the everyday ones
Agent:(calls
get_cart, add_cart_item, get_cart)Added. Basket total 17.10 for eight items.
Shopper: Actually make it twenty tins of tomatoes
Agent:(calls
get_cart, update_cart_item)I can’t go that high — there’s a limit of twelve tins per order and you have six. Shall I take you up to twelve?
Shopper: Yes. And take off the oil
Agent:(calls
get_cart, update_cart_item, get_cart, remove_cart_item, get_cart)Tomatoes are now twelve, and the everyday olive oil is removed. Your basket is twelve tins of chopped tomatoes at 14.40 and one 500g arborio rice at 3.40 — 17.80 for thirteen items. Delivery is added at checkout. Shall I confirm this basket?
Monitor connector health
The connector logs endpoint,
GET /{entity_id}/agent_connectors/{connector_id}/logs, reports how your cart service is answering.curl -X GET "https://api.facebook.com/{entity_id}/agent_connectors/{connector_id}/logs?summary_only=true&top_n=5&include_stats=true" \
-H "Authorization: Bearer {ACCESS_TOKEN}" \
-H "X-API-Version: 2.0.0"
Logs cover the last seven days, and the requested time range cannot exceed seven days. The response carries two objects:
| Object | Field | What it reports |
|---|---|---|
data | failure_code_name | The failure category |
data | error_message | The message returned by your endpoint |
data | tool_name | Which tool made the call |
data | occurrences | How many times this failure appeared |
stats | success_rate | Share of calls that succeeded |
stats | avg_latency_s | Mean round-trip time in seconds |
stats | p95_latency_s | 95th percentile round-trip time in seconds |
stats | p99_latency_s | 99th percentile round-trip time in seconds |
get_cart is called several times per turn, so it dominates the connector’s totals and will mask a failing mutation. Filter with tool_id and read each write tool separately.Two ratios are worth tracking outside these logs. Limit rejections per basket rising means your limits are too tight or the agent is not reading them back usefully. Baskets confirmed against baskets started falling after a change usually points at a mutation that is failing quietly rather than at a pricing problem.
Watch
p95_latency_s on get_cart closely. Because it runs before and after every change, its latency is paid two or three times per turn, and a slow cart read is felt as a slow agent throughout the conversation.Where else this applies. When one tool is called an order of magnitude more often than its siblings, connector-level success rate becomes meaningless. Alert per tool wherever a read dominates the call mix.
Tips for this use case
These are the cart decisions that most often go wrong once the agent is live.
Keep the cart in your system. A basket reconstructed from conversation will be plausible and wrong, usually by one quantity.
Read before and after every write. The read after is what the shopper hears, and it is the only way they can see what happened.
Separate add from set, loudly. “Make it three” against “add three” is the most common wrong write in the flow. Put the distinction in both tool descriptions.
Never assume a quantity of one. Ask. Assuming is fine on a web page with a visible quantity field and wrong in a thread where nothing is visible.
Address lines by a stable
line_id from the current read. Position changes and SKUs repeat.Reject whole operations, never part of one. A partial write in a chat thread is invisible until delivery.
Return the headroom with a rejection. The maximum, the current quantity, and the requested one make a useful sentence; “rejected” makes an apology and a retry.
Do not let the agent do arithmetic. Return subtotal, discount, and item count from your service and have the agent read them out.
Confirm ambiguous removals. An incorrectly removed line is silent, and it surfaces at delivery.
Re-validate at confirmation. Availability moves during a ten-minute basket, and confirmation is when the basket becomes a commitment.
Say what is not included. Delivery and taxes added later turn an agreed total into a disputed one.
Summary checklist
Confirm each of the following before you enable the agent on a production phone number.
- Held the cart in your own service, keyed on the session rather than the phone number
- Added a
cart-managementinstruction that forbids describing the basket from memory - Forbade the agent from computing totals
- Defined
get_cart,add_cart_item,update_cart_item,remove_cart_item, andapply_discount_code - Set
user_auth_requiredtotrueon every cart tool - Documented the add-versus-set distinction in both mutation tool descriptions
- Returned a stable
line_idper line and required it from the current read - Returned subtotal, discount, and item count from
get_cart - Enforced per-line, per-basket, and regulatory limits server-side before writing
- Made limit rejections return the maximum and the current quantity
- Confirmed no operation can be partially applied
- Rejected a quantity of zero on update rather than treating it as a removal
- Sent discount codes unmodified and reported only the reason the service gave
- Re-validated availability for the whole basket at confirmation
- Required an explicit yes before leaving the basket phase
- Stated what is not yet included in the total
- Tested ambiguous references, add-versus-set, limits, stock loss mid-basket, and declined confirmation
- Set up per-tool monitoring so
get_cartvolume does not mask a failing mutation