Multiple turns share a common KV cache prefix, forming a tree structure:
[system prompt + conversation history] β trunk (shared cache)
/ \
[branch A: question A] [branch B: question B] [branch C: question C] β branches (new computation)
Core properties:
Shared trunk: All branches reuse the parent's KV cache, no redundant computation** Independent branches**: Each branch's new tokens are computed independently** Cache reuse**: When switching branches, the common prefix cache remains available (within TTL)
Typical scenario: IM platform thread mechanisms. Each thread is a branch sharing the main thread's prefix cache. Usually, base information is pre-filled into cache first (e.g., project code/docs in coding scenarios), then different branches execute different tasks β each branch inherits the cached project context and only needs to compute its own task tokens.
Main thread (trunk)
βββ thread_A: fix bug β inherits trunk cache + bug description
βββ thread_B: add feature β inherits trunk cache + requirement description
βββ thread_C: write tests β inherits trunk cache + test scope
Each thread's cost β task description tokens (project context uses cache).
A temporary instruction injected at the end of a prompt, leveraging the KV cache bypass branch mechanism to perform specific tasks.
Tail prompts are a variant of cache trees β Cache Vine. One main trunk grows continuously, with leaves sprouting periodically; after leaves fall, the trunk continues growing.
[system prompt + conversation history] βββ trunk (accumulates continuously)
β
βββ [tail prompt A + question] β leaf (one turn, falls off)
β
trunk continues growing...
β
βββ [tail prompt B + question] β leaf (one turn, falls off)
β
trunk continues growing...
β
βββ [tail prompt C + question] β leaf (one turn, falls off)
Differences from cache trees:
| Dimension | Cache Tree | Tail Prompt (Vine) |
|---|---|---|
| Trunk | Shared trunk | Same, but trunk accumulates continuously |
| Branch | Persistent thread | Temporary leaf (one turn) |
| Lifecycle | Cross-turn, user-driven | Single turn, system-injected |
| Controller | User selects branch | System decides when to sprout leaves |
| Typical use | Multi-topic parallelism | Background tasks (compression, extraction, audit) |
KV cache (unchanged): [conversation history] β trunk
bypass branch (new computation): [tail prompt + user question] β leaf
β LLM completes both in a single turn: answer user + execute tail prompt task
β After turn ends, leaf falls off (tail prompt discarded), only results remain
Analogy to TCO (Tail Call Optimization): tail calls reuse the current stack frame; tail prompts reuse the current KV cache. Both are "tail" operations that reuse existing state.
Cache utilization: History portion uses KV cache; only the tail prompt is newly computed** Bypass branch**: Does not modify the main trunk (conversation history), only appends temporary instructions at the end** One-shot**: Removed from prompt after turn ends, not written to session** Control**: Injector decides when and what to inject; Agent only executes
Tail prompts use the vine pattern β one main trunk sprouts leaves, then continues growing. The compression scenario's special case β when the leaf falls, the preceding trunk is also replaced (checkpoint replaces old history).
KV cache (unchanged):
[ckpt_0] + [msg_101..msg_150]
Newly appended messages (only uncached portion):
tail prompt: "First answer the user's question, then analyze above conversation,
call memory_store to extract preferences/facts, mark checkpoint."
user message: "Why is Fluxora's component set closed?"
Agent completes three things in one turn (note order):
1. "Fluxora's component set is closed because..." β answer user question first
2. tool_call: memory_store(...) β then memory operations
3. tool_call: memory_checkpoint(...) β finally mark checkpoint
After turn ends, session stores clean history:
Stored in session:
[checkpoint_1] + ["Why is Fluxora's component set closed?"] + ["Fluxora's component set is closed because..."]
NOT:
[checkpoint_1] + [tail prompt + "Why is Fluxora's component set closed?"] + ["Fluxora's component set is closed because..."]
Tail prompt discarded, no residue.
| Dimension | Traditional Compression | Tail Prompt |
|---|---|---|
| LLM Call | Independent API call | Reuses Agent's normal turn |
| KV cache | Computes from scratch (0% hit rate) | History portion uses cache (~99% hit rate) |
| Attention | Fully concentrated on compression task | Split (answer user + execute task) |
| Control | Compression module controls | Injector controls (via prompt + tools) |
agent-memory.mdβ Tail prompt application in Prefix Checkpointgraph-memory.mdβ Extraction prompts in graph-structured memoryLLM Caching Destruction Patternsβ Cache branch patterns (thread) vs destruction patterns