Practice: the WhatsApp ordering agent¶
Three exercises that build on the labs, then one open build task. Do them in your own copy (a fork) of this repo, commit as you go, and keep short notes.
Read the labs first: bot/core.py, shop/matching.py, bot/confirm.py, 02_sku_matching.py, 04_confirm_in_code.py, 07_evals.py, 08_extract_then_code.py.
Where your work goes:
- Code changes: in
shop/,bot/andtest_bot.py; new eval cases ingolden.json. - Your own files:
my-work/in this folder. - Notes:
my-work/whatsapp-agent.md. For each exercise, a few lines on what you changed, why, and what you would do differently in production.
Some rules below say Decide. Make the choice yourself and write it in your notes.
If your team gave you an ASSIGNMENTS.md, it makes those choices for you: follow it.
ex1: A new region, measured¶
Why: stores in Maharashtra, Gujarat or Tamil Nadu don't type like stores in Delhi. The words you have least data for break quietly.
- Add 8 cases to
golden.json(G26 onwards) in one new flavour, for example Marathi-Hinglish: other unit words ("goni" for a bag), number words, local product names. Give each the expected cart and a new tag. - Run them before any change:
python 07_evals.py --extract G26 G27 .... List the misses in your notes, each with its cause: synonym, unit, number, or the model. - Fix in code first (
SYNONYMS,UNIT_WORDS,parse_quantity()); change a prompt only when code can't fix it. - Run all the cases again: none of the first 25 may get worse.
- Decide: a word that means different products in two regions: ask the customer, or pick by the customer's city?
- Add model-free tests for every new word to
test_bot.py.
Done when pytest -q passes and your notes have the score on your 8 cases before and after, and on all cases after.
ex2: Minimum order and delivery day¶
Why: business rules belong in code, shown on the card and enforced again at the tap, because time passes between the two.
- Add
MIN_ORDER(₹) and a daily cut-off hour toshop/. A cart below the minimum gets a card without a Confirm button and a note saying how much more to add;confirm()refuses it too (an old card can still be tapped). - The card shows the delivery date: before the cut-off, the next day; after it, the day after; never a Sunday.
confirm()works out the date again at the tap; if it changed, the customer gets a new card, as when a price moves.- Pass the current time in as a parameter, so tests don't depend on the clock.
- Decide: does the minimum apply to pay-now orders as well as credit orders?
- Add model-free tests for each rule.
Done when pytest -q passes, including your new tests.
ex3: How fragile is it?¶
Why: the evals run at temperature 0, so every run is the same. Before a launch, find the cases that pass only by luck.
- Create
my-work/robustness.py: run every golden case 3 times withrun_case(case, mode="extract", chat=functools.partial(door.achat, temperature=0.7)). Put the run underif __name__ == "__main__":so importing the file does not call the model. - Print, per case, how many of the 3 runs passed, and list the cases that flipped.
- Pick one flipping case, find the cause with
-vin07_evals.py, fix it in code and run again. - Decide: your launch gate: every case 3 out of 3, or a pass rate over all runs? Write down what each would have blocked.
Done when the script runs and your notes have the flipping cases before and after your fix.
Names these exercises build on¶
Please keep these names as they are. In bot/: Bot, Session, confirm, cart_card, route_message, RULES, run_case, score_case, extract_order, apply_intent. In shop/: match_products, parse_quantity, to_base_units, SYNONYMS, UNIT_WORDS, place_order, credit_status, orders_for, handoff. Checks and later topics rely on them.
Build it yourself: damaged-delivery claims¶
No starter code and no steps this time: a short brief, like one you'd get at work. Plan for half a day.
Your code goes in my-work/build/ plus the hooks it needs in bot/ and shop/; reuse the router, sessions, cards and the extract-then-code design rather than copying them. Notes go in a "Build" section of my-work/whatsapp-agent.md.
The brief. Store owners report problems after a delivery: "kal ke order mein 6 bag cement jam gaya", "2 sariya mude hue aaye", sometimes with a photo. Today every complaint goes to a person (lab 06). Build a claims flow in the same chat, so simple claims are filed in a minute and only the rest reach a person.
It must:
- Send claim messages to a claims route (rules first, then the model) that sees only claim tools.
- Collect the order (or offer the customer's recent orders), product, quantity and issue, asking one question at a time for whatever is missing.
- Never accept a claimed quantity above what was delivered for that product (code).
- Show a claim card with Submit, Change and Cancel buttons, with a claim ID and version like the cart; Submit runs code and files the claim once, however many times it is tapped.
- Send claims above a ₹ limit, or a second claim from the same store within 30 days, to a person with a handoff ticket.
- Keep a photo, if one is sent, with the claim. Reading it with the vision model is optional.
Decide: the ₹ limit. What does the store owner hear after Submit: a credit note now, or after an inspection?
Done when:
pytest -q my-work/buildpasses with model-free tests: the quantity rule, Submit filed once, and the handoff rules.- At least 10 claim messages (Hinglish included) with expected claims are scored in code, and your notes have the score.
- The flow works in the web chat, and your notes describe one miss you fixed in code.
Or bring your own problem. Build the same pattern on a problem from your own work instead. Write a five-line brief first (who uses it, what goes in, what comes out, what must never go wrong, how you'll measure it), then meet the same "Done when" list. Use synthetic data only, never real customer data.