Skip to content

middleware

1 post with the tag “middleware”

The Prompt Is the Smallest Part: Context Engineering as a Middleware Stack

Context engineering as an ordered middleware stack: seven layers (token budget, PII redaction, output sanitizer, compaction, skills, persona, domain policy) narrowing onto a single model call at the core.

Open the harness and the system prompt is 40 lines you could read over coffee. Print what the model actually receives on the same turn and it’s 4,000 tokens: a persona block, a skills catalog, a summarized history, tool schemas, spotlighted retrieval. None of it is in the prompt file. That gap is context engineering, and if you let it be ad-hoc string concatenation it rots. Here’s how we made it an ordered middleware stack instead, and why the order is load-bearing.