Skip to content
← Notebook

Agent Engineering

Context Engineering in 2026: How to Beat the 2 Types of Context Bloat (Definitions vs Results) in AI Agents

Attention collapse and wasted tokens aren't solved by enlarging the context window. A dissection of Progressive Disclosure (Skills), Isolated Subagents and Tool Clearing for production.

Date
Oct 13, 2026
Reading time
9 min
Result
>70% Start-up Token Savings • Subagent Isolation • Context Rot Prevention • Dual Track

Translated from the Spanish original. The code, data and READMEs on GitHub are in Spanish.

During the first years of the language model explosion, engineers focused exclusively on Prompt Engineering: fine-tuning adjectives, designing meticulous system prompts and experimenting with Chain-of-Thought. However, as models have gone from static chatbots to long-running autonomous agents that interact with tools, run code and sustain decision loops over dozens of turns, the bottleneck has changed radically.

In 2026, the decisive discipline is Context Engineering: the art and science of curating and managing the minimal set of high-signal tokens that maximises the probability of an agent making the right decision.

The naive belief that giant context windows (1M or 2M tokens) would solve this challenge has been disproved by the harsh reality of production. Research on Context Rot shows that saturating the window isn’t just ruinously expensive: it drastically degrades the model’s attention, multiplies hallucinations and triggers endless error loops.

In this engineering notebook from YesWeLab (@Yeswelab_OU) we break down the anatomy of Context Bloat, its two critical variants (Definition Bloat and Result Bloat) and the architectures from the trenches to eradicate it in both open-source environments and enterprise SaaS.


1. The Giant Window Trap and the ‘Context Rot’ Phenomenon

When a novice developer faces a context problem, their first instinct is usually to migrate to a model with a bigger window or to pile up the whole conversation history, trusting global attention.

Needle-in-a-haystack retrieval studies and research on attention degradation in autonomous agents have formalised the concept of Context Rot:

[ CONTEXT ROT: ATTENTION VS CONTEXT VOLUME ]
Accuracy
100% ────┐
         │ (Optimal zone: <30k high-signal tokens)
         │───────────┐
 50%                 │ (Context Rot: diluted attention weights)
                     └─────────────────────────────┐ (Collapse / Loops)
  0% ──────────────────────────────────────────────┴───────────────►
     0k      40k      80k      120k     160k     200k+    Tokens

As the history fills up with API calls, SQL dumps and tool schemas, the model’s attention spreads across thousands of irrelevant tokens. Even if the window accepts 200,000 tokens, performance degrades long before reaching the physical limit. The agent loses track of the initial instructions, confuses tool parameters and starts to suffer what Anthropic calls “context anxiety”: premature task closures or stochastic retry loops.

To fix this collapse, the first step is diagnosing which of the two types of Context Bloat you’re facing.


2. The Two Faces of Context Bloat: Initialisation vs Execution

Context bloat isn’t a uniform problem. It happens at two completely different moments in the agent’s lifecycle and requires different architectural levers:

Dimension Tool Definition Bloat Tool Result Bloat
When it hits Session initialisation (Turn 0). During execution (Turns 1 to N).
Root cause Mass loading of MCP / OpenAPI schemas into tools. Accumulation of payloads returned by the tools.
Analogy The 500-page menu problem. The filing cabinet on the desk problem.
Consequence Fixed per-turn cost skyrockets before any interaction. Diluted attention (Context Rot), latency and loops.
Main solution Progressive Disclosure (Skills) / Tool Search. Isolated Subagents / Tool-Result Clearing.
                       ┌──────────────────────────────────────────────┐
                       │            THE AGENT LIFECYCLE               │
                       └──────────────────────┬───────────────────────┘
                                              │
              ┌───────────────────────────────┴───────────────────────────────┐
              ▼                                                               ▼
   [ 01. INITIALISATION ]                                          [ 02. EXECUTION ]
   Tool Definition Bloat                                           Tool Result Bloat
   • 50+ MCP servers connected                                     • Raw SQL / API dumps
   • Giant JSON / OpenAPI schemas                                  • Logs, traces and web pages
   • 50,000 - 130,000 initial tokens                               • Pile-up in the history
              │                                                               │
              ▼                                                               ▼
   SOLUTION:                                                       SOLUTION:
   Progressive Disclosure & Skills (L1-L3)                         Isolated Subagents & Tool Clearing

