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 / 081

A meal-planning agent receives eleven constraints and zero facts

An AI planner is the role that may receive the most constraint types. Derive them and see that two facts about one household member (a medication and a schedule) collapse into one serve window with no times, no drug and no name.

Audience: agent builder · Objectif: Des robots pour les gens, Rendre les gens en meilleure santé · Niveau: intermediate

Lire d'abord: /docs/HOUSEHOLD-CONTEXT/ /trust/ /docs/CORE/

Étapes

  1. Derive the planner's constraints from the example household. deriveConstraints

  2. The serve window is derived from two facets at once, the medication timing and the household schedule; the agent learns a window exists, not why.

  3. Only two facets are withheld from a planner: the receiving rules (a grocer's business, not a planner's) and the firmware (consented, and no grant names a planner).

  4. The same medication facet alone: it yields an avoid-ingredient rule and a serve window, and the facet's free text about timing never leaves. deriveConstraints

Résultat

Your planning agent can be built against DerivedConstraint documents only, which is also what the kitchen agent-safety benchmark expects. Next: 096 shows why recipe text is data for the same agent.

Ligne de commande

cookwala constraints examples/household/context.json --role planner
jq '.roles.planner' profiles/household/recipient-roles.json

Sortie enregistrée

Statut: ok

[1] deriveConstraints: {"constraints": [{"type": "allergen_block", "derivedFrom": ["cw.facet.household.health.allergies"]}, {"type": "diet_rule", "derivedFrom": ["cw.facet.household.health.diets"]}, {"type": "avoid_ingredient", "derivedFrom": ["cw.facet.household.health.medications"]}, {"type": "serve_window", "derivedFrom": ["cw.facet.household.health.medications", "cw.facet.household.people.schedule"]}, {"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"]}, {"ty…
[4] deriveConstraints: {"constraints": [{"type": "avoid_ingredient", "derivedFrom": ["cw.facet.household.health.medications"]}, {"type": "serve_window", "derivedFrom": ["cw.facet.household.health.medications"]}], "disclosed": [], "withheld": []}

Code

Exécuter: python scenarios/out/081-meal-planner-gets-constraints-not-facts/python.py

# Scenario 081: A meal-planning agent receives eleven constraints and zero facts
# An AI planner is the role that may receive the most constraint types. Derive them and see that two facts about one household member (a medication and a schedule) collapse into one serve window with no times, no drug and no name.
# 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: Derive the planner's constraints from the example household.
planner = c.derive_constraints(pick(load("examples/household/context.json"), "facets"), "planner")
assert pick(planner, "constraints.length") == 11, pick(planner, "constraints.length")
print("ok", "constraints.length", "=", 11)
assert pick(planner, "disclosed.length") == 0, pick(planner, "disclosed.length")
print("ok", "disclosed.length", "=", 0)
assert pick(planner, "withheld.length") == 2, pick(planner, "withheld.length")
print("ok", "withheld.length", "=", 2)
assert pick(planner, "constraints[0].type") == "allergen_block", pick(planner, "constraints[0].type")
print("ok", "constraints[0].type", "=", "allergen_block")
assert pick(planner, "constraints[1].type") == "diet_rule", pick(planner, "constraints[1].type")
print("ok", "constraints[1].type", "=", "diet_rule")
assert pick(planner, "constraints[2].type") == "avoid_ingredient", pick(planner, "constraints[2].type")
print("ok", "constraints[2].type", "=", "avoid_ingredient")

# Step 2: The serve window is derived from two facets at once, the medication timing and the household schedule; the agent learns a window exists, not why.
assert pick(planner, "constraints[3].type") == "serve_window", pick(planner, "constraints[3].type")
print("ok", "constraints[3].type", "=", "serve_window")
assert pick(planner, "constraints[3].derivedFrom") == ["cw.facet.household.health.medications", "cw.facet.household.people.schedule"], pick(planner, "constraints[3].derivedFrom")
print("ok", "constraints[3].derivedFrom", "=", ["cw.facet.household.health.medications", "cw.facet.household.people.schedule"])

# Step 3: Only two facets are withheld from a planner: the receiving rules (a grocer's business, not a planner's) and the firmware (consented, and no grant names a planner).
assert pick(planner, "withheld[0].facet") == "cw.facet.commerce.receiving_rules", pick(planner, "withheld[0].facet")
print("ok", "withheld[0].facet", "=", "cw.facet.commerce.receiving_rules")
assert pick(planner, "withheld[0].reason") == "not_allowed_for_role", pick(planner, "withheld[0].reason")
print("ok", "withheld[0].reason", "=", "not_allowed_for_role")
assert pick(planner, "withheld[1].facet") == "cw.facet.self.firmware", pick(planner, "withheld[1].facet")
print("ok", "withheld[1].facet", "=", "cw.facet.self.firmware")
assert pick(planner, "withheld[1].reason") == "no_consent", pick(planner, "withheld[1].reason")
print("ok", "withheld[1].reason", "=", "no_consent")

# Step 4: The same medication facet alone: it yields an avoid-ingredient rule and a serve window, and the facet's free text about timing never leaves.
meds = c.derive_constraints([{"facet": "cw.facet.household.health.medications"}], "planner")
assert pick(meds, "constraints.length") == 2, pick(meds, "constraints.length")
print("ok", "constraints.length", "=", 2)
assert pick(meds, "constraints[0].type") == "avoid_ingredient", pick(meds, "constraints[0].type")
print("ok", "constraints[0].type", "=", "avoid_ingredient")
assert pick(meds, "constraints[1].type") == "serve_window", pick(meds, "constraints[1].type")
print("ok", "constraints[1].type", "=", "serve_window")
assert pick(meds, "withheld.length") == 0, pick(meds, "withheld.length")
print("ok", "withheld.length", "=", 0)

print("scenario complete")

scenarios/081-meal-planner-gets-constraints-not-facts.json

Précédent: 080 Suivant: 082