Check usage and compact the conversation
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
- Audit token consumption: Inspect your harness's token or context indicator to observe total tokens consumed and percentage of the sequence window occupied.
- 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.
- Initialize a fresh session: Start a new agent session and direct it to read
notes/session-summary.mdto resume work with minimal context overhead. - Audit the summary document: Review
notes/session-summary.mdcarefully: because new sessions inherit claims recorded here, correct any inaccurate statements before continuing (Memory).
Workshop example · Clinical: clinic network
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 clinic_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 three memo questions, the cleaning decisions (units converted, age repaired from other visits, and so on), the files in
data/clean/ and out/, the headline results (target attainment, the pilot odds ratios), and what remains (for example the abstract or the dashboard).
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