Free self-study · No account needed · Progress stays in this browser. Back it up before clearing site data or changing devices.

← Week 6: Context Engineering

Week 06 / Lesson 3

Compacting a conversation without losing decisions

Preserve facts, uncertainty, decisions, and revoked instructions through summarization.

Section 3.1 1 of 7

Overview

Focus

Preserve facts, uncertainty, decisions, and revoked instructions through summarization.

Your route through the lesson

  • 3.2 A structured summary of working state
  • 3.3 Compaction and retained source references
  • 3.4 Testing repeated compression and changed constraints
  • 3.5 Put it into practice
  • 3.6 Guided comparison
  • 3.7 A revoked preference surviving compression

All required teaching is included here. Review selections are saved. Choose a correct answer for every question to continue; retries are unlimited. Study time and personal notes are optional.

Section 3.2 2 of 7

A structured summary of working state

Focus

Summarize working state with separate facts, decisions, options, and revocations.

A conversation summary is a replacement representation of working state, not a license to simplify every statement into a decision. Facts describe known information. Decisions record chosen actions or constraints. Tentative options remain possibilities. Revoked instructions record what is no longer authorized. Open questions preserve missing information.

Consider a project-blue conversation: the project is blue, output must be local, a table is being considered, email delivery was revoked, and the retention owner is unknown. A summary saying use a table and email the result changes two statuses. The table was never selected, and email is explicitly no longer allowed. Fluent prose can hide that semantic damage.

A structured summary uses separate fields and source references. It can still contain concise prose within fields, but its categories help a request builder retain current constraints. Source references let a later reviewer resolve ambiguity against original turns. The summary should not imply a person approved a proposal merely because it was discussed. Compression is successful when it preserves the distinctions needed for the next supported task, not when it simply produces the shortest attractive paragraph.

// Quick review

Check your understanding.

Choose an answer for immediate feedback. Retry freely; a correct answer for every question unlocks the next section.

1. A table was only considered. Where should it appear in a structured summary?
2. Email delivery was revoked. A summary says email is preferred. What changed incorrectly?
3. Why retain an unresolved retention owner as an open question?

Section 3.3 3 of 7

Compaction and retained source references

Focus

Compact history while retaining source references and enough detail to reconstruct meaning.

Compaction replaces a longer history with a smaller state representation so future requests can fit their budgets. The application should keep original records under an appropriate retention policy while sending only needed state. A compact summary and durable history serve different purposes: one supports current reasoning, the other supports reconstruction and audit.

Retain references such as conversation:turn4 or document:new alongside claims. A reference is not proof by itself, but it points to evidence that can be inspected. Include scope and status, not only a keyword. The phrase email appeared loses whether it was requested, rejected, or revoked. A useful compact record says email delivery revoked at turn 4 for project blue.

The core helper uses copy.deepcopy to create a separate nested structure. Deep copying means later edits to a nested dictionary in the copy do not silently modify the original state. This is deterministic state projection, not language-model summarization. It provides a precise baseline for status preservation. A free-form model summary would require its own comparison against original decisions, uncertainty, revocations, and source support before replacing the trusted working state.

// Quick review

Check your understanding.

Choose an answer for immediate feedback. Retry freely; a correct answer for every question unlocks the next section.

1. Why is email appeared an inadequate compact record?
2. What does a deep copy protect against?
3. A summary cites conversation:turn4. What must still be possible?

Section 3.4 4 of 7

Testing repeated compression and changed constraints

Focus

Test repeated compaction and updates so obsolete constraints do not reappear.

One correct summary does not establish stability after repeated compression. Small status errors can accumulate: a tentative option becomes a decision, a missing fact becomes certain, or a revocation disappears. Test several rounds and a reload into a fresh state representation, comparing required invariants each time.

Changes must be applied to the current structured state with evidence. If the user later selects a table, move that option from tentative to decision and record the new source. If the user revokes email, preserve the revocation rather than keeping both send email and do not send email as undifferentiated instructions. A fresh session should receive the current interpretation.

The fixture performs three compactions and JSON disk reloads. Serialization creates an independent persisted representation, making accidental in-memory aliases less likely to hide defects. Assertions check local output remains chosen, table remains tentative, email remains revoked, and the source reference survives. This validates the trusted projection helper's behavior, not a live model's compression quality. Extending to model summaries requires actual outputs and semantic checks, with the same distinction between status, source, and active authority.

// Quick review

Check your understanding.

Choose an answer for immediate feedback. Retry freely; a correct answer for every question unlocks the next section.

