Aller au contenu principal

Terre & Table (démo)

La promesse. Une épicerie fine fictive : on parcourt le catalogue librement, on compose sa sélection de produits et un créneau de livraison ; pour commander, on se connecte par un code, et on confirme. L'agent ne commande jamais à sa place.

La source. L'API publique de la démo, terre-et-table.convoy-ai.com (sa spec : /openapi.json, ses pages : /docs) : produits, stock, créneaux, vérification et devis de livraison, commandes, et sa propre vérification par code. Elle ne relit jamais une commande à personne. C'est un des deux modèles de la Console : on le publie tel quel.

Le parcours​

  1. Parcourir, librement : products cherche dans le catalogue et montre chaque produit avec son prix et sa photo ; personne n'a besoin d'être connecté pour regarder ni pour choisir.
  2. Choisir la livraison : delivery demande où livrer, vérifie que Terre & Table y livre (le check de l'API) et remplace le prix du créneau par son devis (update) ; un créneau ne se choisit qu'une fois des produits choisis.
  3. Se connecter pour commander : passer la commande demande d'être connecté. La personne reçoit un code envoyé par Terre & Table à son e-mail (pour la démo, les codes s'affichent sur terre-et-table.convoy-ai.com/demo/inbox) ; l'agent ne voit ni l'e-mail ni le code (Connecter par un code).
  4. Confirmer : la personne confirme sa sélection ; la commande part alors, une clé d'idempotence par commande. Une station n'est jamais à l'origine d'une commande sans cette confirmation (Décider qui soumet).

Sa config​

terre-et-table.yaml
# Terre & Table: your own shop station on Terre & Table's demo API, ready to publish as it is.
#
# Terre & Table is a fictional French delicatessen whose API is public for you to build on:
# https://terre-et-table.convoy-ai.com (its OpenAPI: /openapi.json, its pages: /docs). It has
# products, stock, delivery windows, a delivery check and quote, POST /orders, and a sign-in by
# one-time code. It never reads an order back to anyone: what others filed stays private.
#
# What this station does, in order:
# 1. `products` searches the catalogue and shows each product with its price and picture;
# 2. `delivery` asks where to deliver, checks Terre & Table delivers there (`check`), prices the
# slot (`update`), then files the order on Terre & Table's API (`submit`);
# 3. to file it, the person SIGNS IN, then confirms (`submit_guard`): browsing and choosing are
# open to anyone, the order is a signed-in person's own act, and the assistant never orders.
# It speaks French and English: the person's own language when it is one of them.
#
# To try it, sign in with any @example.com address (Terre & Table's demo sends no e-mail and accepts
# only those), with the code shown at https://terre-et-table.convoy-ai.com/demo/inbox.
#
# Then try its POLICIES: the rules Convoy applies whatever the model says. One is on (each person's
# orders per day): see it on the station's Policies tab. Another example is below as a comment,
# ready to enable: remove the « # » of the lines it says, check, publish. A new version each time: roll back from the Versions tab, watch the
# effect in Analytics.

station:
id: my-shop # Convoy sets this to your station's name when you publish
name: Terre & Table
# Signing in: a one-time code to the person's e-mail, sent and checked by Terre & Table's own
# operations. The address signed in is the order's (`customer_email`, the delivery form's field
# marked `identifies`): no one files an order under someone else's address.
identity:
providers:
email:
mechanism: otp
verifies: customer_email
via: tenant
send: sendVerificationCode
check: checkVerificationCode
# Policies for the whole station, each cited by its name (defined under `policies:` below).
# `at: submit`: judged on every line the submit would send, before the person's confirmation.
policies:
- {policy: orders-per-day, at: submit}

global:
language: fr # the default, when the person speaks neither of the station's languages
languages: [fr, en]
currency: EUR
locale: fr-FR

domain:
domain_type: retail
entity_name: product
entity_name_plural: products

voice:
tone: friendly
persona: "a delicatessen assistant, warm and precise about where each product comes from"
rules:
- "Never invent a price, an origin or a stock level: ask the API."
- "Say plainly when a product is out of stock, and offer an alternative."
- "Check the delivery area BEFORE proposing a slot."
emoji: false

# Terre & Table's API. Three entries on one API with different operations: what reads, what
# writes and what signs in are separated, so the boundary shows in the config instead of being
# implied. No key: this API is open (filing an order and the sign-in are rate-limited).
apis:
- name: catalogue
openapi_url: "https://terre-et-table.convoy-ai.com/openapi.json"
base_url: "https://terre-et-table.convoy-ai.com"
operations:
- {id: searchProducts, access: read}
- {id: getDeliveryWindows, access: read}
auth: {type: none}

- name: orders
openapi_url: "https://terre-et-table.convoy-ai.com/openapi.json"
base_url: "https://terre-et-table.convoy-ai.com"
operations:
- {id: checkDeliverable, access: read}
- {id: quoteDelivery, access: read}
- {id: placeOrder, access: write}
auth: {type: none}