Problem 1: Tool Definition Bloat (The 500-Page Menu)

When we connect a typical enterprise MCP ecosystem (connectors for GitHub, Slack, Linear, PostgreSQL databases, Jira and AWS), each server exposes its JSON schemas with names, descriptions and parameter types.

According to Anthropic’s engineering metrics, loading 58 common tools consumes about 55,000 tokens before the user sends a single word. In complex setups, tool definitions can exceed 134,000 tokens (67% of a 200k window).

Imagine walking into a café and being forced to memorise a 500-page legal catalogue before ordering a latte. That’s exactly what we do when we inject every tool into an agent’s prompt up front.

Problem 2: Tool Result Bloat (The Filing Cabinet on the Desk)

This one happens throughout execution. Every time an agent runs a database query, reads a log file or scrapes a website, the raw result is appended to the message history (role: tool_result).

If an agent reads a 40,000-token log file to find a single error message on line 320, those 40,000 tokens stay in the history for every subsequent turn. In a 10-turn session, the agent will pay for and process those 40,000 tokens over and over again, speeding up the arrival of Context Rot.


3. Beating Definition Bloat: Progressive Disclosure and the Skills Architecture

The fix for definition bloat isn’t to cut tools arbitrarily, but to apply the principle of Progressive Disclosure through the open Skills standard.

A Skill packages a complete capability (instructions, schemas, examples and scripts) into a hierarchy organised in three layers:

┌────────────────────────────────────────────────────────────────────────┐
│ LEVEL 1: THE CATALOGUE (Always in active context, <500 tokens)          │
│ • Name + a 50-character activation trigger.                            │
│   Example: "database-query: Read-only analytical SQL queries"           │
└───────────────────────────────────┬────────────────────────────────────┘
                                    │ (If the task needs the skill)
                                    ▼
┌────────────────────────────────────────────────────────────────────────┐
│ LEVEL 2: THE PLAYBOOK (Loaded into context on demand)                   │
│ • Operating instructions, validations and tool schemas.                 │
└───────────────────────────────────┬────────────────────────────────────┘
                                    │ (If it needs helper code or docs)
                                    ▼
┌────────────────────────────────────────────────────────────────────────┐
│ LEVEL 3: THE APPENDIX / SCRIPTS (Loaded in the execution sandbox)      │
│ • Deterministic Python scripts, templates and reference tables.        │
└────────────────────────────────────────────────────────────────────────┘

With this architecture, an agent can have access to 200 different tools with an initial consumption of under 1,000 tokens. Heavy tools are only loaded into the window when the agent identifies the need to use them through dynamic search (Tool Search).


4. Beating Result Bloat: Isolated Subagents and Tool-Result Clearing

To mitigate the pile-up of raw data during execution, we have two complementary engineering patterns:

1. Isolated Subagents (Isolated Child Contexts)

Instead of letting the main agent clutter its own memory with exhaustive exploration, we delegate the heavy lifting to an ephemeral subagent.

[ MAIN ORCHESTRATOR ]
   │
   ├─► Spawn subagent (specific goal, clean context of 0 tokens)
   │     │
   │     ├─► Runs tool A (15,000 tokens)
   │     ├─► Runs tool B (25,000 tokens)
   │     ├─► Analyses and filters locally
   │     │
   │     └─► Returns ONLY: a typed summary (1,200 tokens)
   │
   ▼
[ ORCHESTRATOR CONTEXT ]  <-- Stays clean and nimble

The subagent may consume 50,000 tokens reading logs or making HTTP requests, but when its mission ends, its context is destroyed. Only the 1,000-token synthesised report reaches the main orchestrator.

2. Surgical Tool-Result Clearing

Many tool results can be retrieved on demand (the contents of a local file or a timestamped API response). Keeping the full payload in the history after it’s been consumed adds no value.

With the Tool Clearing pattern (natively available in APIs such as Anthropic’s Context Editing with clear_tool_uses), the engine walks through the historical messages and replaces heavy result blocks with lightweight synthetic markers:

