Esta página fue traducida por una máquina y aún no ha sido revisada por una persona. El inglés es la referencia; las correcciones son bienvenidas en GitHub. GitHub

Cookwala / SDK y escenarios / 040

Start an execution and read its status as it advances

Send the example ExecuteRequest to the reference hub with a person in the kitchen, then read the status a few seconds later and see the sequence number and the first step that needs a person.

Audiencia: developer · Objetivo: Robots para las personas · Nivel: beginner

Leer primero: /docs/CORE/ /docs/HUB/

Pasos

  1. Read the capability document of the device behind the hub: one counter arm that cuts, cracks and transfers, with a vision sensor and no heat source. capabilities

  2. Start the example request for shakshuka. The hub dry-runs the recipe first and answers with an ExecutionStatus at seq 0 that carries the plan. startExecution

  3. The hub used by the runner simulates time at 200x. The arm dices the onion, pepper and tomato, then reaches the first step a person must perform.

  4. Read the status: seq has advanced (the ETag header carries the same number) and the device waits for a person to heat the pan. getExecution

  5. The status names the request it answers; the recipe reference and hash are in that request and in the execution log.

Resultado

You have started a run, read its status and seen that a device with no heat source hands heating to the person present. Next: scenario 041 stops a run and reads its log; 042 resumes one.

Línea de comandos

cookwala hub --recipes examples --speed 200
jq '. + {"x-hub-human-present": true}' examples/core/execute-request.json | curl -s -X POST http://localhost:7878/v1/executions -H 'Content-Type: application/json' -H 'Idempotency-Key: ex-2026-10-04-001-a' -d @-
curl -si http://localhost:7878/v1/executions/ex-2026-10-04-001

Salida grabada

Estado: ok

[1] capabilities: {"cookwala": "0.1.0", "actor": {"kind": "robot", "id": "robot:arm-1", "vendor": "Example Robotics", "model": "CounterArm 2"}, "roles": ["executor"], "location": {"zone": "counter-left", "mobile": false}, "capabilities": {"ops": [{"op": "cw.op.cut", "params": {"shape": ["dice", "slice", "mince", "julienne"]}, "ingredientClasses": ["cw.ing.class.vegetable_firm", "cw.ing.class.herb"], "reliability": 0.97}, {"op": "cw.op.crack", "reliability": 0.95}, {"op": "cw.op.transfer", "maxMassG": 3000}], "sensors": [{"sensor": "cw.sense.vision", "visionCues": ["cw.sense.translucent", "cw.sense.egg_whites_se…
[2] startExecution: {"core": "0.2.0", "kind": "ExecutionStatus", "id": "ex-2026-10-04-001", "seq": 0, "state": "accepted", "request": "ex-2026-10-04-001", "updatedAt": "2026-10-07T00:54:07Z", "x-hub-plan": [{"node": "n1", "op": "cw.op.cut", "by": "device", "verifiedBy": "sensor", "rung": "cw.sense.vision"}, {"node": "n2", "op": "cw.op.cut", "by": "device", "verifiedBy": "sensor", "rung": "cw.sense.vision"}, {"node": "n3", "op": "cw.op.cut", "by": "device", "verifiedBy": "sensor", "rung": "cw.sense.vision"}, {"node": "n4", "op": "cw.op.heat", "by": "human", "verifiedBy": "human"}, {"node": "n5", "op": "cw.op.saute…
[4] getExecution: {"core": "0.2.0", "kind": "ExecutionStatus", "id": "ex-2026-10-04-001", "seq": 6, "state": "needs_human", "request": "ex-2026-10-04-001", "updatedAt": "2026-10-07T00:54:10Z", "x-hub-plan": [{"node": "n1", "op": "cw.op.cut", "by": "device", "verifiedBy": "sensor", "rung": "cw.sense.vision"}, {"node": "n2", "op": "cw.op.cut", "by": "device", "verifiedBy": "sensor", "rung": "cw.sense.vision"}, {"node": "n3", "op": "cw.op.cut", "by": "device", "verifiedBy": "sensor", "rung": "cw.sense.vision"}, {"node": "n4", "op": "cw.op.heat", "by": "human", "verifiedBy": "human"}, {"node": "n5", "op": "cw.op.sa…

Código

Ejecutar: python scenarios/out/040-start-an-execution-and-read-its-status/python.py

# Scenario 040: Start an execution and read its status as it advances
# Send the example ExecuteRequest to the reference hub with a person in the kitchen, then read the status a few seconds later and see the sequence number and the first step that needs a person.
# 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: Read the capability document of the device behind the hub: one counter arm that cuts, cracks and transfers, with a vision sensor and no heat source.
hub = c.capabilities()
assert pick(hub, "actor.model") == "CounterArm 2", pick(hub, "actor.model")
print("ok", "actor.model", "=", "CounterArm 2")
assert pick(hub, "actor.kind") == "robot", pick(hub, "actor.kind")
print("ok", "actor.kind", "=", "robot")
assert pick(hub, "capabilities.ops.length") == 3, pick(hub, "capabilities.ops.length")
print("ok", "capabilities.ops.length", "=", 3)

# Step 2: Start the example request for shakshuka. The hub dry-runs the recipe first and answers with an ExecutionStatus at seq 0 that carries the plan.
try:
    started = c.start_execution(load("examples/core/execute-request.json"), "ex-2026-10-04-001-a", True)
except CookwalaProblem as p:
    started = p.body  # a refusal is a result, not a crash
    print("refused:", p.refusal)
assert pick(started, "state") == "accepted", pick(started, "state")
print("ok", "state", "=", "accepted")
assert pick(started, "seq") == 0, pick(started, "seq")
print("ok", "seq", "=", 0)
assert pick(started, "id") == "ex-2026-10-04-001", pick(started, "id")
print("ok", "id", "=", "ex-2026-10-04-001")
assert pick(started, "x-hub-plan.length") == 13, pick(started, "x-hub-plan.length")
print("ok", "x-hub-plan.length", "=", 13)

# Step 3: The hub used by the runner simulates time at 200x. The arm dices the onion, pepper and tomato, then reaches the first step a person must perform.
import time; time.sleep(4)

# Step 4: Read the status: seq has advanced (the ETag header carries the same number) and the device waits for a person to heat the pan.
status = c.get_execution("ex-2026-10-04-001")
assert pick(status, "state") == "needs_human", pick(status, "state")
print("ok", "state", "=", "needs_human")
assert pick(status, "seq") == 6, pick(status, "seq")
print("ok", "seq", "=", 6)
assert pick(status, "humanNeeded.why") == "a person performs cw.op.heat", pick(status, "humanNeeded.why")
print("ok", "humanNeeded.why", "=", "a person performs cw.op.heat")
assert pick(status, "step.progress") == 1.0, pick(status, "step.progress")
print("ok", "step.progress", "=", 1.0)

# Step 5: The status names the request it answers; the recipe reference and hash are in that request and in the execution log.
assert pick(status, "request") == "ex-2026-10-04-001", pick(status, "request")
print("ok", "request", "=", "ex-2026-10-04-001")
assert pick(status, "kind") == "ExecutionStatus", pick(status, "kind")
print("ok", "kind", "=", "ExecutionStatus")

print("scenario complete")

scenarios/040-start-an-execution-and-read-its-status.json

Anterior: 039 Siguiente: 041