#!/usr/bin/env python3
"""AAE Lab 04: explicit working state vs conversation text."""

def next_action(state: dict) -> str:
    if not state.get("host"):
        return "ASK_HOST"
    if not state.get("service"):
        return "ASK_SERVICE"
    return f"CHECK_SERVICE host={state['host']} service={state['service']}"

print("AAE Lab 04 — state & memory\n")

state = {"goal": "investigate service", "host": "web01", "service": None}
print("Initial state:", state)
print("Next:", next_action(state))

state["service"] = "nginx"
print("\nAfter learner says 'nginx':", state)
print("Next:", next_action(state))

assert next_action(state) == "CHECK_SERVICE host=web01 service=nginx"
print("✓ Required working state preserved.")

print("\nBreak it deliberately: delete the host.")
broken = dict(state)
broken.pop("host")
print("Broken state:", broken)
print("Next:", next_action(broken))
assert next_action(broken) == "ASK_HOST"
print("✓ Failure reproduced: the task lost required working state.")

print("\nDurable memory is intentionally NOT used in this lab.")
