Skip to content

ExpertLesson 3 of 412 min read

Compact, take notes, recall the objective

A course from the Academy: Context engineering: what your agent sees

Go to the quiz ↓

An agent that works for hours, on a code migration or a documentary investigation, always ends up approaching its context limit. Three techniques let it last without losing the thread.

1. Compaction

When the context approaches a threshold, the model is asked to summarise the history, then you start again from a fresh context containing that summary. The whole art lies in what the summary keeps:

  • the decisions taken, and why;
  • the constraints given by the user, word for word;
  • the open problems and the avenues already ruled out;
  • references to what has been touched (files, documents), so you can return to them.

What gets thrown away first: the raw tool results already used, which can always be requested again. The main risk is well known: a subtle constraint ("do not touch the payment module") summarised too quickly disappears, and the agent violates it three hours later in complete good faith.

2. Notes outside the context

Rather than keeping everything in mind, the agent writes to a file: a plan, a list of tasks ticked off as it goes, the important discoveries. This file survives every compaction and can be reread on demand. This is the principle behind the instruction and notes files that coding agents read at startup, and the memories that some platforms offer to agents.

3. Restating the objective at the end

On a long task, the initial objective ends up buried under dozens of steps, in the middle of the context, where attention is weakest. A simple and effective remedy: have the agent rewrite, at regular intervals, its task list and the objective at the end of the context. It recites them to itself, and puts them back where it sees them best.

Two fine adjustments

  • Keep the errors. Erasing failed attempts makes the context cleaner, but deprives the model of the proof that this path fails: it may try it again. Keep a short record of the failure and its cause.
  • Avoid mechanical repetition. A context filled with twenty near-identical actions pushes the model to continue the pattern, even when the situation has changed. Slightly varying how the steps are presented breaks this entrainment effect.
Analogy. It is the night team of a hospital ward. It does not reread the whole day minute by minute: it receives handovers (compaction), consults the written care record (the notes), and the ward sister restates the ward's three priorities at the start of the shift (the recited objective). A botched handover that forgets an allergy, and the night goes badly.

Key points

  • Compaction: keep decisions, constraints word for word, open problems and references; throw away raw results.
  • Notes in a file: they survive compactions and can be reread on demand.
  • Have the objective recited at the end of the context, and keep a record of failures.

Key concepts

Complete the lesson

A 4-question quiz: 3 correct answers are enough, plus an exercise to practise. It opens in the Academy, on this same lesson.

Take the quiz and complete the lesson Free. With an account, your progress is saved and leads to the course certificate.

The course: Context engineering: what your agent sees

  1. Context is a finite resource11 min
  2. A stable context, for caching and for consistency11 min
  3. Compact, take notes, recall the objective12 min
  4. Sous-agents : isoler pour mieux penser11 min

The whole Academy →The AI glossary