MSBA-371 · Lesson 2 of 12 · 20 min

Planning and execution control

▶ Video coming soon A video version of this lesson is on the way.

Dmitri Kovac brought the second session's problem. He had assigned the Copilot cloud agent an issue that asked it to add a metric-or-imperial toggle to the trail-units action's output. The issue was three lines long. The agent produced a pull request that added the toggle, renamed two existing inputs for consistency, rewrote the README's examples and updated a test helper used by another action. Every change was defensible on its own, and the tests passed, but Dmitri had wanted a twenty-line change and was looking at four hundred. "It did what it decided the task was," he said, "not what I meant."

Priya wrote two words on the whiteboard: plan and control. An agent that plans before it acts gives people a chance to correct its understanding while correction is cheap. An agent whose execution is controlled by limits, checkpoints and stopping rules cannot wander far even when its understanding is wrong. This lesson covers both, which together make up the execution half of the GH-600 domain on memory, state and execution.

Why planning comes first

A plan is a short, explicit statement of what the agent intends to do: the goal as it understands it, the steps it will take, the files it expects to touch, how it will check the result, and what it will not do. Writing the plan has three benefits.

First, the plan exposes misunderstanding early. Dmitri would have seen "rename inputs for consistency" in a plan and struck it out in seconds; in a finished pull request it took him half an hour to separate it from the work he wanted. Second, the plan becomes durable state, as the previous lesson showed, so the work can resume after an interruption. Third, the plan gives reviewers something to compare the diff against, which is how drift and scope creep are caught.

Planning is not free. For a one-line fix a plan is overhead. The rule of thumb Tidewater adopted was to require a plan whenever the task touched more than one file, changed a public interface such as an action's inputs, or was described in fewer words than the change was likely to need.

Planning features in GitHub's agents

GitHub's agents support planning in several ways, and the details change often, so the course describes them in general terms. The Copilot cloud agent writes its plan into the pull request description as a checklist and updates it as it works. It can also be asked to research a problem and propose a plan without changing code, so that a person can approve the approach before implementation starts; MSBA-370 called these research and plan-first sessions. Editor agents and Copilot CLI offer planning modes or planning agents that produce a plan for approval before making edits, and a custom agent can be written whose only job is planning, with read-only tools and a handoff to an implementation agent.

Whatever the tool, the pattern is the same: ask for a plan, read it, correct it, approve it, and only then let the agent change things. For high-risk work the approved plan should be saved where reviewers will see it later.

A flow from left to right. Task leads to a plan box, then to a person approving or correcting the plan, then to a loop of execute step, check, update plan. A diamond asks whether a stopping condition is met; yes leads to hand back for review, no returns to execute step. A side arrow from check leads to escalate to a person.
Plan first, then execute in checked steps. Every step updates the plan, and stopping conditions decide when control returns to a person.

A good plan, and a poor one

Lena rewrote Dmitri's issue as an exercise, then asked an agent for a plan against both versions. The poor plan, from the original three-line issue, read "Add a units toggle; update docs and tests as needed." It said nothing about scope and gave the agent permission, by vagueness, to update anything it judged related.

A good plan names the goal, the definition of done, small steps, what is out of scope and the files it expects to change.
## Plan: add output-units input to trail-units

Goal: callers can choose metric or imperial output; default stays metric.
Done when: npm test passes, dist/ rebuilt, README documents the new input.

Steps
1. Add input output-units (metric | imperial, default metric) to action.yml
2. Read the input in src/main.js and pass it to formatDistance()
3. Add tests: default, imperial, invalid value fails with a clear message
4. Rebuild dist/ with npm run build
5. Add one README row for the new input

Out of scope
- Renaming existing inputs
- Changes to other actions or shared test helpers

Files expected: action.yml, src/main.js, test/main.test.js, dist/index.js, README.md

The better plan has five features worth copying. It states the goal and the default, so behavior for existing callers is fixed. It defines done in checkable terms. Its steps are small enough that each produces a reviewable change. It lists what is out of scope, which is the line Dmitri had wanted and never wrote. And it names the files expected, which lets a reviewer, or the controller, spot when the agent strays.

Execution control: the levers

Once the plan is approved the agent executes it. Execution control is everything that keeps execution bounded. Some levers are set by the product, some by administrators and some by the person who assigns the task.

