Top 5 · 2026-05-23 · source-backed
Three API Primitives Cut a Research Agent's Context From 335K Tokens to 50K. Here's How.
Story
Context engineering just got its cookbook.
Anthropic's Claude Cookbook published a complete guide to three API-level primitives that, used together, reduced a research agent's peak context from 335K tokens to a sustained 50-80K range. Server-side compaction. Tool-result clearing. Persistent memory. Each one is simple. Together they change the economics of long-running agents.
Compaction triggers at a configurable token threshold (the cookbook uses 150K) and distills the conversation to a summary, preserving key decisions while dropping the narrative. Tool-result clearing replaces bulky tool outputs with [cleared] placeholders at zero inference cost, because tool results are almost always re-fetchable. Persistent memory stores cross-session state in files the model manages itself.
The diagnostic framework is the part I keep thinking about. If more than 80% of your context is re-fetchable tool output, use clearing first. If long dialogue accumulates, add compaction. If work spans sessions, add memory. That's not a recipe. It's a decision tree. And it works because it forces you to ask the right question: what in this context window is actually load-bearing?
I run a research agent pipeline every day in my personal projects. Context bloat is the single biggest reliability problem I hit. Agents get dumber as context fills up. They start ignoring earlier instructions. They lose track of what they've already done. The fix isn't a bigger context window. It's being surgical about what stays in it.
The cookbook also introduces the "Summarize up to here" option in Claude Code's Rewind menu. Manual mid-conversation compaction. Use it after completing a major milestone to reclaim token budget while preserving key decisions. Claude Code docs confirm this shipped recently.
For builders: implement tool clearing before anything else. If your agents call tools that return large JSON payloads, you're paying to re-read that data on every subsequent turn. Clear it after extraction. The cost savings compound with every interaction.
Related stories
Each link below shares sources, entities, or timing with this story.
Shared entities / Same source / Shared topic / What happened next
Know the difference between compaction and agentic memory, and use both.
Both cover Anthropic, Compaction; cite the same source (Anthropic's Claude Cookbook); overlapping topics (agent, compaction, context, memory).
Shared entities / Shared topic / Earlier coverage / Downstream implication
Anthropic Published How They Actually Build With Claude Code. It's Two Agents, Not One.
Both cover Anthropic, Each, JSON; overlapping topics (agent, context); earlier Anthropic coverage from 2026-03-24.
Shared entities / Shared topic / Earlier coverage
Your Claude Code Was Running at 1/5th Context. Nobody Told You.
Both cover Claude Code, Context, Tool; overlapping topics (agent, context, tool); earlier Claude Code coverage from 2026-04-23.
Today's Skills
Both cover Anthropic, Claude Code, Each; overlapping topics (agent, context, token); earlier Anthropic coverage from 2026-03-12.
Shared entities / Shared topic / What happened next
Compaction: distill your agent's context before it hits 100% and cut tokens 84%
Both cover Anthropic, Compaction; overlapping topics (agent, compaction, context, cost, token); picks up the Anthropic thread on 2026-06-04.
Shared entities / Shared topic / Earlier coverage / Tension
Stripe Shows Its Cards: Minions Blueprint Architecture Uses 400 Tools, Deploys ~15 Per Run, and Ships 1,300+ PRs Weekly
Both cover Claude Code, Each; overlapping topics (agent, context, decision, tool); earlier Claude Code coverage from 2026-03-25.
Shared entities / Same source domain / Shared topic / Earlier coverage
Skills You Can Learn Today
Both cover Claude Code, Context; reported by the same outlet (code.claude.com); overlapping topics (context, token, tool).
Shared entities / Shared topic / Earlier coverage
75,000 Stars on 18 Markdown Files. Agent Skills Ate Open Source.
Both cover Claude Code, Context, Each; overlapping topics (agent, output); earlier Claude Code coverage from 2026-05-22.
Source trail
Entities
Provenance
- Canonical issue
- Ramsay Research Agent — May 23, 2026
- AI generated
- no
- Story unit
- 2026-05-23-three-api-primitives-cut-a-research-agent-s-context-from-335k-tokens-to-50k-here-s-how
- Labels
- source-backed, canonical briefing excerpt