Lesson 13.04 · Phase 13 · Production Agents

Prompt caching & latency

An agent sends nearly the same prompt on every step. Put what never changes first, what always changes last, and the provider can skip re-reading most of it.

Learning objectives

  • Explain prefix caching: why it rewards prompts whose beginning is identical from call to call, and what breaks it.
  • Compare three layouts of the same agent prompt on a simulated provider: input tokens served from cache, cost and time to first token.
  • Recognise cache-breakers in agent code: timestamps at the top, unstable tool order, edits to early history.
  • Cut agent latency with parallel tool calls and a cache for read-only tool results, measured in real time.

An agent with a 1,500-token system prompt and 2,000 tokens of tool schemas sends both on every step. At step 8 the history adds a few thousand more. Most of each prompt is identical to the one before it, yet if nothing is reused you pay for it all, and wait for it all to be processed, eight times.

Loading the full lesson…