Search⌘ K
AI Features

Structured Notes, Attention Recitation, and Recursive Slicing

Explore how to maintain structured notes across agent turns, keep the current plan near the end of context, and verify completed tasks against tool traces. Learn to process oversized documents with map-reduce, recursive slicing, token checks, and save-first model output.

We'll cover the following...

In the previous lesson, we compacted a long session by saving the older turns to a file and replacing them with a summary. This reduces the number of tokens in the active conversation history. However, compaction does not explicitly track task progress. Suppose an engineer asks, “What’s left before we can close this incident?” The information needed to answer this question is distributed across recent turns and the compacted summary. The assistant would need to reconstruct its task progress from the conversation history each time.

In this lesson, we'll introduce a structured notes file that stores the assistant's findings and task list and is updated after every turn. We'll append the contents of the notes file to the model's input context on each call, placing the current plan at the end of the context. We'll also verify that each completed task is supported by evidence from a corresponding tool call. We'll then address another context management challenge: processing documents that exceed the available token budget for a single model call. We'll split the document into chunks, summarize each chunk independently, and combine the resulting summaries.

Keep the plan in notes

Before closing an incident, the on-call engineer must complete a checklist: identify the change responsible for the latency spike, verify that latency has returned to acceptable levels and that the required runbook steps were completed, page the owning team, and determine whether a rollback is necessary. We'll use this checklist as the assistant's task list.

The notes file holds two sections:

  • Findings: One entry per completed task, with supporting evidence such as a document ID or a reference to the relevant tool result.

  • To-do: All checklist items, marked [x] when completed and [ ] when pending. Pending items appear at the end of the list.

This approach is commonly referred to as structured note-taking. The agent persists notes in external storage and loads them into its context on subsequent turns. The key implementation detail is the file update strategy. After each turn, we regenerate the entire notes file from the current state rather than append new entries.

notes_md.py · Python 3.14.0
CHECKLIST = { # what must be confirmed before the incident can be closed
"change": "Identify the change behind the spike",
"latency": "Confirm p99 latency recovered",
"errors": "Confirm the checkout error rate is normal",
"runbook": "Confirm the current runbook was followed",
"redis": "Confirm Redis was not restarted",
"owner": "Page the team that owns the tax service",
"rollback": "Decide whether to roll back v2.31",
"status": "Post a status update",
}
FINDINGS = {
"change": "v2.31 deployed 14:02, new_tax_display on 14:03 [change log]",
"latency": "p99 back to 210 ms at 14:13 [get_metrics]",
"errors": "error rate 0.3%, same as before 14:00 [get_metrics]",
"runbook": "flag turned off first, per [note-1]",
"redis": "no Redis restart, per [note-8]",
"owner": "payments on-call paged at 14:20 [note-6]",
"rollback": "keep v2.31 with the flag off until the tax call is fixed [note-2]",
"status": "status update posted at 14:30",
}
TURN_ORDER = ["change", "latency", "runbook", "redis", "owner", "errors", "rollback", "status"]
def write_notes(done, path="NOTES.md"):
lines = ["# Incident notes: checkout latency, 14:05", "", "## Findings"]
lines += [f"- {item}: {FINDINGS[item]}" for item in done]
lines += ["", "## To-do (pending items last)"]
lines += [f"- [x] {text}" for item, text in CHECKLIST.items() if item in done]
lines += [f"- [ ] {text}" for item, text in CHECKLIST.items() if item not in done]
with open(path, "w") as f: # rewrite the whole file every turn, never append
f.write("\n".join(lines) + "\n")
if __name__ == "__main__":
for turn in range(1, len(TURN_ORDER) + 1):
write_notes(TURN_ORDER[:turn]) # one rewrite per turn
if turn == 4:
print(open("NOTES.md").read())
...