Cette page a été traduite par une machine et n'a pas encore été révisée par une personne. L'anglais est la référence ; les corrections sont les bienvenues sur GitHub. GitHub
Cookwala / SDK et scénarios / 001
A dry run refuses koshari on a robot with no oil thermometer
See the standard's first rule in action: before anything heats up, a device checks every step and refuses what it cannot verify. Deep frying has exactly one rung on its sensor ladder, an oil thermometer.
Lire d'abord: /docs/CORE/ /docs/QUICKSTART/
Étapes
Ask the hub which recipes it can plan; the example set includes koshari.
listRecipesDry-run koshari on a kitchen robot that has a hob but no thermometers. A person is in the kitchen, so cutting and sautéing may run.
dryRunSame recipe on a robot with an oil thermometer: accepted, with a plan that says which rung verifies each step.
dryRunThe accepted plan still has every step; nothing was skipped to make it pass.
Résultat
You have seen a refusal with a reason and a node id, and an acceptance with a plan. Next: scenario 002 shows the same check from a browser, and scenario 010 adds a person-absent run.
Ligne de commande
cookwala dryrun examples/koshari.cookwala.json --device examples/capabilities/demo-hob-robot-basic.json --human-present
cookwala dryrun examples/koshari.cookwala.json --device examples/capabilities/demo-fryer-robot.json --human-presentSortie enregistrée
Statut: ok
[1] listRecipes: {"recipes": ["basbousa", "ful-medames", "kofta-oven", "koshari", "lentil-soup", "molokhia", "rice-vermicelli", "salata-baladi", "shakshuka"]}
[2] dryRun: {"state": "refused", "refusal": {"reason": "missing_sensor_no_fallback", "node": "n14", "detail": "no way to verify cw.op.deep_fry on this device"}, "plan": [{"node": "n1", "op": "cw.op.boil", "by": "device", "verifiedBy": "model", "rung": "model"}, {"node": "n2", "op": "cw.op.simmer", "by": "device", "verifiedBy": "model", "rung": "model"}, {"node": "n3", "op": "cw.op.drain", "by": "device", "verifiedBy": "time", "rung": "time"}, {"node": "n4", "op": "cw.op.boil", "by": "device", "verifiedBy": "model", "rung": "model"}, {"node": "n5", "op": "cw.op.boil", "by": "device", "verifiedBy": "model",…
[3] dryRun: {"state": "accepted", "plan": [{"node": "n1", "op": "cw.op.boil", "by": "device", "verifiedBy": "sensor", "rung": "cw.sense.liquid_temp"}, {"node": "n2", "op": "cw.op.simmer", "by": "device", "verifiedBy": "sensor", "rung": "cw.sense.liquid_temp"}, {"node": "n3", "op": "cw.op.drain", "by": "device", "verifiedBy": "time", "rung": "time"}, {"node": "n4", "op": "cw.op.boil", "by": "device", "verifiedBy": "sensor", "rung": "cw.sense.liquid_temp"}, {"node": "n5", "op": "cw.op.boil", "by": "device", "verifiedBy": "sensor", "rung": "cw.sense.liquid_temp"}, {"node": "n6", "op": "cw.op.drain", "by": "d…Code
Exécuter: python scenarios/out/001-dry-run-refuses-without-oil-thermometer/python.py
# Scenario 001: A dry run refuses koshari on a robot with no oil thermometer
# See the standard's first rule in action: before anything heats up, a device checks every step and refuses what it cannot verify. Deep frying has exactly one rung on its sensor ladder, an oil thermometer.
# Run a hub first: python hub/cookwala_hub.py --recipes examples
import json, os
from cookwala.client import CookwalaClient, CookwalaProblem
def load(path):
with open(path, encoding="utf-8") as f:
return json.load(f)
def pick(obj, path):
for part in path.replace("]", "").replace("[", ".").split("."):
obj = obj[int(part)] if part.isdigit() else (len(obj) if part == "length" else obj.get(part))
return obj
c = CookwalaClient(os.environ.get("COOKWALA_HUB", "http://localhost:7878"))
# Step 1: Ask the hub which recipes it can plan; the example set includes koshari.
recipes = c.list_recipes()
assert pick(recipes, "recipes.length") == 9, pick(recipes, "recipes.length")
print("ok", "recipes.length", "=", 9)
# Step 2: Dry-run koshari on a kitchen robot that has a hob but no thermometers. A person is in the kitchen, so cutting and sautéing may run.
basic = c.dry_run(recipe_id="koshari", device_id="demo-hob-robot-basic", human_present=True)
assert pick(basic, "state") == "refused", pick(basic, "state")
print("ok", "state", "=", "refused")
assert pick(basic, "refusal.reason") == "missing_sensor_no_fallback", pick(basic, "refusal.reason")
print("ok", "refusal.reason", "=", "missing_sensor_no_fallback")
assert pick(basic, "refusal.node") == "n14", pick(basic, "refusal.node")
print("ok", "refusal.node", "=", "n14")
# Step 3: Same recipe on a robot with an oil thermometer: accepted, with a plan that says which rung verifies each step.
fryer = c.dry_run(recipe_id="koshari", device_id="demo-fryer-robot", human_present=True)
assert pick(fryer, "state") == "accepted", pick(fryer, "state")
print("ok", "state", "=", "accepted")
# Step 4: The accepted plan still has every step; nothing was skipped to make it pass.
assert pick(fryer, "plan.length") == 20, pick(fryer, "plan.length")
print("ok", "plan.length", "=", 20)
print("scenario complete")