Skip to content

Check usage and compact the conversation

Quick step  about 5 min

In this exercise, you audit active token usage in your agent harness, synthesize key analytical decisions into a concise Markdown summary, and initialize a fresh working session without losing project state.

Before you start: An active agent session that has executed multiple turns across earlier exercises (Setup).

Background

Because language model inference is stateless, each turn re-transmits the complete conversation transcript. Consequently, long-running sessions exhibit increased latency, higher token costs, and attention drift (Context, Costs). Most modern harnesses display active context usage and provide commands to compact or clear history.

Executing manual compaction at logical project milestones is far superior to automatic truncation: you select the precise transition point and decide which decisions to preserve.

General methodology

  1. Audit token consumption: Inspect your harness's token or context indicator to observe total tokens consumed and percentage of the sequence window occupied.
  2. Synthesize state to disk: Instruct the agent to summarize project state into a persistent document:
Summarize this session for a future fresh session:
- The core analytical objective.
- Specific data cleaning and modeling decisions made, along with justifications.
- Files generated and their analytical roles.
- Current project state and open research questions.
Save this summary as notes/session-summary.md (under 40 lines). Do not include credentials or unredacted confidential data.
  1. Initialize a fresh session: Start a new agent session and direct it to read notes/session-summary.md to resume work with minimal context overhead.
  2. Audit the summary document: Review notes/session-summary.md carefully: because new sessions inherit claims recorded here, correct any inaccurate statements before continuing (Memory).

Workshop example · Imaging: chest radiographs

Start from: any checkpoint where you have worked for a while (how to restore)
Produces: notes/session-summary.md

Prompt

Summarise this session for a future session: the questions from radiology_notes.txt we are answering, the cleaning decisions and why, the files we created and what each is for, the results so far, and the open questions. Save it as notes/session-summary.md in under 40 lines.

What you should see. A short file listing the five questions from the radiology memo, the cleaning decisions (which images were fixed or excluded, and that no exclusion depended on a model score), the files in data/clean/ and out/, the headline results (AUC with intervals, the pilot bar not met), and what remains (for example the abstract or the report classification).

Images and context. Viewing many images costs far more of the agent's working memory than reading text. If you looked at images in this session, a long session is a good moment to summarize and start fresh.

Calibrating cost. After your first long session, look at your account's usage page. Compare the usage for this session with a short one, to see how conversation length drives usage.

Verification criteria

  • Decision-centric summary: The summary synthesizes methodological decisions and file roles rather than logging conversational dialogue.
  • Context reduction: The new session initializes with substantially reduced token overhead while accurately identifying where prior work concluded.
  • Durable external state: All critical conventions discussed in the earlier conversation now exist as persistent files on disk.

Common pitfalls

Symptom Underlying cause Resolution
Summary is excessively verbose Prompt lacked line constraints or section structure Direct the agent to condense the document to under 40 lines across four explicit sections
Key methodological rule omitted Decision was discussed conversationally but never committed to disk Add the missing rule directly to notes/session-summary.md and append to AGENTS.md

Concepts behind this

  • Context. Context represents the model's active working memory. Because every turn re-transmits the complete conversation, long sessions increase latency, cost, and attention drift. Go deeper →
  • Costs. Language model pricing is determined by token volume. Because conversation history re-transmits on every turn, session length compounds costs quadratically. Go deeper →

Builds on: Orient the agent in a folder