What you need to know
A long-running agent faces two budgets. Reasoning costs time and tokens on every step. Context fills up as tool results and turns accumulate, and an agent with a cluttered context forgets what it decided and repeats work. This skill asks you to allocate the first and manage the second so the agent stays accurate for the whole session, within its latency limits.
Allocate reasoning effort
Thinking helps where a step needs planning, comparison or multi-step reasoning, and wastes time where the step is routine. Current models let you steer how much they think with an effort setting, and can decide adaptively how much a request needs.
| Step | Effort | Why |
|---|---|---|
| Planning a migration, choosing between designs, diagnosing a complex failure | High | Errors here propagate to every later step |
| Routine tool calls, copying data, formatting output | Low | More thinking does not change the result |
| A latency-critical reply to a user | Low or moderate | The latency limit binds |
Three context lifecycle tools
| Tool | What it does | Fits |
|---|---|---|
| Context editing | Clears old tool results (and optionally old thinking) from the context as it grows, keeping the most recent | Agents whose context fills with large tool outputs they no longer need |
| Memory tool | Lets the agent write notes to files outside the context and read them back later, including in a new session | Progress, decisions and facts that must survive beyond the current context window or session |
| Compaction | Summarizes the conversation so far and continues from the summary | Long conversations where the gist matters more than the detail |
They combine. A typical long-running agent clears stale tool results with context editing, records its progress and decisions in memory, and compacts the conversation when it nears the limit.
Choose by what the session must remember
- Exact state that later steps depend on (which batches are done, which files were changed, the decision on a design question): write it to memory. A summary can lose it; clearing tool results certainly will.
- Bulky outputs that served their purpose (file listings, logs, search results): clear them with context editing.
- The thread of a conversation (what the user asked, what was agreed): compact it, and check that the summary keeps the decisions.
In the exam
Items describe a long-running agent with stated latency and accuracy requirements and a symptom: it slows down, costs climb, it forgets decisions or repeats work late in the session. Pick the lifecycle tool that matches what must be kept (memory for exact progress and decisions, context editing for stale tool output, compaction for the conversation thread), and the effort allocation that spends reasoning on planning and hard steps rather than everywhere. Distractors raise effort on every step, enlarge the window, raise max_tokens, or restart without notes.
Check your understanding
A coding agent works for hours on a large repository. Its context fills with file listings and test logs from many turns ago, and quality drops late in the session. Which change fits best?
Show answer
Answer: A. The clutter is stale tool output, which context editing removes. A bigger window or more output room does not remove it, and more reasoning does not restore focus.
An assistant must remember a user's preferences and past decisions across separate sessions over several months. Which tool fits?
Show answer
Answer: B. Only memory persists outside the context, across sessions. Compaction and context editing manage a single session's context, and pasting history into the prompt grows without limit.
An agent plans a database migration, then runs about 400 routine copy commands. Latency per step matters. How should reasoning effort be allocated?
Show answer
Answer: C. Errors in the plan propagate to every command, so planning earns more reasoning. Routine commands gain nothing from it, and their latency adds up.
Apply it: Keep Northgate's audit agent on track
Northgate wants one long-running agent to audit services for the deprecated logging library, working through the 160-service catalogue over a day-long session. In a pilot over 20 services, the agent slowed down after about 30 services' worth of output, re-audited two services, and once forgot a decision to treat configuration-only use as low risk.
- Allocate reasoning effort across the agent's steps.
- Design the context lifecycle: what is cleared, what goes to memory, and when compaction runs.
Done when: a restart could resume without re-auditing anything. - Say how you would test that the design fixed all three pilot problems.
Show model answer
1. Effort. Higher effort when the agent classifies a service's usage pattern and assigns risk, because a wrong classification flows into the migration plan. Lower effort for listing files, running searches and writing the result record.
2. Lifecycle.
| What | Treatment |
|---|---|
| Search results, file listings, file contents from finished services | Cleared with context editing once the service's result is written |
| Progress: services audited, results written, services skipped and why | Written to a progress file in memory after each service; read before choosing the next |
| Decisions and rules learned during the run, such as "configuration-only use is low risk" | Written to a decisions file in memory when made; read at the start of each service |
| The conversation with the platform engineer | Compacted when the context nears its limit, then checked against the decisions file |
3. Test. Rerun the 20-service pilot, then a 60-service run with a forced restart halfway. Pass when no service is audited twice, every service in the catalogue has exactly one result, the configuration-only rule is applied after the restart, and time per service stays flat through the run.