1. After repeated compression, a tentative table becomes a confirmed decision without new input. Result?
2. Why test a disk reload as well as in-memory compaction?
3. A later user explicitly selects a table. What should state management do?

Section 3.5 5 of 7

Put it into practice

Focus

Run three structured compactions and verify state after reload.

Download week06.py, save it in an exercise folder, and run python week06.py --lesson 3. This single practice uses a temporary state.json file, standard-library Python, a small processor, and seconds of runtime. It performs no model inference or external action and removes the temporary folder afterward.

The compact function selects facts, decisions, tentative, revoked, open_questions, and sources, then deep-copies them. A list comprehension identifies the retained keys; a dictionary comprehension maps each key to its state value. The for _ in range(3) loop repeats three times; underscore indicates the iteration index is deliberately unused. Each round writes JSON and reads it back into a fresh object.

Assertions require decisions.output to remain local, tentative.format to remain table, send_by_email to remain revoked, format not to appear in decisions, and the turn reference to survive. PASS confirms those exact invariants after three rounds and reloads. This is deterministic structured compaction, not an unmeasured claim that a free-form model summary is faithful. The downloadable artifact provides an executable baseline against which a later model-assisted summarizer can be evaluated honestly.

Download this week’s Python lab ↓

// Quick review

Check your understanding.

Choose an answer for immediate feedback. Retry freely; a correct answer for every question unlocks the next section.

1. What does range(3) do in the compaction loop?
2. Why assert format is not in decisions while tentative.format equals table?
3. The compaction fixture passes. Which claim is supported?

Section 3.6 6 of 7

Guided comparison

Focus

Explain the retained statuses and why deterministic copying is a useful baseline.

The completed state retains project blue as a fact and local output as a decision. It retains table as tentative, email as revoked, retention owner as unresolved, and conversation:turn4 as a source. These are six different kinds of information even though a short paragraph could mention all of them in one sentence.

The helper does not invent a natural-language summary. It projects permitted state fields and deep-copies their contents. Repeating that operation should preserve the same meanings, and JSON reload verifies their persisted representation. This is intentionally a strong simple baseline for a bounded structured state, not a demonstration of intelligent compression of arbitrary transcripts.

If a future model-generated summary is shorter but loses email revocation, it is worse for the supported workflow despite its brevity. Compare semantic invariants before comparing size. A token budget still matters for the actual serialized request, but fitting a corrupted summary is not success. The worked result therefore combines preserved meaning with explicit execution limits: no model compression, no fresh model session, and no external effects were tested. Only the fresh reconstructed state was checked.

// Quick review

Check your understanding.

Choose an answer for immediate feedback. Retry freely; a correct answer for every question unlocks the next section.

1. A shorter summary loses email revocation. Is smaller size sufficient improvement?
2. The helper projects and copies fields without a model. Why is it useful?
3. What does fresh reconstructed state mean in this fixture?

Section 3.7 7 of 7

A revoked preference surviving compression

Focus

Prevent a revoked preference from surviving compression as current authority.

A user initially requests email delivery, then switches to local-only output and explicitly revokes email. A summary generator keeps the first preference because it appeared repeatedly and drops the later revocation as a short detail. The next worker sees email as preferred and may propose a send, even though the user's current choice is the opposite.

The worked repair stores active_output=local, revoked=[email], and the source turn for the change. A verification check compares the compacted state with the original update and rejects any summary that marks email active. If a send proposal still appears, the executor separately checks current approval and denies it. This combines state fidelity with an independent effect boundary.

Repeated mentions are not a vote over current instructions. Later authenticated changes can revoke earlier choices, and their scope must survive compaction. The summary should also distinguish a temporary exception from a permanent change when the source says so. If scope is unclear, preserve the ambiguity rather than inventing duration. This transfer shows why summaries are part of the authority chain: losing a small status word can change what a future agent believes it may do.

// Quick review

Check your understanding.

Choose an answer for immediate feedback. Retry freely; a correct answer for every question unlocks the next section.

1. Email was repeated earlier but later explicitly revoked. Which controls current state?
2. A compacted state wrongly marks email active. Which two protections help?
3. A temporary exception duration is unclear in the source. What should compaction preserve?

Your personal notes

Optional, ungraded, and saved only in this browser. Export a backup from the Academy homepage to keep them.

References and further reading
Ask your own AI assistant

Copy this prompt into an assistant you already use. Nothing is sent automatically, and your personal notes are not included.

Next lesson: Embeddings and searchable document chunks →