Policies and agent types
A policy is a rule for choosing an action from the information available to an agent. It may map an observation or an internal state to an action, or assign probabilities to actions. Our simplest policy stops if the goal is reached, moves right when clear, and otherwise stops. The policy is deterministic and uses no training.
Four agent designs
A simple reflex agent selects actions using the current observation. A model-based reflex agent updates an internal description of the world from observations, previous actions and a model; for example, it can remember a previously seen barrier. A goal-based agent considers possible future states to find actions that reach a specified goal. A utility-based agent evaluates how desirable outcomes are, for example choosing among routes using both travel time and energy. Under uncertain outcomes it may compare expected utility. These are useful design categories, not a required progression; combinations are possible. A learning agent can improve its behavior from experience, but learning is not required by any of these four categories.
Write a reflex policy
The policy uses the two Boolean fields from the previous lesson. Goal detection takes priority over movement: even if another tile is clear, it should stop when it has arrived.
def policy(observation): if observation["at_goal"]: return "stop" if observation["right_clear"]: return "right" return "stop"
print(policy({"at_goal": False, "right_clear": True}))print(policy({"at_goal": False, "right_clear": False}))print(policy({"at_goal": True, "right_clear": True}))The printed actions are right, stop, stop. The last result demonstrates why condition order matters. Reversing the conditions could cause the robot to move away from the goal. The policy itself neither changes the grid nor checks that a real action is authorized.
Bound execution and report why it ended
A runner joins observation, policy and transition in a loop. The example below inlines the same reflex decisions for readability. It counts successful right moves, stops on a blocked observation and checks the goal before moving again. The maximum move budget is an integer from 0 to 100; zero is allowed. The grid and coordinates obey the previous lesson’s contract. A trace records the initial position and each subsequent successful move. At budget exhaustion, success still takes precedence if the goal was just reached. Otherwise the status is budget, even if the next tile happens to be blocked, because no next decision was attempted.
def run(grid, start, goal, max_steps): if not 0 <= max_steps <= 100: raise ValueError("Step budget must be between 0 and 100") x, y = start trace = [start] for _ in range(max_steps): if (x, y) == goal: return trace, "goal" if x + 1 >= len(grid[y]) or grid[y][x + 1] == "#": return trace, "blocked" x += 1 trace.append((x, y)) if (x, y) == goal: return trace, "goal" return trace, "budget"
grid = ["...", ".#."]print(run(grid, (0, 0), (2, 0), 2))print(run(grid, (0, 1), (2, 0), 4))print(run(grid, (0, 0), (2, 0), 1))The first run visits (0,0), (1,0), (2,0) and reports goal. The second remains at (0,1) and reports blocked. The third reaches (1,0) and reports budget. With a zero budget, the runner returns the initial position and reports goal only when it already matches the destination. This is a simulated environment; no actual robot or external tool is controlled.
Compare alternatives using a blocked route
From (0,1), a path to (2,0) exists: up, right, right. The right-only reflex policy cannot discover it. For an agent allowed to move up, down, left and right, a goal-based planner could use a map to find that route; systematic search is introduced in the next chapter. If two successful routes take 3 and 5 moves, and the objective is to minimize moves with equal safety and no other cost, prefer the 3-move route. If the shorter route has high energy cost, a utility-based comparison may prefer the longer one. A toy score 10 - moves - energy_cost for successful routes gives 2 for 3 moves and cost 5, and 4 for 5 moves and cost 1. Failure must be evaluated separately under this illustrative rule; a high numeric score cannot override a safety constraint.
Bounded autonomy is not unrestricted permission
Classical agents can select actions without an LLM. An LLM-based agent may propose tool calls, but a separate controller must validate arguments, permissions and limits before any effect. For example, a simulated library assistant may look up a fictional catalog, but a request to alter real customer records is outside the lab scope. Keep the available actions explicitly allowlisted, cap steps, log outcomes and require appropriate human review before consequential operations. A step cap prevents an endless loop; it does not by itself make an agent safe.
Practice and next steps
Trace a right-only run starting at (1,0), targeting (2,0) with one allowed move. Then trace a run from (0,1) with a zero budget. Explain why the first is goal and the second is budget, not blocked. Propose an extra observation that would help an agent recognize a detour, and explain why information alone is not a planning algorithm. Next: State spaces, problem formulation and graphs.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Policies and agent types — understanding check
Apply agent and environment concepts to the fictional grid world.
What action does policy return when at_goal and right_clear are both True?
Which reflex-agent design explicitly updates an internal world description using prior observations and actions?
Why does the right-only policy stop at (0, 1) even though the map contains a path to (2, 0)?
For the lesson map, what status does run(grid, (0, 0), (2, 0), 2) return alongside its trace?
Which control should determine whether an agent’s proposed external tool call may execute?