← Lesson
What Is an AI Agent?
Joeven
Run
Reset
Python loads on first run
goal = "have_umbrella_if_rain" world = {"raining": True, "has_umbrella": False} def observe(world): # Sensors: copy what the agent is allowed to see. return dict(world) def act(world, action): # Actuators: only this verb can change the world. if action == "take_umbrella": world["has_umbrella"] = True return world def policy(obs, goal): # The brain. Later this can call an LLM. Today it is an if. if goal == "have_umbrella_if_rain": if obs["raining"] and not obs["has_umbrella"]: return "take_umbrella" return "stop" def goal_met(world, goal): if goal != "have_umbrella_if_rain": return False if world["raining"]: return world["has_umbrella"] is True return True obs = observe(world) steps = 0 while steps < 5: action = policy(obs, goal) print("obs:", obs, "-> action:", action) if action == "stop": break world = act(world, action) obs = observe(world) steps = steps + 1 print("done:", world) print("steps used:", steps) print("goal met:", goal_met(world, goal))
Run to execute this in your browser. Nothing is sent to a server.