Prompt Prefix Layout

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

BoundaryAction
Stable instructionsPlace first and version
Tenant policyKeep tenant-scoped and versioned
Session summaryCompact before volatile evidence
Retrieval outputAppend late and treat as untrusted
Cache unavailableRun correctly without it
Prompt changesCanary 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.

Further reference

Browse all engineering snippets

>