// BEFORE (history bloated with 35,000 tokens)
{
  "role": "tool_result",
  "tool_use_id": "call_123",
  "content": "[... 35,000 lines of raw SQL dumps ...]"
}

// AFTER (with Tool-Result Clearing applied: 25 tokens)
{
  "role": "tool_result",
  "tool_use_id": "call_123",
  "content": "[RESULT_CLEARED: Query ran successfully. 3 anomalies detected and summarised in turn 3]"
}

The agent keeps the certainty that it made the call and the verdict it reached, but frees up 99% of the tokens in its attention window.


5. Dual Track Implementation at YesWeLab

At YesWeLab we apply our Dual Track philosophy to solve Context Engineering, adapting to each project’s operating constraints:

                           ┌──────────────────────────┐
                           │  THE DUAL TRACK PHILOSOPHY│
                           │       AT YESWELAB        │
                           └─────────────┬────────────┘
                                         │
             ┌───────────────────────────┴───────────────────────────┐
             ▼                                                       ▼
   [ TRACK A: DIY / OPEN SOURCE ]                          [ TRACK B: FAST-TRACK SAAS ]
   • Full autonomy, $0 extra inference cost                • Zero infrastructure friction
   • Local models or direct endpoints                      • Managed SLAs and compliance
   • Orchestration with Hermes / LangGraph                 • Anthropic Context Editing & Compaction
   • Local subagents in isolated CLI processes             • Claude Agent SDK with native memory tool
   • Local sandboxes (Python/Bash) for filtering           • Transparent server-side purging
   • Persistence in SQLite WAL & Markdown files            • Automatic token management for enterprise

Track A: The Open-Source, Local Route ($0 Cost)

For developers, solopreneurs and teams who want absolute control and data privacy:

  1. Subagents in isolated subprocesses: Launch subagents with bounded tools via CLI (such as Hermes’s delegation command or sub-graphs in LangGraph), running in child processes with their own memory environment.
  2. Programmatic filtering with code (Sandboxing): Instead of dumping a 20 MB JSON file into the model’s window, the agent runs a Python script in a sandbox that filters the relevant records with Pandas/SQLite and returns only the aggregated table.
  3. External memory in SQLite WAL: Store the full event history in a local SQLite database in WAL (Write-Ahead Logging) mode. The agent keeps a lightweight state of notes in Markdown (NOTES.md) and queries the database only through targeted queries.

Track B: The Fast-Track SaaS Route (Enterprise)

For corporate organisations where the priority is deployment speed, regulatory compliance and production stability:

  1. The Context Editing API (clear_tool_uses): Turn on automatic purging of tool results in the inference platform to keep context growth below predefined thresholds.
  2. Native server-side compaction: Use server-side compaction mechanisms that distil the full history while preserving architectural decisions and critical dependencies, with no operational friction.
  3. Claude Agent SDK & Memory Tool: Integrate the persistent memory tool (in public beta) for multi-session projects without needing complex embedding or RAG pipelines.

6. A Checklist from the Trenches: Audit Your Agents Today

Before launching your next fleet of autonomous agents, go through these 5 operating rules:

  • 1. Start-up budget (<3,000 tokens): Do your tool schemas consume more than 5,000 tokens at start-up? If so, migrate immediately to a Skills catalogue with Progressive Disclosure.
  • 2. Heavy-task isolation rule: Any web search, document scraping or massive analytical query must run in an isolated subagent or code sandbox, never in the orchestrator’s context.
  • 3. Pruning stale results: Implement Tool Clearing for tool results whose value has already been processed and synthesised in the conversation.
  • 4. An external notebook: Give your agent a structured memory tool (a notes file or a local database) so it can save states and dependencies without relying on the active window.
  • 5. Context Rot alert: Monitor context length on every turn. If your workflow goes past 50,000 tokens without compaction or pruning, assume the probability of hallucination or looping triples.

The success of agentic artificial intelligence in 2026 doesn’t depend on the size of your context window, but on the rigour with which you protect your models’ attention.

#Model Context Protocol (MCP)#Agent Skills Standard#Subagent Workflows#Context Editing API#SQLite WAL#Python Sandbox