Skip to main content

Lesson 5: Prompt vs. Context Engineering

Topics Covered
  • The Core Difference: Design-time instruction vs. Runtime assembly.
  • Prompt Engineering: Techniques for steering model behavior (CoT, Role-playing).
  • The Context Window: Managing the model's finite "attention span."
  • Context Engineering: Programmatically assembling Memory, RAG, and Tools.

If Prompt Engineering is the art of asking a good question, Context Engineering is the engineering discipline of giving the model the right notes before it answers.

1. The Core Constraint: The Context Window

To understand why we need Context Engineering, you must understand the Context Window.

  • The model has a finite limit on how much text it can process at once (e.g., 8k, 32k, or 128k tokens).
  • You cannot feed it your entire database, user history, and codebase.
  • Context Engineering is the strategy of dynamically selecting the most relevant information to fit into that window at runtime.

2. Prompt Engineering (Design Time)

This is the process of crafting the static instructions that guide the model's reasoning style. It happens before the application runs.

Key Techniques

  • Role Assignment: "You are a Senior SQL Engineer." This primes the model to use professional terminology and best practices.
  • Few-Shot Examples: Providing 2-3 examples of Input -> Desired Output pairs to enforce specific formatting (e.g., JSON structures).
  • Chain of Thought (CoT): explicitly instructing the model to "Think step-by-step." This forces the model to generate intermediate reasoning tokens, significantly reducing logic errors.

3. Context Engineering (Runtime)

This is the programmatic assembly of the prompt during the user interaction. A production prompt is rarely just the user's question; it is a layered artifact.

The Anatomy of a System Prompt

When a user asks "What is my flight status?", the system assembles a massive context block invisible to the user:

  1. System Instructions (Static): "You are a travel assistant. Be concise."
  2. Memory (Dynamic): "User is in London. Previous trip was to Paris."
  3. RAG / Knowledge (Dynamic): [Retrieved from Vector DB] "Flight BA123 is delayed by 45 mins."
  4. State (Dynamic): "Current Step: Trip Confirmation."
  5. Tools (Dynamic): Definitions of functions the model can call (e.g., check_flight_api).
  6. User Query: "What is my flight status?"

Key Components

  • Memory Management: Deciding what conversation history to keep. Do we summarize the last 20 turns? Or just keep the last 5?
  • Contextual Slicing: Instead of retrieving an entire "HR Policy PDF," we retrieve only the paragraph about "Maternity Leave" to save token space and reduce noise.
  • Tool Definitions: To an LLM, a "tool" is just a text description in the context. If you don't describe the tool clearly in the context, the model won't know how or when to use it.

4. The Synthesis

DisciplineFocusAnalogy
Prompt EngineeringThe Question. Optimizing the phrasing to get the best answer.Writing a clear exam question.
Context EngineeringThe Reference Material. Programmatically retrieving the right data to answer that question.Letting the student bring an "open book" cheat sheet into the exam.

In production systems, 80% of the prompt is Context Engineering (data you fetched), and only 20% is the Prompt Engineering (the instructions and the user's query).