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 1

Building an observe decide act loop

Separate the model’s action proposal from the executor and its observations.

Section 1.1 1 of 7

Overview

Focus

Separate the model’s action proposal from the executor and its observations.

Your route through the lesson

  • 1.2 Workflows and model-selected actions
  • 1.3 Proposals, tool dispatch, and observations
  • 1.4 A small explicit state machine
  • 1.5 Put it into practice
  • 1.6 Guided comparison
  • 1.7 A lookup that has not returned a result

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 1.2 2 of 7

Workflows and model-selected actions

Focus

Distinguish a fixed workflow from a loop in which a model selects the next action.

An agent is a program that selects actions using observations while pursuing a goal. The model can propose the next step; the surrounding program controls execution. A deterministic workflow follows predefined transitions. An agent loop allows more of the next-action choice to depend on model output. Both still need explicit state, permissions, and failure handling.

Consider a service-status assistant. A workflow always validates a service name, looks it up, and displays the result. A model-selected loop might choose between reading service status and retrieving a maintenance note, depending on the request. The extra flexibility can help varied requests, but it introduces invalid proposals, repeated calls, and unsupported conclusions.

A loop is not automatically superior. If the task always requires the same two calls in the same order, a workflow is easier to test and bound. Use model selection where interpretation or changing evidence actually matters. The lab begins with one supplied read-only lookup, so the distinction can be observed without needing a tool registry or a complex framework.

// Quick review

Check your understanding.

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

1. Every request must validate a service name, perform one lookup, then display it. Which design is easiest to bound?
2. A model selects whether to inspect a maintenance note after reading a status result. What makes this agent-like?
3. The lab uses one supplied validated lookup rather than a registry. Can it still teach an agent loop?

Section 1.3 3 of 7

Proposals, tool dispatch, and observations

Focus

Treat model output as a proposal and tool output as an observation.

A proposal is a structured suggestion such as {"action": "lookup", "service": "mail"}. It is not evidence that a lookup happened. The dispatcher validates the proposal, checks permissions, calls the supplied tool, and records its result. An observation is the returned information or a structured failure, including the request identity needed to connect it to the action.

Suppose the model proposes a mail lookup. The executor records call 4, receives {"status": "ok", "value": "healthy"}, and adds that observation to state. Only then may the system report the observed healthy status. If call 4 times out, the observation is timeout, not healthy. A model’s expectation about what the service probably returns cannot fill the gap.

Keep intent, execution, and observation separate in logs. This supports debugging and prevents a common failure: treating fluent model text saying “I checked” as a successful operation. A deterministic final-answer guard can require an acceptable observed result before allowing any completed-status claim.

// 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 model emits “lookup mail,” but no executor has run. What exists?
2. A tool times out. The model predicts it would have returned healthy. Which observation should be stored?
3. Why attach a call identifier to a tool result?

Section 1.4 4 of 7

A small explicit state machine

Focus

Represent legal agent transitions explicitly rather than relying on narrative text.

A state machine names the states a program may occupy and the transitions between them. For the simple lookup agent, use ready, waiting, observed, completed, and failed. From ready, an accepted lookup moves to waiting. A successful result moves to observed. A final answer based on that result moves to completed. A timeout moves to failed in this first bounded example.

These transitions express invariants. A completed state must contain a successful observation. Waiting means a result is outstanding, so a “done” proposal in that state cannot bypass the result. Unknown actions are rejected instead of being executed as arbitrary Python code.

State can be a dictionary holding status, observations, calls, and outcome. A list preserves the observation order. Explicit state is useful even when a language model is involved, because the program can validate transitions without understanding persuasive natural language. The model proposes; the machine decides whether the proposal is legal in the current state. This keeps completion and failure meanings stable across different model outputs.

// 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 lookup agent is waiting for a tool result. The model proposes done. What should the state machine require?
2. A proposal names an unknown action. Which response preserves a narrow runtime?
3. Why keep observations in an ordered list?

Section 1.5 5 of 7

Put it into practice

Focus

Execute the supplied loop and compare a successful lookup with a timeout.

Save week09.py in your exercise folder and run python week09.py --lesson 1. The standard-library lab uses a read-only synthetic service directory and scripted proposals. It requires no network, credentials, or model download. The scripted proposer is a test double: it makes transitions repeatable without claiming that a real model selected these actions.

Python functions can be passed as values. The runtime calls the proposer with its current state, then validates the returned dictionary. Here dictionary access retrieves a known field, and append records an observation:

state = {"observations": [], "status": "ready"}
result = {"call_id": 1, "status": "ok", "value": "healthy"}
state["observations"].append(result)
state["status"] = "observed"
assert state["observations"][-1]["status"] == "ok"

The index -1 means the last list item. The weekly file supplies the dispatcher and full transitions. Expect one successful observed lookup and a timeout that ends without a success claim. Inspect the trace to see whether every completed result has an actual corresponding observation.

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. In Python, observations[-1] selects which element?
2. A scripted proposer completes the success and timeout fixtures. What has been verified?
3. The timeout fixture ends failed with no successful observation. What final claim is valid?

Section 1.6 6 of 7

Guided comparison

Focus

Read a trace by separating proposed work, accepted work, and confirmed work.

The completed success trace begins ready with no observations. Proposal 1 asks to look up mail. Validation accepts the service name and moves the agent to waiting. The synthetic tool returns healthy, stored as call 1. The runtime moves to observed. Proposal 2 asks to finish, and the guard allows completed because call 1 supplies evidence.

In the timeout trace, the same accepted lookup receives a timeout result. The runtime moves to failed. A later “finish successfully” proposal is rejected because there is no successful observation. Both traces have an attempted call, but only one has a confirmed result. Counting attempts as completed tasks would falsely make their outcomes identical.

The trace records task outcome, proposal count, tool-call count, and termination reason separately. These measurements become more useful when loops grow. A one-call success and a five-call success can have the same task outcome while consuming different resources. A failed task may still have performed useful reads, which should remain visible without being mislabeled as completion.

// Quick review

Check your understanding.

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

1. Two traces each attempted one call; only one received an ok result. How many confirmed lookup successes occurred?
2. A task finishes after five calls rather than one. Which measurements reveal the difference?
3. A failed task performed two useful read calls. How should the report describe it?

Section 1.7 7 of 7

A lookup that has not returned a result

Focus

Avoid claiming a lookup result while its response is still pending.

A user asks whether a payment job is currently running. The agent submits a read-only lookup, but the response is delayed. A maintenance note suggests that the job usually runs at this time. The note gives background context; it does not supply the requested current observation.

A completed design keeps the task waiting until the bounded response deadline. If the result arrives, the agent reports it with the observation time. If the deadline expires, it reports that current status could not be confirmed. It can mention the usual schedule only as a separate supported statement, not as a substitute for live status.

This case transfers the proposal-observation distinction to real asynchronous systems. A request can have been accepted while its result remains unknown. Neither a pending spinner nor a model’s confident completion statement changes that fact. The executor’s state and observed result determine what the application can claim. The next lesson adds controlled stopping rules so a pending or repeating task cannot consume resources indefinitely.

// 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 live status lookup is pending, while a schedule says the job usually runs now. What can be claimed?
2. A delayed status result finally arrives. What helps bound the claim?
3. The response deadline expires without a result. Which state is honest?

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: Stopping an agent predictably →