# Market Basket Agent **An AI agent that prices a grocery list across every open store on Yemeksepeti Market, picks the cheapest *net* basket, fills that store's cart — and stops before checkout.** A case study in turning a model capability (browser control) into something a person actually uses weekly. Built and run against my own live Yemeksepeti account. Three live runs, all numbers below are measured, not estimated. --- ## The problem Yemeksepeti Market shows you one store at a time. To know where a basket is actually cheapest you would have to price the same list in four stores, then adjust each subtotal for delivery fee, plastic-bag fee, minimum-basket rules, Pro-subscription thresholds and whichever coupon happens to apply. Nobody does this. So people default to the store they used last time. The gap turned out to be much larger than I expected. **Same four-item list, same address, same morning:** | Store | Subtotal | Coverage | |---|---|---| | BİM | **204,00 TL** | full | | Y-Market Kavaklı | 293,92 TL | 2 items missing | | Oğuz Market | 373,49 TL | full | | Uğur Seç Market | 464,00 TL | full | **2.3× spread on milk, eggs, pasta and bread.** That spread is the entire product. *(Subtotals only. Net adds delivery, bag fee and any minimum-basket gap, minus coupons — the agent ranks on net, not on this column.)* --- ## Who it's for Me, first — that's the honest answer, and it's why the failure modes below are real rather than imagined. The generalisation is any household that orders groceries through a delivery aggregator and has no way to see across stores. --- ## What I decided *not* to build **It never places the order.** The agent's job ends at a filled cart with the coupon applied. The human clicks the last button. This was the first decision and I'd make it again. An agent that spends your money on a mistake it made three steps earlier destroys the trust that makes it useful at all. Stopping one click early costs the user two seconds and buys the whole feature its licence to operate. The rule is written into the spec as a hard constraint with no exceptions, in three separate places, because the model *will* find the "Sepeti Onayla" button otherwise. Same reasoning produced two more constraints: - **Never touch login forms or credentials.** Not logged in → stop and ask. - **The site's on-screen total is the source of truth.** If the cart disagrees with the agent's own arithmetic, it reports the discrepancy instead of silently trusting itself. An AI feature that quietly wins its own arguments against reality is worse than no feature. --- ## What testing it actually taught me I ran it live three times and each run broke it in a way I had not predicted. **Run 1 — it was slow for a boring reason.** ~120 browser calls, roughly 30% of them spent on avoidable round trips: one action per call, screenshot-wait-scroll-screenshot. Fixed by batching every multi-step interaction into single calls. **Run 2 — adds were lying.** After each page navigation, the first "add to cart" click was silently swallowed — no error, no modal, the item just wasn't there. It happened three times in one run, in open stores with nothing on screen to explain it. I had assumed a successful tool call meant a successful add. Now every single add is verified against the cart sidebar before moving on, and the verification is scoped to the sidebar specifically — checking the whole page text false-positives against the product grid behind it. **Run 3 — the reading method had an accuracy bug, not a speed bug.** I replaced screenshot-reading with direct DOM extraction to save calls. It also found a 17,00 TL pasta where the previous run had picked 23,50 TL. The cheaper item existed the whole time; it was below the fold, and screenshots simply never saw it. **The fast path wasn't just cheaper, it was more correct** — and the old method had been quietly losing the user money on every run without ever failing visibly. That one reframed how I think about testing AI features: the dangerous failures aren't the ones that error out. They're the ones that return a plausible answer. **Other findings that only appear in live use:** multi-word searches return zero results where single words return 59 ("tost ekmeği" → 0, "ekmek" → 59). The SPA needs ~6s before its product list exists, so an immediate read returns an empty page that looks exactly like an empty store. Bag fees are sometimes 1 TL and sometimes 2 TL. I probed the network layer hoping for a clean product API, found only analytics beacons, and wrote the dead end into the spec so I wouldn't waste calls re-probing it later. --- ## Results | | v1 | v3 | |---|---|---| | Browser calls per run | ~120 | target ≤20 | | Product listing read | navigate → wait → scroll → wait → screenshot | one call, full DOM extract | | Below-the-fold items | missed | captured | | Sold-out items | invisible | detected | | Add-to-cart reliability | ~3 silent failures/run | verified per item | --- ## Product decisions worth arguing about **A cheaper incomplete basket is not the winner.** The agent distinguishes "cheapest brand of the same thing" (fine, substitute freely) from "only the premium variant is in stock" or "packaged toast when you asked for a fresh loaf" — those count as *missing*, and a store missing items gets flagged in the table rather than crowned. It surfaces the alternative and its price so the user can override. The temptation to declare a winner by ignoring what's absent is exactly how a comparison tool starts lying. **Sometimes the right answer is to add more to your cart.** BİM enforces a ~298 TL minimum and charges the gap as a completion fee if you're under it — so a 204 TL basket pays the same either way. The agent detects this and recommends filler items up to the gap: same money, more groceries instead of a fee. The same check runs against free-delivery thresholds and coupon minimums, and it only suggests a filler when the net total *strictly* drops. **Closed stores are excluded, not ranked.** A cheaper basket that arrives tomorrow isn't a cheaper basket. **Cached prices never decide anything.** The agent keeps a per-address cache, but it's split by trust level: URLs and product names are navigation hints, prices are history for trend notes only. Every price in a live comparison is read from the live page. The one exception is documented and bounded — a store already 1.7× above the live leader can't change the winner, so it's skipped and clearly labelled as unverified in the output. --- ## What I'd measure if this had real users - **Savings per run vs. the user's default store** — the only number that justifies the product existing. - **Override rate on substitutions.** High override rate means the missing/substitute rule is mis-tuned, and it's the fastest signal I'd get about whether the agent's judgment matches the user's. - **Abandonment at the filled cart.** The agent stops there deliberately, which makes that step a clean funnel measurement: how often does someone see the finished basket and not order? - **Cart-total reconciliation mismatches**, tracked as a correctness metric rather than a bug queue. It's the closest thing to a ground-truth accuracy check the agent has. --- ## Repo contents | File | What it is | |---|---| | [`SKILL.md`](SKILL.md) | The agent spec — the actual prompt, in phases, with the hard rules and failure modes | | [`reference.md`](reference.md) | Living navigation notes for the site, corrected after every run | | [`preferences.md`](preferences.md) | User-editable config: pinned brands, banned items, store rules, filler candidates | | [`cache.example.md`](cache.example.md) | Redacted example of the run cache — store hints and price history | Written as a [Claude Code skill](https://docs.claude.com/en/docs/claude-code/skills). It drives a real logged-in browser session; there is no API. The real `cache.md` is not published — it contains a home delivery address. --- ## Honest limitations Three live runs at one address in one city, all on the same morning. The 2.3× spread is one real measurement, not a study — different neighbourhoods have different store sets and it could easily be smaller elsewhere. The ≤20-call figure is the v3 target from a measured v2 baseline, not yet a confirmed post-change average. Bot-detection is not handled and shouldn't be: if a CAPTCHA appears the agent stops and hands control back.