Execution-control levers. The model chooses actions; these deterministic settings decide how far those actions can go.
LeverWhat it limitsExample at Tidewater
Step or turn budgetHow many model calls or tool calls a session may makeEditor agent asks to continue after a set number of requests
Time limitHow long a session or a single command may runCloud agent sessions are bounded by the product; test commands have a timeout in the setup
Scope rulesWhich files or folders the agent may changeOut-of-scope list in the plan; path-specific instructions; rulesets that require code owner review for workflow files
Tool permissionsWhich tools the agent may callPlanning agent has read-only tools; implementation agent can edit and run tests
Approval pointsWhich actions wait for a personEditor agent asks before running terminal commands outside an allow list
CheckpointsWhere progress is saved and can be rolled backCommit after each plan step; editor checkpoints that restore files
Stopping conditionsWhen the agent must stop and hand backTests pass and plan complete; or three failed attempts at the same step

Budgets stop runaway loops. An agent that keeps retrying a failing command, or reading file after file in search of something that is not there, will eventually hit its budget and stop. Budgets also bound cost, which MSBA-370 covered in its lesson on cost and latency. Set them generously enough for real work and tightly enough that a stuck agent stops before it wastes an afternoon.

Checkpoints make mistakes cheap to undo. In the cloud agent every commit is a checkpoint; in editors, many agents keep checkpoints of the workspace that let a person restore files to the state before a given request. A checkpoint after each plan step means a wrong step costs one step, not the session.

Stopping conditions are rules for when the agent must stop and return control. Good stopping conditions include success (plan complete and checks pass), repeated failure (the same step fails a set number of times), uncertainty (an open question the plan cannot answer), scope (the next step would touch something out of scope), and risk (the next action is in a class that needs a person, covered in the lesson on guardrails).

Stopping conditions in instructions and in software

Some stopping conditions can be written into instructions: "If the same test fails three times after your changes, stop and summarize what you tried." Instructions are cheap and flexible, but they are probabilistic: the model usually follows them, not always. Other stopping conditions are enforced by software: budgets and time limits set by the controller, permissions that refuse a tool call, rulesets that refuse a push. Those are deterministic.

MSBA-370 made the same point about instructions in general, and it applies here with extra force. If a stopping condition protects against harm, enforce it in software and also write it in instructions. If it only saves time, an instruction is usually enough.

Worked problem

Adding stopping conditions to AGENTS.md

After Dmitri's experience, the group added a section on execution to the AGENTS.md file in the trail-units repository.

Show solution
  1. Lena wrote the success condition: stop when the plan's steps are done, npm test passes and dist/ is rebuilt.
  2. Malik wrote the failure condition: if a step fails three times, stop, leave the branch as it is and write what was tried in the pull request.
  3. Dmitri wrote the scope condition: if a needed change falls outside the files named in the plan, stop and ask on the pull request rather than making it.
  4. Priya added the uncertainty condition: if the issue does not say what the default should be, ask rather than choose.
  5. They noted which conditions software also enforces: the ruleset on the default branch, required checks and the session limits of the product.

Steering a running agent

Execution control also includes steering: giving a running agent new information without stopping it. In the cloud agent, people steer by commenting on the pull request, mentioning Copilot with the correction; the agent picks up the comment and continues. In editors, people steer by sending a message while the agent works or by pausing it.

Steering is best for small corrections. When the correction contradicts the plan, update the plan as well as sending the message, so that the durable record and the conversation agree. When the agent has built several steps on a wrong assumption, steering usually costs more than a reset.

Interrupting, pausing and canceling

People need to be able to stop an agent at any time. The controls differ by tool, but they fall into three kinds. Pausing stops execution but keeps state, so the session can continue. Canceling stops the session; work already committed stays on the branch, and a new session can start from it. Rolling back returns files to an earlier checkpoint or commit. A runbook should say which to use: pause to think, cancel when the direction is wrong, roll back when a step did damage.

Context drift during execution

The previous lesson introduced context drift. Long executions are where it shows. Three habits keep execution aligned with the plan.

Re-read the plan at each step. Agents that keep their plan in a file and read it before each step drift less than agents that rely on a plan buried twenty tool results back in the conversation.

Compare changes with the expected files. A controller or a reviewer that notices changes outside the plan's list of expected files has caught drift or scope creep at once.

