Free self-study · No account needed · Progress stays in this browser. Back it up before clearing site data or changing devices.

← Week 9: Agent Fundamentals

Week 09 / Lesson 3

Planning bounded actions

Use a plan to guide observations while checking authorization at execution.

Section 3.1 1 of 7

Overview

Focus

Use a plan to guide observations while checking authorization at execution.

Your route through the lesson

  • 3.2 Plans and observable subgoals
  • 3.3 Read operations, mutations, and irreversible effects
  • 3.4 Revising a plan and choosing a deterministic workflow
  • 3.5 Put it into practice
  • 3.6 Guided comparison
  • 3.7 An eligibility change during execution

All required teaching is included here. Review selections are saved. Choose a correct answer for every question to continue; retries are unlimited. Study time and personal notes are optional.

Section 3.2 2 of 7

Plans and observable subgoals

Focus

Write plans as observable subgoals with dependencies and stopping conditions.

A plan is a proposed sequence of subgoals, not a record of completed work. A useful subgoal has an observable result. “Understand the account” is vague; “read the current subscription and its cancellation eligibility” names evidence the program can check. Dependencies state what must be known before a later step is valid.

For a cancellation request, a bounded plan is: identify the requested subscription, read current eligibility, verify the user’s authority, execute an authorized cancellation in the simulator, and inspect the returned status. The mutation depends on the earlier checks. The plan also says what happens if eligibility is false or authority is missing: stop without mutation.

Planning can improve coordination, but it does not create permissions. A model might propose “cancel all related subscriptions” even though the user requested only one. The executor rejects that widened action. Keep the user’s actual goal and allowed scope alongside the plan so later observations can revise the steps without quietly redefining the task.

// Quick review

Check your understanding.

Choose an answer for immediate feedback. Retry freely; a correct answer for every question unlocks the next section.

1. Which subgoal has an observable result?
2. A plan expands “cancel subscription A” to “cancel every related subscription.” What should control execution?
3. Eligibility is false at the first check. What should the bounded plan do?

Section 3.3 3 of 7

Read operations, mutations, and irreversible effects

Focus

Separate reads from mutations and check permission at the executor.

A read observes state; a mutation changes it. Reading cancellation eligibility is different from canceling a subscription. An irreversible effect, such as sending an external notice, can be impossible to undo completely even if a database field is later restored. The execution boundary must distinguish these operations.

In the harmless local simulator, read_eligibility returns a record without changing it. cancel checks the authenticated actor’s permission, the requested subscription, current eligibility, and the expected version before altering state. A read-only actor is denied even if a model proposes a perfectly formed cancellation.

Authorization belongs where the effect occurs. Hiding the cancel tool from the model can reduce accidental proposals, but the server still checks the caller when a request arrives. Otherwise a malformed client or a future interface could bypass the hidden menu. The lab changes only an in-memory synthetic subscription, so it teaches these checks without affecting any real account. Its safety is part of the exercise design, not evidence that real mutations can ignore permissions.

// Quick review

Check your understanding.

Choose an answer for immediate feedback. Retry freely; a correct answer for every question unlocks the next section.

1. A read-only actor proposes a valid cancellation for an eligible subscription. What should the executor do?
2. Why recheck permission on the server even if the user interface hides a mutation button?
3. Why can sending a notice require special care beyond changing a local field?

Section 3.4 4 of 7

Revising a plan and choosing a deterministic workflow

Focus

Revise a plan when observations invalidate its assumptions.

Plans are conditional on the state observed so far. If eligibility changes before execution, the old plan may no longer apply. The executor must revalidate current preconditions at the mutation boundary rather than relying only on the earlier read. Expected versions help detect that state changed between planning and acting.

Suppose subscription S is eligible at version 4. Before cancel executes, a scheduled renewal creates version 5 and makes it ineligible. A cancellation carrying expected version 4 is rejected. The agent records the changed observation and explains that the planned cancellation did not occur. It may propose a newly authorized alternative, but it cannot relabel the rejection as success.

Some tasks need no open-ended planner. A cancellation process with known checks can be an explicit deterministic workflow whose branches depend on returned values. A model may still interpret the initial request or explain results. Choose the flexible component narrowly, keeping sensitive transitions and completion checks explicit. This reduces the number of ways a plausible plan can drift away from valid execution.

// Quick review

Check your understanding.

Choose an answer for immediate feedback. Retry freely; a correct answer for every question unlocks the next section.

