AI Engineering Reference/Prompting & Context Engineering

Context Engineering & Specs

Context budgets, file selection, spec-driven development with AI, and why rules/skills outlast prompt hacks.

4/5Overview: 35m

From prompt engineering to context engineering

Prompt engineering optimizes the words. Context engineering optimizes the information the model sees. In mid-2026, the bottleneck isn't prompt phrasing — it's what you include, what you exclude, and how you structure it.

Context = system prompt + rules + skills + open files + conversation + tool results + retrieved docs

Every byte competes for the same context window. Senior engineers curate, not dump.

The context budget

Before any agent session, plan your budget:

SlotTypical allocationContent
Rules & conventions5–10%.cursor/rules, coding standards, team patterns
Task spec5–10%What to build, acceptance criteria, constraints
Relevant source40–60%Files directly in scope — not the whole repo
Reference docs10–20%API docs, ADRs, retrieved RAG chunks
Conversation history10–20%Prior turns; summarize when long
Output headroom15–25%Room for model response

If your context is 80% unrelated files, quality on the actual task drops — even with a 1M token window.

Spec-driven development with AI

Replace vague requests with specs the agent can execute:

## Goal Add idempotency keys to POST /orders endpoint. ## Acceptance criteria - [ ] Idempotency-Key header accepted (UUID v4) - [ ] Duplicate requests return cached 201 with same order ID - [ ] Keys expire after 24h (Redis TTL) - [ ] Unit tests for: new key, duplicate key, expired key ## Files in scope - src/handlers/orders.ts (modify) - src/middleware/idempotency.ts (create) - src/handlers/orders.test.ts (modify) ## Out of scope - Database schema changes - Other endpoints ## Patterns to follow - See src/middleware/rateLimit.ts for middleware structure

Specs reduce back-and-forth, make agent output reviewable, and survive model upgrades better than clever one-liners.

File selection strategies

StrategyWhen to use
Manual @-mentionsSmall, well-scoped tasks; you know exactly what's needed
Semantic search (RAG)Large codebase; you know the concept but not the file
Dependency graphRefactors — include callers and callees
Recent git changesBug fixes — include files from the breaking commit
Test filesImplementation tasks — tests define the contract

Don't @-mention your entire monorepo. The model's attention degrades with irrelevant context (lost-in-the-middle effect).

Rules, skills, and persistent context

Rules (Cursor .cursor/rules/, AGENTS.md): always-on conventions. Version-controlled, team-shared, model-agnostic.

Skills (SKILL.md): procedural knowledge loaded on demand. "How to deploy," "How to run migrations."

Project context (llm-context.md, context.md): architecture overview, key abstractions, gotchas.

These replace re-pasting the same instructions every session. Covered in depth in Team Practices.

Summarization vs verbatim

Include verbatimSummarize
Files being modifiedDirectory trees
Interface/type definitionsImplementation internals not in scope
Failing test outputEntire test suite
Error logs (last 50 lines)Full log history
API docs for libraries in useGeneral language tutorials

When summarizing, preserve identifiers (function names, types, error codes) — the model needs these to generate correct code.

Structured outputs for pipelines

When AI output feeds another system (CI, codegen, agent loops), use schema enforcement:

  • OpenAI Structured Outputs (JSON schema)
  • Anthropic tool use with typed parameters
  • Cursor's structured agent responses

Free-form markdown is for humans. JSON is for machines.

Interview framing

"I treat context as a scarce resource. I write specs with acceptance criteria, select files deliberately, use rules for persistent conventions, and reserve the context window for material directly relevant to the task. Prompt wording matters less than context curation."

Senior signal: Draw a context budget diagram for a real feature. Explain why you included file A but summarized file B. Mention that rules in git outlast prompt hacks in chat history.

Further Reading

Hands-On Tasks (Optional)

Practical exercises — prompt drills, local MCP servers, or workflow design on paper. The goal is professional fluency, not model training.

  • Design a context budget for one feature

    For a feature you'd build with an agent: list required files, estimate tokens, define what gets summarized vs included verbatim, and write a 10-line spec the agent can follow without guessing.

    30m