Agent Engineering / Context & Memory
Manage short-term (working) memory
- MUST treat the context window as a limited budget. Load information when a step needs it (by path, query or ID), not up front “in case”.
- MUST keep task state in an external ledger (plan, task list, decisions, open questions, file paths touched), not only in the conversation.
- MUST update the ledger at each milestone: after a step completes, a decision is made, or a plan changes.
- MUST re-read a file, page or tool result before acting on it if it was loaded before a compaction or many turns ago. Do not act on recalled content.
- MUST keep these through any compaction or summary: the goal and done-criteria, decisions and their reasons, open items, and the identifiers (paths, IDs, URLs) needed to reload detail.
- SHOULD drop or summarise bulky tool output (long logs, full file dumps, search results) once its conclusion is recorded.
- SHOULD send deep or noisy work (broad searches, large log analysis) to a sub-agent with its own context, and take back only its conclusions and references.
- SHOULD record where each working fact came from (file and line, URL, command), so it can be re-checked instead of trusted.
- MAY compact proactively at natural boundaries (end of a task unit) rather than waiting for the window to fill.
When to apply
Section titled “When to apply”Any task longer than a few turns, any task that reads large files or logs, and any session that may be compacted, resumed, or handed to another agent.
Procedure
Section titled “Procedure”- Start a ledger (a file such as
progress.md, or the harness’s task list) with goal, done-criteria and the unit list. - Work one unit at a time. Load only what the unit needs.
- At each milestone, write to the ledger: what was done, the evidence, decisions, and what is next.
- Before compaction or handoff, make sure the ledger alone is enough to resume.
- After compaction or resume, read the ledger first and reload detail by reference.
# Ledger — add --json to parts CLIGoal: every data command supports --json (BP-0001). Done when: tests pass, jq parses output.- [x] U1 schema — schema/list.json; fixture validates (bun test schema)- [ ] U2 list --json — nextDecisions: field names snake_case (matches API). Open: does `show` include stock history?Touched: cmd/list.go, schema/list.jsonAnti-patterns
Section titled “Anti-patterns”- Reading the whole repository or every log at the start.
- Relying on “I saw that earlier” after the window has been compacted.
- A summary that keeps the narrative but drops the file paths and decisions.
- Letting a sub-agent return its full trace instead of conclusions.
- Keeping the only copy of the plan in the conversation.
Checklist
Section titled “Checklist”- Ledger exists and is current
- Context loaded by reference, just in time
- Bulky output summarised once used
- Facts re-read after compaction before acting