AI agent that drafts. You approve.
An AI agent reads order emails and PDFs, checks stock and drafts the order, a low stock flag and a reply. Nothing is saved until a person clicks Approve. Every tool call is logged.
The business and all its data are made up. The run in the video is real.
In the video
The PDF asks for 12 caramel syrup and only 9 are in stock. The agent leaves it off and flags it. I approve the order and the flag (orders 18 to 19, cups 30 to 25) and reject the reply.
What I checked
- All 12 emails: drafts as expected on 12 of 12.
- The agent changed nothing in the database. Its connection is read-only.
- Reject saved nothing. Approve took exactly the ordered amounts off stock.
After the run

All 12 emails
Model: gemini-3.8-flash.
| Drafted | As expected | |
|---|---|---|
| Order for this week | order: 20 x CB-ESP-1K, 4 x CUP-12-1000; reply | yes |
| PO 2291 attached (PDF) | order: 10 x CB-FIL-1K, 6 x SYR-VAN-750, 3 x SUG-STK-1000; reply | yes |
| Decaf top up | order: 15 x CB-DEC-1K, 2 x SUG-STK-1000; low stock flag: CB-DEC-1K; reply | yes |
| Order 0457 (PDF) | order: 5 x CUP-8-1000; low stock flag: SYR-CAR-750; reply | yes |
| Delivery day? | reply | yes |
| New customer, first order | reply | yes |
| the usual | reply | yes |
| Double your cafe foot traffic in 30 days | nothing (marketing email) | yes |
| Tea order (PO 118) (PDF) | order: 30 x TEA-EB-100, 2 x NAP-2PLY-2000; low stock flag: TEA-GRN-100; reply | yes |
| Change to yesterday's order | reply | yes |
| Order please | order: 8 x CB-ESP-1K, 2 x CUP-8-1000, 4 x MLK-OAT-6; reply | yes |
| Invoice copy | reply | yes |
The only code that saves
def approve(draft_id):
"""Write one approved draft to the ERP, in one transaction. Stock is checked again at this moment."""
d = _draft(draft_id)
if d["status"] != "pending":
raise ValueError(f"draft {draft_id} is already {d['status']}")
p = json.loads(d["payload"])
erp = sqlite3.connect(ERP, timeout=10)
try:
with erp:
if d["kind"] == "create_order":
for line in p["lines"]:
stock = erp.execute("SELECT stock FROM products WHERE sku = ?", (line["sku"],)).fetchone()[0]
if stock < line["qty"]:
raise ValueError(f"not enough stock now for {line['sku']}: {stock} left, {line['qty']} asked")
oid = erp.execute("SELECT MAX(id) + 1 FROM orders").fetchone()[0]
erp.execute("INSERT INTO orders VALUES (?,?,?,?,?)", (oid, p["customer_id"], now()[:10], "new", f"email {d['email_id']}"))
for line in p["lines"]:
price = erp.execute("SELECT price FROM products WHERE sku = ?", (line["sku"],)).fetchone()[0]
erp.execute("INSERT INTO order_items VALUES (?,?,?,?)", (oid, line["sku"], line["qty"], price))
erp.execute("UPDATE products SET stock = stock - ? WHERE sku = ?", (line["qty"], line["sku"]))
result = f"Order {oid} written, stock reduced."
elif d["kind"] == "flag_low_stock":
fid = erp.execute("INSERT INTO stock_flags (sku, needed_qty, note, created_on) VALUES (?,?,?,?)",
(p["sku"], p["needed_qty"], p["note"], now()[:10])).lastrowid
result = f"Low stock flag {fid} written for {p['sku']}."
else:
mid = erp.execute("INSERT INTO outbox (to_addr, subject, body, created_on) VALUES (?,?,?,?)",
(p["to"], p["subject"], p["body"], now()[:10])).lastrowid
result = f"Reply {mid} put in the outbox."
finally:
erp.close()
return _decide(draft_id, "approved", result)