Skip to content
AgenticAIWiki
  1. Learn
  2. Part 11
  3. 60. Summarization and compaction
  4. 60.3

Lesson 60.3 · 3 of 4 · 4 min read · Reviewed 24 Nov 2026

Context editing and clearing tool results

By the end, you can

  • Compare clearing tool results with summarising.
  • Pick the lighter technique first.

Two tools reduce context. Use the lighter one first.

Clearing tool results Summarising history
What it removes Raw content of old tool results Old turns, replaced by a summary
Cost Almost none A model call
Risk Low, if the results were used Can drop or distort details
Best when Results dominate the context The conversation itself is long

In practice

  1. Return lean tool results in the first place.
  2. Clear old results automatically (context editingContext editing: Removing or replacing parts of an agent’s context, such as old tool results, while it runs., 54.6, or your own code).
  3. Summarise only when the conversation alone is getting too long.
  4. Keep critical facts outside both, in a pinned block or notes file (60.4).

Key points

  • Clearing old tool results is cheap and loses little if the results were already used.
  • Summarising history costs a model call and can lose detail.
  • Try clearing tool results first; summarise only when the conversation itself is too long.
Hands-on labRuns in the Playground

Compare clearing with summarising

Simulate a long agent run and compare two ways of shrinking its context: clearing old tool results and summarising history, by tokens, extra model calls and facts lost.

You will have: A side-by-side table for the two strategies and a recommendation printed by the script.

Steps

  1. Read the RUN: 48 tool results of 2,000 tokens, 24,000 tokens of conversation, and 6 facts spread through it.
  2. Strategy A, clearing: keep the 4 newest results, replace the rest with 50-token placeholders that keep their fact.
  3. Strategy B, summarising: replace everything older than the last 10 turns with a 1,500-token summary; assume 1 in 6 facts is lost.
  4. Print tokens after, extra model calls and facts lost for each.
  5. Print which strategy to try first and why.

Done when

  • Clearing brings the context to about 34,200 tokens with 0 extra calls.
  • Summarising needs at least 1 extra model call.
  • The script recommends clearing first.

Open in the Playground No API key needed.

Starter code (Python)
RESULTS, RESULT_TOKENS, CONVERSATION, FACTS = 48, 2000, 24000, 6

def clearing(keep=4, placeholder=50):
    # TODO: return {"tokens": ..., "extra_calls": 0, "facts_lost": 0}
    return {"tokens": 0, "extra_calls": 0, "facts_lost": 0}

def summarising(recent_tokens=8000, summary=1500, loss_rate=1 / 6):
    # TODO: return {"tokens": ..., "extra_calls": 1, "facts_lost": ...}
    return {"tokens": 0, "extra_calls": 0, "facts_lost": 0}

before = RESULTS * RESULT_TOKENS + CONVERSATION
print("before:", before)
for name, r in (("clearing", clearing()), ("summarising", summarising())):
    print("%-12s %s" % (name, r))
Show a solution
RESULTS, RESULT_TOKENS, CONVERSATION, FACTS = 48, 2000, 24000, 6

def clearing(keep=4, placeholder=50):
    tokens = CONVERSATION + keep * RESULT_TOKENS + (RESULTS - keep) * placeholder
    return {"tokens": tokens, "extra_calls": 0, "facts_lost": 0}

def summarising(recent_tokens=8000, summary=1500, loss_rate=1 / 6):
    return {"tokens": recent_tokens + summary, "extra_calls": 1, "facts_lost": round(FACTS * loss_rate)}

before = RESULTS * RESULT_TOKENS + CONVERSATION
print("before:", before)
a, b = clearing(), summarising()
for name, r in (("clearing", a), ("summarising", b)):
    print("%-12s %s" % (name, r))
print("recommend: clearing first (no extra calls, no facts lost); summarise only if the conversation itself is too long")
Quick checkAn agent's context is 80% old tool results and 20% conversation. What's the lightest effective step?
How sure are you?
Pick an answer and how sure you are