Run and inspect an agent workflow
Hand a ready-made plan to an agent, follow its planning, implementation and verification step by step, and steer it to a proper recovery when a step fails.
Outcome: Follow planning, implementation and verification, then recover from a failed step.
Note
Reading as a visitor
Learning objectives
- Describe the plan, act and verify phases of an agent run and what each should produce.
- Read an agent's event stream, using observations such as commands, exit status and output as evidence instead of its summary.
- Recognise a failed step, including quiet failures, and trace it to its root cause.
- Steer an agent's recovery with explicit evidence and constraints, and refuse fixes that only silence a check.
- Explain why applied database migrations must never be edited, and how to make a schema change instead.
Prerequisites
- Has used an AI coding agent such as OpenHands, Claude Code or OpenCode on a small task.
- Comfortable with git status, git diff and reverting a file.
- Knows what a database migration is.
- Has access to a language model for the agent, through your own provider account or API key.
Concepts
What an agent workflow is
A coding agent works in a loop. It plans what to do, takes an action (runs a command, reads or edits a file), observes the result, and decides the next action from what it observed. It repeats this until it believes the task is done. Most agents add an explicit verification phase at the end, running the type checker and the tests, because the loop only converges on something correct if the observations tell it the truth.
Three phases are worth watching separately:
- Plan. What the agent intends to do, in which order, and what it will treat as done. Errors here are cheap to fix and expensive to miss: a wrong step in the plan is carried out faithfully.
- Act. The commands and edits themselves. This is where you see what actually changed, as opposed to what the plan said would change.
- Verify. The checks that decide whether the work is finished. A verification step is only useful if its failures are taken seriously.
Reading the event stream
Agents record their work as a sequence of events: messages, actions and the observations that answer them. In OpenHands, each action the agent takes, such as running a command or editing a file, produces an observation with the result, and the conversation is built from that history. The OpenHands interface groups the steps of each stage in the chat; expanding a step shows the command or edit and what came back. Claude Code and OpenCode show the same kind of history in the terminal, one tool call at a time.
When you inspect a run, read the observations, not the agent's narration of them. The narration is the model's interpretation; the observation is the evidence. For a command, look at three things: the exact command that ran, its exit status, and the first error in its output. The first error is usually the cause; later errors are often consequences.
Recognising a failed step
Some failures are loud: a non-zero exit code, a stack trace, a red test. Others are quiet, and you only notice them if you compare the observations with the plan:
Worked example
The situation
The front desk wants to see only active bookings, so you give an agent a small task: "Add an optional status filter to GET /bookings." This walk-through follows the run phase by phase and shows where it went wrong. It uses a different task and a different kind of failure from the exercise; the way of watching is what carries over.
Phase 1: the plan
The agent reads the code and proposes:
1. Add an optional `status` query parameter (CONFIRMED or CANCELLED) to GET /bookings.
2. Filter in SQL; when no status is given, return confirmed bookings.
3. Add tests for both values, then run npm run verify.
Compare the plan with the specification before letting it continue. The contract says GET /bookings returns all of the caller's bookings, including cancelled ones. Step 2 quietly changes that default: a client that sends no parameter, which is every existing client, would stop seeing cancelled bookings. This is the cheapest moment to correct it, with one message: "Without status, keep returning every booking, as today." Suppose you miss it, as is easy to do when a plan looks reasonable.
Phase 2: the actions
The agent edits src/routes/bookings.ts: a querystring schema with status as an optional enum, and a WHERE clause that uses it. In the event stream, each edit is a step you can expand to see the change. Reading the diff here would have shown the default again:
Concept questions
Sign in and enrol to answer and save your progress.
Exercise
Your task
The starting point contains TASK.md, a ready-made plan written by a colleague for adding booking notes. Give it to an agent, and supervise the run: follow the plan, the implementation and the verification as they happen, and if a step fails, find out why and steer the agent to a correct recovery. The finished code must implement the feature properly.
The lesson centres on OpenHands, whose conversation view shows each step of the run. The exercise works the same way with Claude Code or OpenCode, where the steps appear in the terminal.
The feature
TASK.md describes it in full. In short:
POST /bookingsaccepts an optionalnotesstring.- Notes are trimmed; a note that is empty after trimming is stored as
null. - At most 500 characters after trimming; a longer note is refused with
400(INVALID_NOTES). - Every booking response (
POST /bookings,GET /bookings,GET /bookings/:id) includesnotes, which is when there is none.
Reflection
Recorded for you to look back on. It is not graded and does not by itself show understanding.
Prompt: Which step of the run failed? Describe the evidence you saw (the command and its output), the underlying cause, and how you steered the recovery: what you told the agent, which of its proposals you accepted or refused, and how you confirmed the result.
Further reading
- OpenHands documentation: Conversations in Agent Canvas (opens in a new tab)
- OpenHands documentation: Prompting Best Practices (opens in a new tab)
- OpenHands Software Agent SDK: Events (actions, observations and the event log) (opens in a new tab)
- OpenHands Software Agent SDK: Stuck Detector (opens in a new tab)