- name: identity
openapi_url: "https://terre-et-table.convoy-ai.com/openapi.json"
base_url: "https://terre-et-table.convoy-ai.com"
operations:
- {id: sendVerificationCode, access: write}
- {id: checkVerificationCode, access: write}
auth: {type: none}

# Who may call what. Closed by default: an operation no profile grants is called for no one.
# Anyone browses, chooses and is quoted a delivery; only a signed-in person files an order. Asked
# before that, Convoy has them sign in, then files it.
profiles:
anonymous:
when: "$identity.authenticated == false"
grants:
- catalogue.searchProducts
- catalogue.getDeliveryWindows
- orders.checkDeliverable
- orders.quoteDelivery
signed-in:
when: "$identity.authenticated"
grants:
- catalogue.searchProducts
- catalogue.getDeliveryWindows
- orders.checkDeliverable
- orders.quoteDelivery
- orders.placeOrder

# Reusable policies: written once here, cited by name where they apply (a skill's `select.guards`,
# or `station.policies` above). A policy nobody cites is refused when the config loads.
policies:
# ON. Each person's orders per day: at most 3. Each delivery slot filed is one order (`when`),
# `count: true` counts it once, and `scope: identity` counts per signed-in person, whatever the
# conversation; the day starts at 00:00 UTC. The fourth order is held before the confirm, and
# the person reads `reason`. Try `mode: observe`: it refuses nothing and writes in the journal
# what it would have refused.
orders-per-day:
budget: {count: true, per: day, scope: identity, max: 3}
when: "$item.kind == 'slot'"
reason: "three orders a day per person; come back tomorrow"

skills:
- name: products
cognitive:
objective: "help the person put together a selection of products, by taste and budget"
diagnose: [the kind of product, the budget, any dietary preference]
# What the model may give: the person's words, a category and the page. Each may be left
# out, and the API's own default applies.
params:
q: {type: text, set_by: [llm], required: false}
category: {type: text, set_by: [llm], required: false}
limit: {type: integer, set_by: [llm], required: false}
offset: {type: integer, set_by: [llm], required: false}
invoke:
method: searchProducts
args: {q: "$params.q", category: "$params.category", limit: "$params.limit", offset: "$params.offset"}
kinds: {product: {}}
# How a result is drawn: its name, its price, its picture. `from` is the API's own field.
present:
fields:
name: {from: name, type: text, role: title}
price: {from: price, type: price, role: billed}
image: {from: image_url, type: image}
# OFF. A cap per product line: at most 6 of each. To enable it, uncomment the next 2 lines.
# select:
# quantity: {max: 6}
render: {component: carousel}

- name: delivery
cognitive:
objective: "confirm Terre & Table delivers to the person, then offer a delivery slot"
diagnose: [the region, the postcode, the slot wanted]
params:
region: {type: text, set_by: [llm]}
invoke: {method: getDeliveryWindows, args: {region: "$params.region"}}
kinds: {slot: {}}
# A slot only makes sense once products are chosen: choosing products first is enforced.
depends_on: {products: {on_loss: clear}}
present:
fields:
name: {from: label, type: text, role: title}
select:
max_items: 1
guards:
# The form the person fills (its labels are one text: the shop's French); the submit below
# reads these fields back as `$item.fields.*`.
- form:
region: {type: text, required: true, label: "Région", enum: [lyon, grenoble, valence, paris]}
postcode: {type: text, required: true, label: "Code postal"}
customer_name: {type: text, required: true, label: "Nom du destinataire"}
customer_email: {type: email, required: true, label: "E-mail de confirmation", identifies: true}
customer_address: {type: text, required: true, label: "Adresse de livraison"}
# `check` asks Terre & Table whether it delivers there; the person is told if not.
- check: checkDeliverable
# `update` replaces the slot's price by Terre & Table's quote.
- update: {price: quoteDelivery}
# The order itself, filed on the person's confirm. A dotted key builds the API's nested body.
submit:
- name: placeOrder
mode: request
tool: placeOrder
args:
body.items: "$selection[kind=product]"
body.region: "$item.fields.region"
body.window: "$item.ref"
body.delivery_fee: "$item.price"
body.customer.name: "$item.fields.customer_name"
body.customer.email: "$item.fields.customer_email"
body.customer.address: "$item.fields.customer_address"
body.customer.postcode: "$item.fields.postcode"
# One key per person and order: a retry reuses it, so an order is never filed twice.
body.idempotency_key: "$action.key"
# Terre & Table's order line is `{slug, quantity}`: how a selected product becomes one.
line:
slug: "$line.ref"
quantity: "$line.quantity"
render: {component: cards}

# The order of a complete purchase: products, then a slot. Both are required.
playbooks:
- name: place-an-order
goal: "Put together a selection of products, then choose a delivery slot."
activation: {when: "true"}
tasks:
products:
skill: products
required: true
delivery:
skill: delivery
required: true
after: [products] # a slot comes once products are chosen: the steps show it in this order

# Who submits. The person in the conversation, with their own click (`confirm`): the assistant never
# files an order. And only the room's owner, SIGNED IN (`submitted_by`): holding the conversation's
# code is not enough to order in someone's name.
submit_guard:
confirm: true
submitted_by: [{who: owner}]