1. Eligibility was true at version 4 but false at version 5 before mutation. Which check prevents stale execution?
2. A cancellation is rejected after an eligibility change. What should the agent report?
3. A process always follows known eligibility and permission checks. Which architecture is reasonable?

Section 3.5 5 of 7

Put it into practice

Focus

Exercise authorized, denied, ineligible, and changed-state cancellation paths locally.

Save week09.py in your exercise folder and run python week09.py --lesson 3. The lab uses a synthetic subscription object with eligible, active, and version fields. It exercises a permitted cancellation, a read-only denial, an ineligible request, and a state change between read and mutation. No account or real subscription is touched.

Python dictionaries can represent the simulator’s state. A copy makes a separate shallow dictionary, sufficient here because the fixture values are simple numbers and booleans. The following complete example shows the version precondition:

subscription = {"eligible": True, "active": True, "version": 4}
observed = subscription.copy()
subscription["version"] = 5
subscription["eligible"] = False
assert observed["version"] != subscription["version"]
assert subscription["active"] is True

The weekly cancel function checks these conditions before changing active. Expected output confirms exactly one permitted effect and zero effects in the three denied paths. The scripted plan demonstrates runtime control and observation handling; it does not demonstrate a model’s planning quality.

Download this week’s Python lab ↓

// Quick review

Check your understanding.

Choose an answer for immediate feedback. Retry freely; a correct answer for every question unlocks the next section.

1. A subscription starts with active=True. Its cancellation is rejected before mutation because its version changed. What should active remain?
2. A subscription dictionary contains only booleans and an integer version, with no nested mutable values. Why is a shallow copy sufficient to preserve those observed values?
3. A local simulator passes all cancellation branches. What remains unverified?

Section 3.6 6 of 7

Guided comparison

Focus

Compare effect counts with the observed plan outcome.

The completed authorized trace reads active subscription S, confirms eligibility and version 1, and checks an actor with cancel permission. The executor changes active to false, increments the version, and returns canceled. The final answer can claim cancellation because a completed mutation result exists.

The read-only trace reads the same eligible state, then fails the permission check. Its effect counter remains zero. The ineligible trace stops after observing eligibility false. The changed-state trace notices that the expected version no longer matches and also leaves the effect counter at zero. These traces produce different explanations even though all three end without cancellation.

Recording effect counts is stronger than checking only a final message. A bug might say “denied” after already changing the subscription. The lab therefore asserts both the returned outcome and the unchanged active field for rejected paths. This is a reusable engineering pattern: validate what happened to the world, not just what the agent says happened. In a real service, the corresponding evidence might be a durable operation record and a subsequent authorized status read.

// Quick review

Check your understanding.

Choose an answer for immediate feedback. Retry freely; a correct answer for every question unlocks the next section.

1. A cancellation returns denied but active becomes false. Is the denial path correct?
2. A read-only denial and an ineligible result both have zero effects. Should their reasons be identical?
3. What supports a real-service claim that cancellation completed?

Section 3.7 7 of 7

An eligibility change during execution

Focus

Respond safely when eligibility changes between observation and execution.

A booking assistant reads that reservation R can be canceled without a fee at 14:59. At 15:00 the cancellation window closes. The user had authorized a free cancellation, so a later paid cancellation would be a different operation even if the reservation identifier stays the same.

The completed executor rechecks the current policy and binds the request to the observed version and zero-fee condition. It rejects the old free-cancellation proposal after the window closes. The assistant reports that the authorized operation was not performed because the conditions changed. It can present the newly observed option, including its fee, but cannot silently execute it under the old authorization.

This case combines planning, state freshness, and exact scope. The plan remains useful as an explanation of intended steps, yet current observations determine which steps are still legal. Version checks catch state changes; business-rule checks catch changed meaning; permission checks protect the effect. None of these can be replaced by the model remembering that cancellation was previously eligible.

// Quick review

Check your understanding.

Choose an answer for immediate feedback. Retry freely; a correct answer for every question unlocks the next section.

1. The user authorized a free cancellation, but the current operation charges a fee. What should happen?
2. Why check both version and business rules at execution?
3. The free cancellation is rejected after the deadline. Which completion statement is accurate?

Your personal notes

Optional, ungraded, and saved only in this browser. Export a backup from the Academy homepage to keep them.

References and further reading
Ask your own AI assistant

Copy this prompt into an assistant you already use. Nothing is sent automatically, and your personal notes are not included.

Next lesson: Defining and registering tools →