Context Engineering vs Prompt Engineering: What Is the Difference?

A
Author
18 Oct, 2026 3 min read 0 views

Prompt engineering is about writing the wording of an instruction so the model understands the task. Context engineering is about managing the whole set of tokens the model sees on every call: instructions, but also tools, memory, retrieved data, history and tool output. Prompt engineering is one part of context engineering, and the larger practice becomes necessary once your application runs more than one call.

Where prompt engineering stops

Classic prompt engineering assumes a single shot. You write a prompt, send it and read the answer. The questions are about phrasing: should I give an example, should I ask for step-by-step reasoning, how do I specify the output format? These questions still matter and you will use the answers throughout this course.

But a single prompt is a fixed string you can edit by hand. Agents do not work that way. The text the model sees on turn 15 of an agent run was assembled by your code at runtime from many sources, and you never saw it written down.

Where context engineering begins

Once your application builds the prompt dynamically, new questions appear:

  • Which of the 40 stored user facts belong in this request?
  • The last tool returned 30,000 characters. Do we keep all of it?
  • The conversation is 80 turns long. What do we drop or summarise?
  • Which of our 25 tools should the model see right now?
  • Which part of the prompt is stable enough to cache?
  • How do we know the new version is better than the old one?

None of these is about phrasing. They are about selection, ordering, size and lifetime of information. That is the shift in thinking.

A side-by-side comparison

AspectPrompt engineeringContext engineering
Unit of workOne promptThe context on every turn of a run
Main skillClear wordingSelecting and sizing information
Who writes itA person, by handYour code, at runtime
Typical failureAmbiguous instructionStale, missing or bloated context
Tested byReading outputsEvals over many runs

An example of the difference

Suppose an agent answers questions about a codebase. A prompt-only fix says: "Be careful to read the file before answering." A context fix changes what the agent receives: the tool returns a file outline first, with line numbers, and the agent asks for specific line ranges. The wording barely changed, but the information design did.

# Prompt-level fix: add a sentence and hope
system = "You are a code assistant. Read files carefully before answering."

# Context-level fix: change what the tool returns
def read_file_outline(path: str) -> str:
    """Return function and class names with line numbers, not the whole file."""
    import ast
    with open(path, encoding="utf-8") as f:
        tree = ast.parse(f.read())
    lines = []
    for node in ast.walk(tree):
        if isinstance(node, (ast.FunctionDef, ast.ClassDef)):
            lines.append(f"{node.lineno}: {type(node).__name__} {node.name}")
    return "\n".join(sorted(lines, key=lambda s: int(s.split(":")[0])))

The second approach keeps the context small and gives the model a map. It then reads only the lines it needs. That change helps on every future task, while the prompt sentence helps only if the model happens to follow it.

How the two fit together

Think of prompt engineering as writing good paragraphs and context engineering as designing the whole document. You still need clear paragraphs. But you also need to decide which sections exist, how long they are and when they are removed.

Practical takeaways

  • Keep using prompt techniques for each instruction; they are the foundation.
  • When a bug appears in an agent, first print the full context for the failing turn.
  • Ask "what did the model see?" before asking "why did the model do that?".
  • Treat context as a budget that every component competes for.

If you are new to writing prompts, start with the LLM APIs track on this site and come back here once you are calling models from code.

Was this article helpful?

Comments

No comments yet. Have a question or a tip? Be the first to share it.

Leave a comment

Comments are reviewed before they appear.