Cookwala / SDK and scenarios / 088

Your home as a grocer, a neighbour's robot and an insurer would see it

Run the same twelve household facts through three recipient roles and count what each receives: five constraints, three, none. No value ever appears: a budget cap is a cap, not your income.

Audience: home cook · Goal: Make people healthier, Robots for people · Level: beginner

Read first: /docs/HOUSEHOLD-CONTEXT/ /trust/

Steps

  1. The grocer: allergen block, labelling, delivery window, access point, budget cap. deriveConstraints

  2. A second robot: no-movement zone, pet-safe storage, available equipment. deriveConstraints

  3. An insurer: nothing from this household, which has no device fault facet. deriveConstraints

  4. In every answer the disclosed list is empty: no raw fact travelled to anyone.

Outcome

You can see, for any role, what leaves your home before it leaves. Next: 089 follows one allergy to two different recipients.

Command line

cookwala constraints examples/household/context.json --role grocer
cookwala constraints examples/household/context.json --role other_robot
cookwala constraints examples/household/context.json --role insurer

Recorded output

Status: ok

[1] deriveConstraints: {"constraints": [{"type": "allergen_block", "derivedFrom": ["cw.facet.household.health.allergies"]}, {"type": "labeling_required", "derivedFrom": ["cw.facet.household.health.allergies"]}, {"type": "delivery_window", "derivedFrom": ["cw.facet.commerce.receiving_rules"]}, {"type": "access_point", "derivedFrom": ["cw.facet.commerce.receiving_rules"]}, {"type": "budget_cap", "derivedFrom": ["cw.facet.household.economics.budget_posture"]}], "disclosed": [], "withheld": [{"facet": "cw.facet.household.health.diets", "reason": "not_allowed_for_role"}, {"facet": "cw.facet.household.health.medications",…
[2] deriveConstraints: {"constraints": [{"type": "no_movement_zone", "derivedFrom": ["cw.facet.household.people.schedule", "cw.facet.space.environment.foot_traffic"]}, {"type": "pet_safe_storage", "derivedFrom": ["cw.facet.household.pets.animals"]}, {"type": "equipment_available", "derivedFrom": ["cw.facet.space.appliances"]}], "disclosed": [], "withheld": [{"facet": "cw.facet.household.health.allergies", "reason": "not_allowed_for_role"}, {"facet": "cw.facet.household.health.diets", "reason": "not_allowed_for_role"}, {"facet": "cw.facet.household.health.medications", "reason": "not_allowed_for_role"}, {"facet": "cw…
[3] deriveConstraints: {"constraints": [], "disclosed": [], "withheld": [{"facet": "cw.facet.household.health.allergies", "reason": "not_allowed_for_role"}, {"facet": "cw.facet.household.health.diets", "reason": "not_allowed_for_role"}, {"facet": "cw.facet.household.health.medications", "reason": "not_allowed_for_role"}, {"facet": "cw.facet.household.people.schedule", "reason": "not_allowed_for_role"}, {"facet": "cw.facet.space.environment.foot_traffic", "reason": "not_allowed_for_role"}, {"facet": "cw.facet.household.pets.animals", "reason": "not_allowed_for_role"}, {"facet": "cw.facet.commerce.receiving_rules", "r…

Code

Run: python scenarios/out/088-your-home-seen-by-three-roles/python.py

# Scenario 088: Your home as a grocer, a neighbour's robot and an insurer would see it
# Run the same twelve household facts through three recipient roles and count what each receives: five constraints, three, none. No value ever appears: a budget cap is a cap, not your income.
# 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: The grocer: allergen block, labelling, delivery window, access point, budget cap.
grocer = c.derive_constraints(pick(load("examples/household/context.json"), "facets"), "grocer")
assert pick(grocer, "constraints.length") == 5, pick(grocer, "constraints.length")
print("ok", "constraints.length", "=", 5)
assert pick(grocer, "withheld.length") == 9, pick(grocer, "withheld.length")
print("ok", "withheld.length", "=", 9)

# Step 2: A second robot: no-movement zone, pet-safe storage, available equipment.
robot = c.derive_constraints(pick(load("examples/household/context.json"), "facets"), "other_robot")
assert pick(robot, "constraints.length") == 3, pick(robot, "constraints.length")
print("ok", "constraints.length", "=", 3)
assert pick(robot, "withheld.length") == 8, pick(robot, "withheld.length")
print("ok", "withheld.length", "=", 8)

# Step 3: An insurer: nothing from this household, which has no device fault facet.
insurer = c.derive_constraints(pick(load("examples/household/context.json"), "facets"), "insurer")
assert pick(insurer, "constraints.length") == 0, pick(insurer, "constraints.length")
print("ok", "constraints.length", "=", 0)
assert pick(insurer, "withheld.length") == 12, pick(insurer, "withheld.length")
print("ok", "withheld.length", "=", 12)

# Step 4: In every answer the disclosed list is empty: no raw fact travelled to anyone.
assert pick(grocer, "disclosed.length") == 0, pick(grocer, "disclosed.length")
print("ok", "disclosed.length", "=", 0)
assert pick(robot, "disclosed.length") == 0, pick(robot, "disclosed.length")
print("ok", "disclosed.length", "=", 0)
assert pick(insurer, "disclosed.length") == 0, pick(insurer, "disclosed.length")
print("ok", "disclosed.length", "=", 0)
assert pick(grocer, "constraints[4].type") == "budget_cap", pick(grocer, "constraints[4].type")
print("ok", "constraints[4].type", "=", "budget_cap")

print("scenario complete")

scenarios/088-your-home-seen-by-three-roles.json

Previous: 087 Next: 089