← 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.

Filter view:

Phase 1 — Attention Dynamics & Prompt Caching 3 / 3 Mastered

Mastered §1.1

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.

Prerequisites: None (Domain Entry)
Inspect Evidence & Links
Evidence: Documented in Reference & ELI5 (Stanford/Liu 2023 evaluation).
Mastered §1.2

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.

Prerequisites: The "Lost in the Middle" U-Curve
Inspect Evidence & Links
Evidence: Implemented across Hermes/Claude configurations (`~/.hermes/` prefix isolation).
Mastered §1.3

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.

Prerequisites: Prompt Caching Prefix Stability
Inspect Evidence & Links
Evidence: Authored essay "Cheap Code, Expensive Context" (2026).

Phase 2 — Structural Prompt Engineering 3 / 3 Mastered

Mastered §1.4

The Four-Part Partitioning Framework

Test: Format a production agent prompt partitioned strictly into Role/Identity, Task/Context, Constraints/Gates, and Output Schema.

Prerequisites: Token Budgeting & Latency Economics
Inspect Evidence
Evidence: Authored atomic note "The Four-Part Structured Prompt Framework" (2026-08-23).
Mastered §1.5

Negative Constraints & Reality Filtering

Test: Isolate forbidden actions ("Never overwrite originals", "No destructive commands") into explicit gating checks rather than narrative instructions.

Prerequisites: The Four-Part Partitioning Framework
Inspect Evidence
Evidence: Standard standing rules in `CLAUDE.md` and `reality-filter` skill.
Mastered §1.6

Structured Output & Tool Schemas

Test: Enforce strict JSON Schema / XML tag envelopes to prevent downstream JSON parse failures in agent tool calling.

Prerequisites: Negative Constraints & Reality Filtering
Inspect Evidence
Evidence: Authored atomic note "Function Calling Lets LLMs Delegate to Tools via Structured Output" (2026-08-23).

Phase 3 — Memory Tiers & Compaction 2 Mastered, 1 Frontier

Mastered §1.7

Three-Tier Memory Architecture

Test: Separate state between in-memory Turn Buffer, Daily Episodic Logs, and Curated Semantic Notes with independent read/write paths.

Prerequisites: The Four-Part Partitioning Framework
Inspect Evidence & Links
Evidence: Authored atomic note "Context Overflow Needs a Memory Strategy Not Just a Bigger Window" (2026-08-23).
Mastered §1.8

Progressive Summarization (L1 → L2 → L3)

Test: Compress raw capture transcripts into 3 progressive distillation layers before injecting into context payloads.

Prerequisites: Three-Tier Memory Architecture
Inspect Evidence
Evidence: `readwise-synthesis` and `progressive-summarization-technique` skills.
Frontier §2.1

Dynamic Token Budget Enforcers

Test: Write an automated pre-call interceptor that trims vector payloads to fit a rigid 8k-token headroom budget.

Prerequisites: Progressive Summarization

Phase 4 — Codebase AST Context & Pruning Locked

Locked §2.2

AST Class & Signature Slicing

Test: Use Tree-sitter / AST extractors to pass only target function signatures and interface definitions instead of whole modules.

Prerequisites: Dynamic Token Budget Enforcers
Locked §2.3

Import Graph Dependency Subgraphs

Test: Traverse project imports to assemble a minimal 1-hop dependency context for targeted refactoring tasks.

Prerequisites: AST Class & Signature Slicing

Phase 5 — Multi-Turn Hygiene & Contamination Prevention Locked

Locked §2.4

Chat Contamination Detection

Test: Identify repetition loops, apologizing spirals, and hallucination cascading in long multi-turn sessions.

Prerequisites: Three-Tier Memory Architecture
Locked §2.5

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.

Prerequisites: Chat Contamination Detection
Locked §2.6

Automated Session Boundary Guards

Test: Deploy automated session-length watchers that trigger compaction before context degradation occurs.

Prerequisites: Re-Anchoring & Session Compaction