Zenaique

Spot the context engineering error in this tool result handling code

Spot the error·Medium·4.0 · 0·~2 min·Asked atLtimindtreeSnowflakeTypeface
Attempt it

Click any words you think contain an error. Click again to unmark.

Mark at least one word to submit.
TL;DR

The snippet shoves growing tool results into the system prompt, which destroys prompt caching and dumps tool outputs into the lost-in-the-middle trough at the same time.

Memory aid
Sign in to see the mnemonic that makes this stick.
Easy to grasp

Picture a noticeboard at a coffee shop with a sign that says 'this stays the same all day.' If the barista starts pinning every customer's receipt to that board as the day goes on, two things break. The 'stays the same' promise is gone, so any system that was relying on it stops working. And the board fills up so fast that the original menu, the thing customers actually need, is buried under three months of receipts. The system prompt is that noticeboard. Tool results are the receipts. They belong in a different place, and old ones should come down when they are no longer useful.

Concept explanation~2 min read

Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.

This snippet is short, but it manages to violate three independent context-engineering principles at once, and the violations interact in a way that makes the design strictly worse than either violation alone. The right way to read it is to take each claim at face value, trace what actually happens at the byte level, and watch the contradictions surface.

The design says: (1) tool results go in a persistent list in the system prompt, (2) tool results are never removed, and (3) the same system prompt is sent every turn for prompt-caching benefits. Read carefully, claims 1, 2, and 3 cannot all be true at the same time. The system prompt cannot be both "the same on every turn" and "the place where new tool results are appended on every turn."

Why the prompt-caching claim is structurally impossible

Prompt caching on Anthropic, OpenAI, and Google all share one property: the cache key is the literal byte sequence of the cached prefix. When the prefix matches byte for byte across two requests, the second request reuses the cached state; when it differs by even one character, the cache misses and the model recomputes from scratch.

The snippet says the system prompt is sent the same every turn. The snippet also says tool results are appended to a list inside the system prompt on every turn. Both cannot be true. After the first tool call, the system prompt has one extra result. After the second, it has two. The byte sequence is different on every request, the cache key shifts on every request, and the cache rate is zero.

The error survives because each half of the design looks correct in isolation. "Cache the system prompt for cost savings" is a textbook-correct move. "Put persistent state in the system prompt so it is always available" is plausible-sounding. The combination is incoherent. Sniffing out this incoherence is the spot the error skill the question is testing.

The fix is to relocate the mutating content out of the cached span. Tool results go into the conversation message sequence, in the uncached tail. The system prompt becomes truly byte-stable and the cache actually hits.

Why the system prompt is the wrong home for tool results regardless
The missing eviction policy
The fix and the framework lesson
Sign in to unlock the full deep dive.

Situations where this technique stops working.

Sign in to see when this approach fails.

2–4 min · Everything important, quickly.

Sign in to see the quick scan of the deep dive.

Real products, models, and research that use this idea.

  • Anthropic's Claude tool-use format threads tool_result blocks directly into the conversation, with the system prompt reserved for stable persona and tool schemas.
  • OpenAI's Responses API places tool_calls and their outputs as separate message events in the response stream, never as system-prompt content.
Sign in to see more production examples.

What an interviewer would ask next. Try answering before peeking at the approach.

QIf you wanted some tool results to be durable across many turns, what is the right way to do it without breaking the system-prompt cache?
A

Store the durable observations in agent state (LangGraph typed state, a memory store, a vector index) rather than in the prompt text. Expose a recall_observation(id) tool the model can call when it needs an older result. The system prompt stays cacheable, and durable content is fetched on demand into the recency end of context where attention is strong.

2 more follow-ups an interviewer would ask next. Sign in to reveal them.

Red flags & common mistakes

The phrases that signal junior thinking. Click to expand.

Most common mistake

Conflating 'I want this content to be cached' with 'put it in the system prompt', caching only works while the block is byte-stable, which a growing tool log never is.

Sign in to see all red flags and common mistakes.

60 second bullets to scan on the way to the call.

  • Identify which property of prompt caching the snippet violates

  • Explain why the system prompt is the wrong location for mutating tool results

Sign in to unlock the revision sheet.

Primary sources. Browse if you want the original framing.

Similar questions

Same topic, related formats. Practice these next.

4 curated
Next question
Pick the most effective intervention when an agent's context grows by 8KB every iteration
MCQ·Medium