Agent AI · Field Notes

Prompt, Context & Loop Engineering

Three disciplines that get confused for one. Each shapes a different unit of an LLM system — and each fails in its own way. Getting an agent to work reliably means getting all three right, not perfecting the prompt alone.

Comparison table of prompt, context, and loop engineering across four dimensions: unit, time scale, typical lever, and failure mode.
Key differences at a glance — unit · time scale · lever · failure mode
In one paragraph

Prompt engineering shapes the instruction text inside a single model call. Context engineering manages the information window the model sees, rebuilt on every turn. Loop engineering governs the sequence of turns across a full agentic run. They are nested, not competing: a prompt lives inside a turn, and turns compose the run — so a system is only as reliable as its weakest layer.

Key Differences

Same goal, three different jobs

Read each column top to bottom to see how the same four questions get different answers at each layer.

PromptENGINEERING
ContextENGINEERING
LoopENGINEERING
Unitwhat you shape
Instruction text
The information window
A sequence of turns
Time Scalewhen it applies
A single call
Refreshed each turn
The full run
Typical Leverwhat you tune
Examples · phrasing · format
Retrieval · compaction · format
Retries · caps · termination
Failure Modehow it breaks
Vague or malformed output
Missing or stale data
Stalls, loops, or runaway cost

Each layer wraps the one before it — a prompt lives inside a turn, and turns compose the run.

The mental model

How the three layers nest

The fastest way to keep them straight: think in widening scopes. Fix a call, and you have prompt engineering. Fix everything the call gets to see, and you have context engineering. Fix the whole loop those calls run inside, and you have loop engineering.

◆ THE RUN — loop engineering

The entire agentic run: many turns chained together until a goal is met or a limit is hit. This is where retries, step caps, budgets, and termination live.

▚ A TURN — context engineering

One turn of the loop. Before the model is called, its context window is assembled — retrieved facts, prior turns, tool results — then compacted to fit.

▸ A CALL — prompt engineering

The single model call at the heart of the turn: the instruction, examples, and output format that decide what comes back.

{ }

Prompt Engineering

the single call

Prompt engineering is the craft of the one message that goes into the model. You control the wording, the examples, the role and constraints, and the shape of the output you ask for. Its scope begins and ends inside a single call — nothing about retries or retrieved data belongs here. When it works, the model returns something well-formed and on-target on the first try.

What you tune
few-shot examples phrasing & tone output format / schema role & system framing explicit constraints task decomposition
How it breaks
Vague or off-target answers when the ask is underspecified.
Malformed output that won't parse — wrong JSON, missing fields.
The model ignores a rule buried in a wall of instructions.
[ ]

Context Engineering

each turn's window

Context engineering decides what the model is actually looking at when it's called. The context window is finite and rebuilt every turn, so the job is curation under a budget: pull in the right facts, drop the irrelevant, summarize what's grown too long, and order it so the important material isn't lost. A flawless prompt still fails if the window is missing the one document that mattered — or filled with a stale copy of it.

What you tune
retrieval (RAG) compaction / summarizing ordering & formatting memory & state tool-result trimming token budget
How it breaks
Missing data — the needed fact was never retrieved into the window.
Stale data — an old value lingers while the source has moved on.
Context rot — the signal drowns as the window fills with noise.

Loop Engineering

the full run

Loop engineering governs the run as a whole — the outer loop that calls the model, acts on the result, feeds it back, and repeats. This layer owns the questions no single turn can answer: how many steps are allowed, when to retry a failure, when the job is actually done, and what happens when it isn't. It's the difference between an agent that finishes and one that spins forever or quietly spends your budget.

What you tune
retry policy & backoff max-step caps termination conditions token / cost budgets circuit breakers loop / oscillation detection
How it breaks
Stalls — the agent waits on a condition that never arrives.
Loops — the same two steps repeat with no progress.
Runaway cost — no stopping rule, so tokens and dollars pile up.
Common questions

Frequently asked

What's the difference between prompt engineering and context engineering?

Prompt engineering shapes the instruction text inside a single call — wording, examples, output format. Context engineering decides which information occupies the model's window on each turn: retrieved documents, prior turns, tool results, and how they're compacted and ordered. Prompt engineering asks "how do I phrase this?"; context engineering asks "what should the model be looking at right now?"

Where does loop engineering fit in an AI agent?

One level above a single turn. An agent runs many turns in a loop — call the model, run a tool, feed the result back, repeat. Loop engineering sets the rules for that whole run: how many steps are allowed, when to retry, when to stop, and what budget caps apply. It's what keeps an agent from stalling, cycling, or burning unlimited tokens.

Why isn't a good prompt enough for a reliable agent?

A perfect prompt only controls one call. In a multi-turn agent, the model may see stale or missing context (a context problem) or never terminate and rack up cost (a loop problem). Reliability comes from getting all three layers right — not from perfecting the prompt alone.

What causes runaway cost in an agent, and how do you prevent it?

Usually a missing or weak stopping condition: the agent loops, retries endlessly, or re-reads a growing context every turn. Prevent it with loop-engineering controls — a maximum step count, a token or dollar budget cap, explicit termination conditions, and a circuit breaker that halts on repeated errors or detected oscillation.

Do these three replace each other?

No — they're nested, not competing. A prompt lives inside a turn, and turns compose the run. Each layer wraps the one before it, and each has its own unit, its own levers, and its own way of failing. Strong systems tune all three together.

Remember this

Three layers, one system

01 · PROMPT

Shape the call. Wording, examples, and format decide the quality of a single response. Start here — but don't stop here.

02 · CONTEXT

Curate the window. The best prompt fails on missing or stale inputs. Retrieval and compaction decide what the model gets to reason over.

03 · LOOP

Govern the run. Caps, retries, and termination turn a clever model into an agent that actually finishes — on budget.