Flows category icon
Memory & Context
Intermediate

Prompt-Cache-Aware Conversation Design

Structure your agent's context for prefix caching: stable prefixes, append-only history, and cache-friendly dynamic content.

3 steps9 verify checks45-75 minutesWorks with: emergent · chatgpt · claude · cursor
Start Guided Walkthrough

The Route

0/3 verified

Context Pack

Paste this first. It briefs the AI on requirements, constraints, and the Definition of Done before your first build prompt.

Context Pack
PROJECT CONTEXT:
My agent's API bills and latency grow with every turn because each call re-processes the whole context. Provider prompt caching can cut both dramatically - but only if the context is laid out so prefixes stay byte-stable.

GOAL:
Restructure context assembly for maximum cache hits: stable-first ordering, append-only history, and isolation of volatile content.

REQUIREMENTS:
- Context ordered stable-first: system prompt, tool definitions, then history, then volatile state
- History strictly append-only between compactions - no in-place edits to old turns
- Volatile content (timestamps, usage counters) moved out of the cached prefix
- Cache breakpoints/markers applied per provider requirements
- Before/after measurement of cached vs uncached token ratios

CONSTRAINTS:
- Never sacrifice correctness for cache hits - compaction still wins when needed
- Cache behavior must be verified from API response metadata, not assumed

DEFINITION OF DONE:
- Multi-turn sessions show high cached-token ratios in API metadata after turn 1
- No per-turn mutation of the system prompt or old history remains
- Cost per turn measurably drops versus the pre-optimization baseline
- Compaction and cache design coexist: cache resets at compaction are accepted and logged

COMMON FAILURES TO AVOID:
- A timestamp in the system prompt silently killing the cache every turn
- Re-sorting or rewriting history each call so no prefix ever matches
- Injecting the dynamic plan reminder at the top instead of the tail
- Claiming cache wins without reading the usage fields that prove them

Paste this into your AI builder first. It teaches the AI what you want before you give it the build prompt.

Related routes

More Memory & Context flows that share ground with this one.

Flows category icon
Memory & Context

Add File-Based Persistent Memory

Give your agent durable memory with plain files - the radical-minimalism approach production practitioners keep converging on.

01Design the memory file structure
02Load memory at session start
03Build the guarded memory_update tool

+1 more steps to Done

Best foryour first pass at this - no prior setup assumed

4 steps45-75 minutesBeginner
Flows category icon
Memory & Context

Cross-Session Project State

Keep long-horizon work coherent across many sessions: externalized project state that any session can load, advance, and hand off.

01Design the project-state document
02Implement the session-start protocol
03Implement the session-end advance

+1 more steps to Done

Best forproduction-grade builds with strict verification

4 steps90-120 minutesAdvanced
Flows category icon
Memory & Context

Design a Memory Index Loaded Every Session

Build the pattern behind minimalist memory systems: a compact index file the agent always loads, pointing to detail files it loads on demand.

01Structure the index and details
02Wire loading: index always, details on demand
03Maintain the index as memory evolves

Best forbuilders who have shipped a basic app before

3 steps60-90 minutesIntermediate

Made with Emergent