Shopkeeper Routines

A shop's weekly routines that run on their own where the evidence holds: each step acts, asks the owner, or stays quiet and says why, decided by Aito's lift and the number of past cases behind it.

Shopkeeper Routines: screenshot from the E-commerce demo
🛒 E-commerce_predict_recommend_estimateE-commerceCross-vertical
In the demoIn the e-commerce demo's weekly win-back run, the routine went through the 20 customers most likely to leave: it acted on 4, expecting €67 more than doing nothing, queued 5 for the owner and stayed quiet on 11. One quiet case: an apology with a €5 credit looked 28 points more likely to bring the customer back, but only 1 past case matched that exact situation and the shop's rule asks for 10. The run is simulated and nothing is sent.

The problem

A webshop is made of thousands of small decisions: who to win back and with what, what to reorder, what to mark down. The owner has time for a few of them a week, so most get made by a fixed rule or not at all. Handing them to an agent is tempting, but most routines don't need a model that reasons. They need a calculation that can be trusted, and a routine with no grip on the shop's data guesses. A confident guess is the most expensive kind of mistake.

What lets a routine run on its own is not capability. It is knowing, for each step, how sure it is and how much evidence that rests on, and having a rule that turns that into act, ask or wait.

How it works

The shopkeeper's routines are rules on the same database the shop's screens use. For win-back, each at-risk customer's actions (an email, a discount, a voucher, a personalised ad, an apology) are scored with _predict: the chance of an order after the action against doing nothing, times the order value, minus the action's cost. The best action and its lift go to a gate, which decides in a fixed order: 1) if nothing beats doing nothing after its cost, stay quiet; 2) if fewer than 10 past rows match this customer's exact situation and action, stay quiet and say so; 3) if the action is one the shop always sends through a person (discounts, vouchers, apologies), queue it; 4) with a lift of 15 points or more, act; 5) with 5 to 15 points, propose it for one-click approval; 6) below that, stay quiet.

The thresholds are the shop's settings, not the model's. The same gate runs a stock check beside win-back. The shop's levers are also exposed as tools an agent can call, running the same code as the screens, so an agent and the owner see the same answer with the same evidence. A model that reads and writes comes in only where a rule can't, such as writing a new product's text.

# The shop's gate, run on every proposed step (first rule that applies wins)
if best_action == "none":            quiet  # nothing beats doing nothing
elif net_eur <= 0:                   quiet  # not worth its cost
elif matching_rows < 10:             quiet  # too little evidence, says why
elif best_action in never_auto:      ask    # always through a person
elif lift >= 0.15:                   act
elif lift >= 0.05:                   ask    # owner approves with one click
else:                                quiet

For the full architecture, see the technology overview. For the broader narrative across multiple use cases, read The Predictive Application. For the whole picture, see predictive e-commerce.

See it live

This use case runs in the 🛒 E-commerce demo today. Click through to the live application and inspect the queries that produce the result.

Open the live demo →

Build it with Claude Code

Paste this prompt into Claude Code, or another coding agent, in your own codebase. It runs Aito locally from the Docker image, reads the API docs written for agents, and follows a working reference implementation.

Shopkeeper routines: a prompt for Claude Code
Add shopkeeper routines to this codebase using Aito, a predictive database. The feature: run our weekly shop routines (win-back first) as rules that act, ask the owner or stay quiet, gated on Aito's lift over doing nothing and the number of past cases behind it.

1. Run Aito locally: `docker pull ghcr.io/aitohq/aito`, then follow https://aito.ai/docker/ to start it with your own API keys (keep them in the environment, never in code).
2. Read https://aito.ai/docs/api/llms.txt for the v2 query shapes before writing any query.
3. Read the use-case guide: https://aito.ai/use-cases/shopkeeper-routines/
4. Use this reference implementation as the pattern (schema, data load and queries): https://github.com/AitoDotAI/aito-ecommerce-demo/blob/main/src/shopkeeper_gate.py and https://github.com/AitoDotAI/aito-ecommerce-demo/blob/main/src/retention_actions.py
5. Find the matching tables in this codebase, design the Aito schema for them (links between tables where we have foreign keys), and load a sample.
6. Measure before switching anything on: from our past actions, compare the outcome with and without the action, and report the lift and how many cases it rests on.
7. Act only when the lift over doing nothing clears the action's cost and enough past cases back it; otherwise ask me or do nothing. Log every decision with its numbers.

Ask me before changing anything outside the new feature.

Frequently asked

Is this an AI agent?

No, and that is the point. The routine is a calculation: the same data gives the same answer, and every step shows its lift, its euros and the rows behind it. A language model adds cost and variance where a calculation is good enough. In the demo, agents are used where a rule can't do the job, and the shop's tools are open to them with the same evidence attached.

Why stay quiet on a customer when the predicted lift is large?

Because a large lift on one or two matching past cases is a guess. The gate asks for a minimum number of past rows that match the customer's exact situation and the action. Below it, the routine holds off and says how many cases it found, so the owner can decide or wait for more evidence.

Can the shop change the thresholds?

Yes. The act bar, the propose bar, the minimum evidence and the kinds of action that always go to a person are the shop's settings. A cautious shop raises the bars; a shop with a lot of history can lower them.

What happens to the steps that act?

In the demo the run is simulated and nothing is sent. In a deployment, the step that acts calls the shop's email, ad or offer system, and every decision is stored with its inputs so later runs can be checked against what actually happened.