💬 Start with the prompt: what you ask for
The first layer is the one everyone knows: the prompt, the text you write asking the model for something. It’s also the layer where most people get stuck—when the agent does something wrong, the reflex is “let me rewrite the prompt.” Sometimes it works. Most of the time, it only puts off the problem.
Improving the prompt has diminishing returns quickly: the first improvements (be specific, give an example, ask for an output format) solve a lot. After a certain point, adding more instructions to the prompt stops changing the result. That’s a signal — not that you wrote poorly, but that the problem has moved elsewhere.
🆕 New here? Three words before you continue
- Harness: the infrastructure around the model—which tools it has, what permissions, and how its output is captured. Without a harness, the model only talks; with a harness, it acts.
- Context window: the amount of text (measured in tokens) the model can "see" at once when responding. Go over the limit, and it forgets what came before.
- Token budget: how much text (input + output) you’re willing to spend on a call or an entire task — the practical limit on cost and context.
What to look at: the dashed line rises without breaking—each step sits on top of the previous one, not in its place. The glow appears only on the last step, "graph," which is the horizon of this module. Remember the order: it’s how you’ll diagnose where a broken agent is really stuck.
✓ The prompt solves it
- ✓Wrong output format (asked for text, got malformed JSON)
- ✓Tone or level of detail outside expectations
- ✓Genuine ambiguity in the instruction ("summarize" — in how many lines?)
✗ A prompt won’t solve it
- ✗The agent doesn’t have access to the file it needs to read (that’s the harness)
- ✗It “forgot” an instruction given 40 thousand tokens ago (that’s context)
- ✗It stops trying again after the first error (that’s the loop)
Key concepts
The most visible, the most tempting
Improves quickly, then stalls
A bad prompt is sometimes a symptom of another layer
Stopped improving? Move up a layer
🧠 Control the context: what it knows
The second layer is the context: everything the agent “sees” when it acts—open files, conversation history, attached documentation, the output of a tool it just ran. The prompt is what you ask for; context is what it knows as it responds. They’re different things, and confusing them is the most common mistake after prompting.
Every model has a context window limited. When it fills up with irrelevant things — verbose logs, files nobody needs, repeated history — the model starts to "forget" what matters, even if the original instruction was perfect. The wrong context undermines a good prompt; no prompt is good enough to make up for a cluttered context window.
📊 What tends to clog the context window
- Raw tool output — a 500-line log when only 3 lines mattered
- Accumulated history — 40 back-and-forths in a conversation that should have been reset
- Entire documentation — paste in the entire manual instead of the relevant section
- Outdated instruction — an old rule nobody removed that still competes for attention
✓ Context handled well
- ✓Only the part of the file that will be edited, not the entire repository
- ✓Tool output summarized before returning to the model
- ✓History pruned when the task changes phase
✗ Context that undermines you
- ✗Include everything "just to be safe" — the model doesn't weigh importance the same way you do
- ✗Let an error from a previous attempt contaminate the next one without marking it as resolved
- ✗Never prune—the window only grows until it overflows
💡 Practical tip
Before rewriting a prompt that "isn’t working," look inside the context window at that moment. If there’s something there you couldn’t use to answer well yourself, the model won’t be able to either. Clearing context often fixes what rewriting the prompt didn’t.
Key concepts
What the agent knows, not what you ask
Always has a token cap
Irrelevant information competes with what matters
Context needs ongoing curation
🧰 Build the harness: what it acts with
The third layer is the harness: the infrastructure around the model. Which tools it has (read a file, run a command, call an API), what permissions it has, how each tool’s output is captured and returned to the model, what happens when a tool fails (retry—automatically try again), and how much token budget the entire task has to spend.
Prompt says what; the harness says with what. An agent with a perfect prompt and a poor harness (no access to the right file, no permission to run the command that would solve the problem) gets stuck all the same—and no prompt rewrite will unblock it, because the problem was never in the text.
Tools and permissions
What the agent can call, and what it can do with each call.
Reading is different from writing; writing to a file is different from running a command on the system. Each level is a risk decision.
Output capture and retry
What returns to the model after a tool call, and what happens if it fails.
Retry: automatically retry after a failure, usually with a limit on the number of attempts.
Token budget
The spending limit (input + output) for the call or the entire task.
Without a defined budget, an agent with a loop can consume credits indefinitely before anyone notices.
⚠️ Signal that the problem is the harness, not the prompt
If you ask for the same thing in two different ways and the agent fails in the same way both times—checking the wrong file, lacking permission to run the test, lacking a tool to validate its own work—the prompt isn’t the bottleneck. It’s the surrounding infrastructure that needs to change.
Key concepts
What it acts on, not what it knows
What is available to call
What it can do, not just what exists
The task's spending limit
🔁 Design the loop: how many times it runs and how it stops
The fourth layer is the loop: how many times the agent tries and how it knows it’s done. That’s all of Track 2 condensed—discover, plan, act, verify, stop. This is the layer where you stop writing prompts and start design a cycle: it’s no longer about what to ask in a single call, but how the system behaves over several calls.
An agent can have a great prompt, clean context, and a well-built harness and still fail — because no one designed the stop condition, or because the verifier (the part that decides whether the result is good) is missing or weak. At that point, more prompting won’t help: what’s missing is loop design.
🎯 The question that changes when you move up to this layer
It's no longer “what should I ask?”—it's “how many iterations does this take, and what tells me it’s done?"
If the answer is “I don't know, it stops when it gets tired” or “I don't know, it runs until it blows the budget,” the loop isn't designed — it's happening by accident.
Key concepts
How many times and how you know it’s done
Without it, it runs forever
What determines whether it passed
System, not a single call
🕸️ Connect the loops in a graph: how many and how they connect
The fifth layer only makes sense after the other four: how many loops you have, and how they connect. A graph here is literally several loops (or nodes with no loops) connected by edges—the researcher sends work to the writer, the writer sends it to the reviewer, and the reviewer can send it back to the writer. Each of these is a node; the whole network is the graph.
Move up to this layer without mastering the four below it multiplies the problem instead of solving it. If an individual loop already has no clear stopping condition, putting three of those loops in a graph doesn't create three problems—it creates a combinatorial problem, because now each poorly designed loop can contaminate its neighbors.
💡 Practical tip
Before drawing a graph, ask: does each individual node, in isolation, already work as a loop — with its own stop condition and verifier? If the answer is no for any of them, fix that first. A graph won’t fix a broken loop; it will only spread the breakage.
Key concepts
How many loops and how they connect
Each node can be an entire loop
Only those who master layer 4 move up
A graph on top of a broken loop makes things worse
⚖️ Compare the Two Harnesses: Script × Distributed Runtime
The harness for ONE loop fits in a script: prompt input, context window, token budget, retry logic, output capture. You can write that in an afternoon. The harness for a GRAPH does all this is more: message routing between nodes, fault isolation for a node (one node going down must not take down the entire graph), state consistency between nodes (what one node knows must match what the next expects), dynamic node creation (the graph decides at runtime that it needs one more node), and observability of the entire graph.
Observability, here, means the ability to answer: which nodes ran, in what order, and with what latency (runtime). In a single-loop script, that question is trivial — it ran once, ran again, stopped. In a graph with parallel nodes and conditional routing, without instrumentation you simply don’t know what happened. That’s exactly why orchestration frameworks (tools that coordinate multiple agents/nodes) gain traction when the conversation shifts from loops to graphs: they solve this set of distributed runtime — a system where several parts run in a coordinated way, each able to fail independently of the others—instead of leaving each team to reinvent this by hand.
What to look at: compare the size of the two boxes. The box on the left has 4 responsibilities and fits into an afternoon’s work. The box on the right has 5 responsibilities — and each one of them, on its own, is an engineering project (fault isolation, for example, is the entire subject of classic distributed systems). That explains why “just adding one more agent” is never “just” that.
| Responsibility | Loop harness | Graph harness |
|---|---|---|
| Prompt input | 1 entry point | 1 per node, routed |
| Failure | Stop the entire loop | Isolated; it doesn't bring down the graph |
| State | A local variable | Needs a schema between us |
| Observability | A linear log | Trace of nodes, order, latency |
🧪 Practical example: diagnose which layer has the problem
Objective: stop rewriting prompts in the dark. A prompt ready to run in Claude Code (or any agentic assistant) that forces you to work through all five layers before accepting "improve the prompt" as the answer.
Meu agente faz <o que ele faz de errado> quando eu peco <a tarefa>. Antes de sugerir qualquer mudanca, analise as cinco camadas NESTA ORDEM e descarte cada uma explicitamente antes de passar pra proxima: 1. PROMPT — a instrucao em si tem ambiguidade real, ou ja e clara? 2. CONTEXTO — o que o agente "ve" no momento de agir esta limpo, ou tem coisa irrelevante competindo com o que importa? 3. HARNESS — ele tem a ferramenta certa, com a permissao certa, e a saida dela volta pra ele de um jeito util? 4. LOOP — existe condicao de parada e verificador? Ele sabe quando "terminou" de verdade, ou so para de tentar? 5. GRAFO — se ha mais de um agente/etapa, o problema esta na ligacao entre eles (roteamento, estado que vaza) e nao dentro de um unico no? Para cada camada, diga "descartada" ou "e aqui" com uma frase de justificativa. So recomende uma mudanca depois de passar pelas cinco.
How to verify: if the answer is just "improve the prompt like this..." without mentioning the other four layers, the model skipped the diagnosis — ask again, insisting that it rule out each layer in order before recommending anything.
Now swap it for yours: replace
<o que ele faz de errado> e <a tarefa>
based on the actual case you have in hand.
Quick check (doesn’t block anything): your agent with just ONE loop already works well on its own, but you want to add a second agent to review its result. What does this change require that a simple loop harness didn’t?
Key concepts
Difference in scale, not degree
Routing, isolation, state, spawning, observability
Who ran, in what order, and with what latency
That’s why frameworks gain traction here
📌 Module Summary
Next Module:
3.2 — The real comparison: agentic, loop, and graph side by side, on the same case — the daily brief.