R504 · Agent architecture › Memory and context

Context is spent now, memory is kept: a harness view of agent memory

Read the original

agent-memorycontext-engineeringcompactionprompt-cachingpermissionsexplainerclaim-checking

Source: Sonpaorong Muchhim, LinkedIn post with an animated diagram, "Agentic Memory: short-term vs. long-term, inside the agent harness" (posted about 2026-12-01). No linked paper or repository: this is a practitioner explainer, so the summary checks its arithmetic and its model rather than any benchmark.

For: staff engineers designing or reviewing an agent harness that runs long, multi-step, permissioned work.

The claim in one paragraph

Agent reliability is decided less by the model than by the harness that controls what enters each model call. The harness owns two layers: the context window (short-term, spent on this call) and long-term stores (kept across sessions). Models are swappable; the memory you build is the durable asset. Four things have to be right: context is a compounding cost, memory management is core engineering, more memory can mean more noise, and reliability is not only in the weights.

The arithmetic, checked

The post's cost example holds. If every call resends the whole context, starting at C0 tokens and growing by d per step, N calls consume N·C0 + d·N(N−1)/2 input tokens.

CallsStartGrowth per stepInput tokens
2020K3K400K + 570K = 970K
4020K3K800K + 2,340K = 3.14M

The second term is quadratic, so doubling the steps costs 3.2 times the tokens. Three things the example leaves out:

The model in the diagram

The GIF animates a ten-step loop around a two-layer memory:

  1. Users send a request (and get the reply).

  2. The orchestrator assembles the context.

  3. Long-term memory is retrieved: search, rank, inject.

  4. More is loaded on demand during the task.

  5. The LLM reasons over the context and picks tools.

  6. A human approves high-risk actions.

  7. Tools act on real systems (APIs, MCP servers).

  8. Results enter the context.

  9. Auto-compaction fires as the window fills (the frame shows it "62% full", illustrative).

  10. Outcomes and lessons are written back to long-term memory.

Layer 1, the context window, is drawn as a stack. The bottom is loaded at session start and prompt-cached: system prompt, tool and MCP definitions, memory files. Above it, added during the task: retrieved memory, conversation history, tool results, then free space for reasoning and output. Three controls act on it: load on demand, auto-compaction, clear tool results.

Layer 2, long-term memory, is split by kind: semantic (facts and domain rules, in graph and vector stores), episodic (past cases and outcomes, in session logs), procedural (how the work gets done, in memory files and playbooks) and user profile (preferences, role, tone). Maintenance is listed as deduplicate, update, expire, delete on request.

Also in the harness: skills loaded when needed, subagents with isolated windows, state (plans and checkpoints), loop control (stops, retries, limits), a sandbox, guardrails (permissions, injection defence), and evals and tracing.

Where it is strong

Where it is thin

Failure modes to design against

Review checklist

The visual

The author's animated diagram (© Sonpaorong M.) is not reproduced here. See the original post on LinkedIn: https://www.linkedin.com/posts/sonpaorong-m_aiengineering-aiagents-agentharness-share-7533610981978161152-BEAf/

Connections

See R504 on the knowledge map

Part of the Research notes on nowucca.com. Figures and claims are the source's own unless the summary says otherwise.