#!/usr/bin/env python3
"""AAE Lab 02: deterministic simulation of observe-decide-act."""

state = {
    "goal": "Is this machine running low on disk space?",
    "disk_percent_used": None,
    "finished": False,
}

def observe(state):
    if state["disk_percent_used"] is None:
        return {"goal": state["goal"]}
    return {"goal": state["goal"], "disk_percent_used": state["disk_percent_used"]}

def decide(observation):
    if "disk_percent_used" not in observation:
        return {"kind": "tool", "tool": "get_disk_usage"}
    used = observation["disk_percent_used"]
    return {
        "kind": "answer",
        "answer": f"Disk usage is {used}%. " + ("Investigate disk pressure." if used >= 85 else "Disk usage is within this lab's threshold.")
    }

def act(decision, state):
    if decision["kind"] == "tool":
        print("ACT: get_disk_usage()")
        state["disk_percent_used"] = 87  # deterministic fixture
    else:
        print("ANSWER:", decision["answer"])
        state["finished"] = True

print("AAE Lab 02 — observe → decide → act\n")
turn = 0
while not state["finished"] and turn < 4:
    turn += 1
    obs = observe(state)
    print(f"TURN {turn} OBSERVE:", obs)
    decision = decide(obs)
    print(f"TURN {turn} DECIDE:", decision)
    act(decision, state)
    print()

assert state["finished"]
print("✓ Loop terminated successfully.")
