Stable policy comes first; volatile evidence remains late, isolated, and non-authoritative.
AI infrastructure · TypeScript
Versioned Prompt Prefix Layout
Reusable context belongs in a stable prefix; volatile evidence belongs at the edge.
const promptVersion = 'sales-agent/policy/v7'
const input = [
systemPolicy, // stable application policy
toolSchemas, // stable contracts
`Prompt-Version: ${promptVersion}`,
tenantPolicy(tenantId), // isolated tenant layer
sessionSummary, // compact memory
retrievedEvidence, // volatile, untrusted
userRequest, // volatile
]
// Record model, version, cached tokens, outcome, and latency.
// A cache miss must affect only cost or latency.Invariant: A cache miss changes cost or latency, never policy, authority, or correctness.
Use when: Agent calls should reuse stable context without treating cache as memory.
Why this boundary matters
Volatile values near the beginning invalidate reusable context. Stable ordering improves caching without making the cache authoritative.
Failure policy
| Boundary | Action |
|---|---|
| Stable instructions | Place first and version |
| Tenant policy | Keep tenant-scoped and versioned |
| Session summary | Compact before volatile evidence |
| Retrieval output | Append late and treat as untrusted |
| Cache unavailable | Run correctly without it |
| Prompt changes | Canary under a new version |
Trade-offs
Stable prefixes reduce latency and cost but can widen sharing scope or preserve stale policy. Prompt order may change behavior, so evaluate it like code.
Decision rule: Optimize prefix reuse only after isolation, versioning, and uncached correctness are proven.