Refresh against the base. Long sessions should check whether the base branch has moved and whether the plan still fits. The cloud agent works on its own branch, so conflicts with other people's work appear in the pull request like any other branch; resolving them is part of finishing the task.

Execution in different environments

Execution control looks different in each environment. In an editor, the agent runs in the developer's workspace with the developer's access, so approval points for terminal commands matter most, and the developer is usually watching. In Copilot CLI, approval of tools and commands is similar, with options to allow some tools for a session. In the cloud agent, nobody is watching in real time, so the controls are environmental: a fresh environment prepared by the copilot-setup-steps workflow, a token scoped to the repository, the firewall, the branch it may push to and the pull request review it must pass.

Seraphine described Skerry's rule of thumb. Interactive agents get approval points, because a person is there to approve. Background agents get boundaries, because nobody is. Asking for approvals from a background agent just creates a queue of requests that nobody answers until morning.

Execution controls differ by environment. Interactive agents rely on approvals; background agents rely on boundaries.
EnvironmentWho is watchingMain execution controls
Editor agentThe developer, usuallyPlan approval, command approvals, workspace checkpoints, request limits
Copilot CLIThe developer, usuallyTool and command approvals, session-scoped permissions, plan mode
Copilot cloud agentNobody in real timeSetup steps, scoped token, firewall, own branch, session log, pull request review and rulesets

Dmitri's second attempt

Dmitri closed the four-hundred-line pull request with a polite comment and opened a new issue with the plan above pasted into it, including the out-of-scope list. He asked the cloud agent to work from it. The new pull request changed five files and fifty-two lines. The plan checklist in the description matched the commits one for one, and the agent left one question on the pull request: whether an invalid value should fail the step or fall back to metric. Dmitri answered "fail", the agent added the test and finished. The review took eight minutes.

Later he went back to the first pull request and saved two of the agent's unrequested ideas, the input renames and the README rewrite, as separate issues. Both were good ideas. They were just not the task.

Common mistakes

  • MistakeAssigning a multi-file change from a three-line issue with no scope.

    InsteadAsk for a plan, correct it, and write what is out of scope before execution.

  • MistakeRelying on an instruction alone to stop risky actions.

    InsteadEnforce stopping conditions that protect against harm in software, and repeat them in instructions.

  • MistakeSteering a session that has built several steps on a wrong assumption.

    InsteadCancel, fix the plan and start a new session.

  • MistakeGiving a background agent approval prompts that nobody will answer.

    InsteadUse boundaries such as scoped tokens, firewalls, branches and review for background agents.

  • MistakeLeaving the plan in the conversation only.

    InsteadKeep the plan in a durable place and re-read it at each step.

Summary and key terms

  • A plan states the goal, done, steps, out-of-scope items and expected files, and is approved before execution.
  • Execution control uses budgets, time limits, scope rules, tool permissions, approval points, checkpoints and stopping conditions.
  • Stopping conditions cover success, repeated failure, uncertainty, scope and risk.
  • Conditions that prevent harm should be enforced by software, not only written in instructions.
  • Steer for small corrections; cancel and restart from a fixed plan for large ones.
  • Interactive agents rely on approvals, background agents on environmental boundaries.
Plan-first
Having an agent propose a plan for approval before it changes anything.
Execution control
Deterministic limits and checkpoints that bound what an agent does while it executes.
Stopping condition
A rule for when an agent must stop and return control to a person.
Checkpoint
A saved state, such as a commit, that work can be rolled back to.
Steering
Giving a running agent new information or corrections without stopping it.
Scope creep
An agent making changes beyond what the task required.

Practice problems

Work each problem on paper first, then reveal the answer to check.

  1. Which line in Dmitri's second plan would have prevented the four-hundred-line pull request?

    Show answer

    The out-of-scope list: no renaming of inputs and no changes to other actions or shared helpers.

  2. Give two stopping conditions enforced by software.

    Show answer

    Any two of: request or step budgets, time limits, permissions refusing tool calls, rulesets refusing pushes, required checks.

  3. When is steering the wrong choice?

    Show answer

    When the agent has built several steps on a wrong assumption; a reset from a corrected plan is faster.

Lesson quiz · 5 questions

Score 60% or more to complete this lesson.

Take the quiz