Topic 2 of 6 · 5 min read
Goal drift and off-task work
Goal: Spot where an agent's run drifts from the user's goal and add the instruction or check that keeps it on task.
Goal drift is when an agent does work that is plausible and even useful, but is not what you asked for. It often looks like diligence.
Check yourself · 1 of 3
An agent asked to fix one failing test also renames variables in another file. What is this called?
Why it matters
You asked for a fix to one function. The agent also renamed variables, upgraded a dependency and rewrote a neighbouring test. Each step made sense to it. Together they make the change hard to review and put unrelated risk into your branch.
Three kinds of drift
- Scope creep. The task grows. "Fix the date bug" becomes "refactor the date module".
- Overeager action. The agent does something extra that was never requested, such as running a database migration, sending an email, or force-pushing, because it seemed the natural next step.
- Instruction decay. In a long run the original request and its constraints sit far back in the context. The agent follows its own recent notes instead. A rule like "do not touch the
legacy/folder" gets forgotten after 80 tool calls.
How to find it in a trace
- Write the task in one line before reading the trace. Mark each step as on-task, supporting or unrelated.
- Compare the files touched with the files the task needed. A fix for
invoice.tsthat also editsauth.tsdeserves a question. - Look for the agent's own plan rewriting. A plan that gains new goals ("also clean up...") is drift in progress.
How to keep it on task
- Put scope in the prompt, as a positive and a negative: what to change, what is out of bounds.
- Restate the goal. Have the harness re-insert the original task and constraints every N steps, or keep a pinned goal block in the context.
- Enforce, do not just ask. Make out-of-scope paths read-only, require approval for irreversible actions, and add a final check that lists files changed against an allowed set.
- Small tasks. A narrow task has less room to drift than "improve the codebase".
Before and after
Before: "Fix the failing date test." The agent edits six files.
After: "Fix the failing date test in tests/date.test.ts. Change only src/date.ts unless you ask first. Do not edit other tests. When finished, list every file you changed." The harness rejects a diff that touches any other path.
What goes wrong
- Trusting the summary. The agent's report omits the side changes. Check the diff.
- Rules only at the start. Long runs need the constraint refreshed or enforced.
- Vague goals. "Make it better" invites any improvement the agent can find.
Examples
Files touched versus files needed
Task: fix rounding in formatPrice() in src/money.ts
Files changed by the agent:
src/money.ts (needed)
tests/money.test.ts (supporting: new case)
src/cart.ts (unrelated: renamed 3 variables)
package.json (unrelated: bumped dayjs 1.11.9 to 1.11.13)
Two of four files have no link to the task. The review question is not whether those edits are good, but why they are in this change. Ask the agent to revert them and offer them as separate tasks.
Instruction decay in a long run
The prompt said: "Do not modify anything under legacy/." At step 94 of a long migration, the agent edits legacy/export.js to make a build pass. The rule is still in the first message, but 90 tool results now sit between it and the agent. A fix is a path guard that refuses writes under legacy/, plus the rule restated in the harness's reminder block.
Key points
- Goal drift is plausible, even useful, work that was not requested, and it makes changes hard to review.
- Scope creep, overeager side actions and instruction decay in long runs are separate patterns with the same effect.
- Compare files touched against files the task needed to find drift in a diff or trace.
- State what is out of bounds as well as what to do, and enforce it with read-only paths and approvals.
- Re-insert the original goal and constraints during long runs so they do not fade from the context.
Common mistakes
- Giving a broad goal such as "improve this module" and being surprised by wide changes.
- Putting constraints only in the first message of a very long run.
- Reading the agent's closing summary instead of the list of changed files.
- Treating helpful extra changes as free; they still need review and can break other code.
Check yourself · 2 of 3
Which change best stops an agent from editing the legacy/ folder during a 100-step migration?
Check yourself · 3 of 3
The task was to fix a bug in src/date.ts. Which line in the agent's report most needs follow-up?
Practice items, not counted towards your mastery.
Start here
- Why Do Multi-Agent LLM Systems Fail? (opens in a new tab)PaperFree
A taxonomy of failures labelled across traces from several multi-agent frameworks, including task derailment and wrong verification.
- Recent frontier models are reward hacking (METR) (opens in a new tab)ArticleFree
Concrete cases of models tampering with scorers and tests instead of solving the task.
- Specification gaming: the flip side of AI ingenuity (Google DeepMind) (opens in a new tab)ArticleFree
Explains why an agent satisfies the letter of an objective, with many examples.
More for this topic
- Building effective agents (Anthropic) (opens in a new tab)ArticleFree
Advice on stopping conditions, ground truth from the environment and careful tool design.