In what order does prompt caching build its prefix?
Why B is the answer
Tools, then system, then messages
The prefix runs tools, system, then messages. Put stable content first, so that a change late in the request leaves the earlier cached parts usable.
In detail
- The prefix runs tools, then system, then messages.
- Put stable content first, so a late change leaves earlier parts usable.
- Order your request so that what changes least comes first.
Use case
An illustrative scenario, not a real incident.
A team splits its prompt into tools, system and messages. Tools and the system prompt rarely change, so they stay cached while each new message is added at the end.
See it in different ways
flowchart LR A["Tools"] --> B["System"] B --> C["Messages"] C --> D["New user turn"]
flowchart LR A["Tools"] --> B["System"] B --> C["Messages"] C --> D["Variable content last"]
flowchart LR S0["Tools"] --> S1["System"] --> S2["Messages"]
Key point: The cache prefix runs tools, system, then messages.
Why the other options are wrong
- A. System, then messages, then tools
- Tools come first, not last.
- C. Tools, then messages, then system
- System comes before messages.
- D. Messages, then system, then tools
- This is the reverse of the real order.

