← Knowledge Trees · Nestor G Pestelos Jr
Context Engineering Knowledge Tree
Prerequisite curriculum: attention dynamics, token budgeting, prompt caching, memory tiers, and multi-turn hygiene.
Target Capability
Design deterministic, cost-optimized token pipelines for LLM agents: enforce strict 4-part prompt structures, preserve prompt-cache prefixes, eliminate attention decay across the "Lost in the Middle" curve, maintain 3-tier memory hierarchies, and prevent multi-turn chat contamination.
Phase 1 — Attention Dynamics & Prompt Caching 3 / 3 Mastered
The "Lost in the Middle" U-Curve
Test: Explain the empirical recall curve across token positions (Primacy 98%, Middle 50%, Recency 99%) and design payload positioning accordingly.
Inspect Evidence & Links
Prompt Caching Prefix Stability
Test: Construct a multi-agent system prompt where all static invariants precede dynamic timestamps to guarantee 90% KV cache hit rates.
Inspect Evidence & Links
Token Budgeting & Latency Economics
Test: Calculate TTFT and TPOT cost-per-turn deltas between a 2,000-token and 50,000-token payload across Claude Sonnet and Haiku.
Inspect Evidence & Links
Phase 2 — Structural Prompt Engineering 3 / 3 Mastered
The Four-Part Partitioning Framework
Test: Format a production agent prompt partitioned strictly into Role/Identity, Task/Context, Constraints/Gates, and Output Schema.
Inspect Evidence
Negative Constraints & Reality Filtering
Test: Isolate forbidden actions ("Never overwrite originals", "No destructive commands") into explicit gating checks rather than narrative instructions.
Inspect Evidence
Structured Output & Tool Schemas
Test: Enforce strict JSON Schema / XML tag envelopes to prevent downstream JSON parse failures in agent tool calling.
Inspect Evidence
Phase 3 — Memory Tiers & Compaction 2 Mastered, 1 Frontier
Three-Tier Memory Architecture
Test: Separate state between in-memory Turn Buffer, Daily Episodic Logs, and Curated Semantic Notes with independent read/write paths.
Inspect Evidence & Links
Progressive Summarization (L1 → L2 → L3)
Test: Compress raw capture transcripts into 3 progressive distillation layers before injecting into context payloads.
Inspect Evidence
Dynamic Token Budget Enforcers
Test: Write an automated pre-call interceptor that trims vector payloads to fit a rigid 8k-token headroom budget.
Phase 4 — Codebase AST Context & Pruning Locked
AST Class & Signature Slicing
Test: Use Tree-sitter / AST extractors to pass only target function signatures and interface definitions instead of whole modules.
Import Graph Dependency Subgraphs
Test: Traverse project imports to assemble a minimal 1-hop dependency context for targeted refactoring tasks.
Phase 5 — Multi-Turn Hygiene & Contamination Prevention Locked
Chat Contamination Detection
Test: Identify repetition loops, apologizing spirals, and hallucination cascading in long multi-turn sessions.
Re-Anchoring & Session Compaction
Test: Flush turn state to an episodic artifact, wipe working memory, and re-anchor a clean session with zero residual error context.
Automated Session Boundary Guards
Test: Deploy automated session-length watchers that trigger compaction before context degradation occurs.