Why Modern AI Agent Harnesses Converge on the Same Memory Management Strategy
The article compares Pi, OpenClaw, Claude Code, and Letta, showing how each framework tackles limited context windows through file truncation, pagination, tool‑result budgeting, sub‑agent isolation, and token‑driven compaction, revealing a clear convergence toward active memory management.
This article compares four AI agent frameworks—Pi, OpenClaw, Claude Code, and Letta—on how they handle the limited context window, covering file truncation, pagination, tool‑result budgeting, and session compression strategies. The analysis shows a strong convergence toward active context management.
Problem Statement
All harnesses face a small context window that cannot contain everything the model might need to remember. As sessions grow, file reads expand, sub‑agents multiply, and tool outputs accumulate, forcing the harness to decide what stays in the working set, what is compressed, and what is retrieved later.
Design Principle
The best systems treat the context window as actively managed memory rather than a passive transcript buffer. They keep high‑value state close to the model, page data on demand, build indexes for fast lookup (similar to grep), and provide cues for further access.
File‑Reading Strategies
Pi (pi‑mono) : imposes a hard limit of 2,000 lines or 50 KB, truncating from the start and adding a continuation prompt such as "[Showing lines 1‑2000 of 50000. Use offset=2001 to continue.]". The harness takes priority, protecting the user before teaching the model to paginate.
OpenClaw : inherits Pi’s 2 K line/50 KB limit and adds a bootstrap file cap of 12 000 characters per file (60 000 total). When a bootstrap file exceeds its budget, it keeps 75 % of the head and 25 % of the tail. Tool results have a separate budget of 16 000 characters or 30 % of the context window, whichever is smaller, and switch to a head‑plus‑tail mode when the tail appears important.
Claude Code : uses a two‑layer guard. Before reading, a stat call checks a 256 KB byte limit; if exceeded, the read is rejected with an error prompting the model to use offset/limit or grep. After reading, output is limited to a 25 000‑token budget. By default it returns the first 2 000 lines; larger files require explicit offset/limit. It also deduplicates repeated reads by returning a stub when the file has not changed.
Letta : parses each uploaded file into chunks and embeddings, offering three tools—open_files, grep_files, and semantic_search_files. It applies per‑file character caps that scale with model context (e.g., 5 000 chars for an 8 K context model, up to 40 000 chars for 200 K+ context). An LRU policy evicts the least‑recently accessed files, supporting up to 15 open files for the largest models.
Session Pruning (Compaction)
Pi : triggers when estimated tokens exceed contextWindow - reserveTokens (default reserve 16 384). It keeps the most recent ~20 000 tokens, summarizes older content into a synthetic user message placed before the retained tail, and guarantees that tool‑call/result pairs remain intact.
OpenClaw : builds on Pi’s compaction and adds two layers. When history exceeds 50 % of the window, it splits history into equal‑token blocks, discards the oldest, repairs tool‑call/result pairing, and runs multi‑round LLM summarization with a merge step. Before loss, a silent agentic turn flushes state to a memory file. It also performs non‑destructive in‑memory pruning of tool results (soft‑trim then hard‑clear) with a 5‑minute TTL.
Claude Code : triggers when tokens exceed the context window minus a 13 000‑token buffer (≈167 K tokens for a 200 K context model). It sends the full conversation to the LLM with a structured nine‑part prompt covering primary request, technical concepts, files, errors, problem solving, user messages, pending tasks, current work, and optional next steps. The summary becomes a user message indicating continuation. After compaction, up to five most‑recent files are re‑attached under the token budget. Summarizer safety is ensured by generating analysis scratchpads that are stripped before insertion. If compaction itself hits the limit, a deterministic head‑drop removes the oldest API‑round groups. Large tool results are persisted to disk with a 2 KB preview; tool limits are 50 000 characters, and aggregated messages have a 200 000‑character cap.
Letta : triggers at 90 % of window usage. It evicts messages starting from 30 % of the transcript and increases the eviction rate by 10 % each round until usage falls below the target, keeping recent messages and discarding the oldest. It uses a self‑compact mode where the agent itself summarizes, avoiding a separate summarizer cost. A two‑stage fallback first clamps tool output to 5 000 characters; if overflow persists, it truncates the transcript to keep 30 % head and 30 % tail. An independent 75 % memory‑warning threshold alerts before the 90 % compaction trigger.
Sub‑Agent Context Management
All four harnesses isolate sub‑agents from the parent session. Pi spawns a new process with only the task string as the user message, omitting parent history. OpenClaw defaults to fresh isolated sessions with an optional fork mode that copies the parent transcript for same‑agent spawns, filtering the workspace to an allowlist (e.g., AGENTS.md, TOOLS.md, SOUL.md). Claude Code offers a typed‑agent path that creates an empty dialog and a newer fork path that copies the full parent history, injects a synthetic assistant message, and adds placeholder tool results; async agents receive an explicit allowlist of tools. Letta runs tools in the main agent loop and accesses historical context via dedicated search tools (conversation search and archival memory search).
Design Convergence
After comparing the four codebases, the most striking observation is not the differences but the strong consensus: all harnesses impose hard file limits, support offset/limit pagination, cap tool result size, isolate sub‑agent sessions, and run token‑threshold‑driven LLM compaction with usage estimation. These shared patterns constitute a convergent solution to the engineering problem of a fixed‑size working set that must feel virtually unlimited.
Design details also rhyme: Pi and OpenClaw both truncate file heads and add continuation prompts; Claude Code and OpenClaw both persist oversized tool results to disk; Pi, OpenClaw, and Claude Code all enforce tool‑call/result safety during compaction; three of the four support forking the parent transcript to sub‑agents. The convergence extends beyond coding agents; Arize’s Alyx assistant for data exploration follows the same playbook, limiting tool results to a 10 000‑token budget, using binary search to find the maximal slice, deduplicating tool calls, splitting large JSON payloads into preview and full copy, estimating token pressure with a char/4 heuristic, and forcing a checkpoint at 50 000 tokens.
Conclusion
Fifty years of computer architecture teach that the best memory management is invisible to the program. Agent harnesses are moving toward the same direction: instead of dumping everything into the context, they provide the model with a well‑managed work set at the right time, allowing the model to make dynamic decisions and manage its own context.
High Availability Architecture
Official account for High Availability Architecture.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
