BATNA iconBATNA.dev

Grocery Cart Agent

Automating grocery delivery by separating the jobs to be done

I subscribed to a meal kit for a while, but was frustrated with the strict weekly format and the lack of being able to cook a big batch meal.

Grocery delivery is a service that exists, but assembling web carts feels like it can take almost as long as going to the store and shopping with a physical cart.

But it's 2026 🙂

I started by pointing Codex at the Whole Foods website through Playwright, but it was slow! So I shifted more of the responsibilities to the deterministic playwright harness, and simplified the generative decision responsibilities to simply taking in just the available items and returning which product to buy.

From a systems perspective, I separated responsibilities into different agents:

  • Job 0 — Recipe creation (Punted): You can paste in your favorite recipes or ask your own chatbot to generate them for you.
  • Job 1 — Turning recipes into a shopping list: Consolidating repeated ingredients across multiple meals and showing a checklist to skip items already in your pantry.
  • Job 2 — Doing the shopping: Given a shopping list, the harness fills the cart based on the model's inference.

Get the source at palmeryan/grocery-cart-agent.

I did some light hardening, but it does expose your agent to the web, so use at your own risk. Also amazon may or may not be happy about this sort of automation. Enjoy!

Grocery Cart Agent Architecture

Job 0: Recipe Source (External)
Generative Decisions (Sandboxed)
Deterministic Code (Compiler & Harness)
User Checkpoints (Review & Checkout)
Storefront (Chrome CDP & Cart API)
Job 0 — Recipe Creation
Recipe creation punted
We're not generating recipes. Find a recipe and paste it in.
Job 1 — Recipes → Shopping List
Ingredients Agent
Extracts identities, amounts, and prep notes. No browser tools.
Review shopping list
TUI review of shopping list so you can remove anything in your pantry already (e.g. olive oil).
Ingredients agent hands off validated shopping list
Whole Foods Storefront
Job 2 — Doing the Shopping (Playwright Harness)
Generative decisions
Sandboxed profile with Whole Foods login
search
query
extract
cards
1Page Search & Ingredient Extraction
Harness searches the store and extracts ASINs, titles, prices, and availability into clean JSON.
cards +
context
Decision Inference
Takes in the page context, the current ingredient, and recipe context.
targeted
click
2Act
Validates choice against visible results; clicks Add / Quantity / Variant via CDP.
select(id, qty)
retry / skip
Structured Decision
Tells playwright which ingredient to add to cart or to search again.
sniff POST
response
3Check
Confirms the quantity delta from the API response before advancing to the next item.
final
check
4Repeat until done
Confirms final cart contents and lets user review before checkout.
all items added to cart
Final Hand-Off — Manual Checkout
5Review & Place Order
Come back to a full cart, review items, pick a delivery window, and complete checkout manually.