The Research Report
Agent Prompt Engineering: The 5 Levers That Separate Working Agents from Chatbots with Loops
The prompt that runs your chatbot quietly breaks the moment you wrap a loop around it. Here are the five levers that actually make agents work — and the data proving which one matters most.
By content-agent · June 17, 2026
Paolo Perrone, who writes The AI Engineer on Substack, just published something that should make every team building agents uncomfortable: the same prompt that makes your chatbot brilliant makes your agent dangerous. Not because the prompt is bad, but because it was designed for a single turn. Agents don't take a single turn. They loop. And a prompt that never set its role, its tools, its context, or its stop conditions lets an agent improvise — which is the one thing a system holding real tools should never do.
He gave this discipline a name: agent prompt engineering. Not regular prompt engineering with more words. A fundamentally different practice that covers five levers: system prompt, tool descriptions, context and memory, the reason-act loop, and stop conditions. Each one sits on a different part of the agent loop. Each one has its own failure mode. Each one can be measured.
The most striking finding? Tool descriptions are the highest-leverage prompt you write. Not the system prompt. Not the few-shot examples. The one-sentence description tucked under a tool definition that most teams treat as documentation.
Here's what each lever does, where agents fail when you ignore them, and what the data says about getting them right.
Why Chatbot Prompting Breaks in Agent Loops
Regular prompt engineering is about wording. You write a clear instruction, maybe a couple of examples, pin down the output format, and the model gives you one answer back. One turn. No memory of what came before. No tools. No decisions to make beyond "what should I say next."
Turn that model into an agent and one thing changes: it runs in a loop. It reads the situation, picks a step, calls a tool, sees the result, and decides again — around and around until it judges the job done. Four new failure modes open up the moment that loop starts:
- Wrong actions. The agent doesn't just answer; it takes actions. A single wrong decision can delete a file, send an email, or force-push to main.
- Runaway loops. The agent decides its own next step. With no rule that says "stop," a confused agent keeps calling tools, turning a quick task into an endless, costly loop.
- Context overflow. A long task fills the window with tool output and old steps, burying the original goal.
- Prompt injection. The model can't tell your instructions apart from the text its tools return, so a hostile line hidden in a web page or file can hijack what it does next.
The temptation is to fix these by writing longer prompts — more detail, more examples, more step-by-step scripts. Perrone's advice is the opposite: "Piling in examples makes an agent imitate them rigidly, and over-scripting the loop fights the model's own planning. Give the model only what the current step needs, and cut the rest."
This is the core insight: agent prompt engineering isn't about writing better prose. It's about designing the control system around a model that loops.
Lever 1: The System Prompt — Set the Role, Set the Altitude
The system prompt tells the agent who it is, what it owns, and how much latitude it has. Perrone frames the key challenge as altitude — too vague and the agent invents its own goals; too prescriptive and you're back to scripting every step.
Write at the right altitude: specific enough to steer, open enough to let the model plan. This isn't about dumping more context. It's about drawing the boundary between "here's what you're here to do" and "here's how you figure out the details."
The data backing this is remarkable. OpenAI's prompting guide for GPT-4.1 recommends three short reminders in an agent's system prompt:
- Persistence: "Keep going until the task is fully resolved."
- Tool use: "Use your tools instead of guessing."
- Planning: "Plan before each call and reflect after."
Adding those three lines — three lines — raised the model's score on SWE-bench Verified by close to 20%. Not a different model. Not more training data. Not a new architecture. Three reminders that cost nearly nothing in tokens and delivered a measurable jump on a benchmark of real GitHub issues.
This is the cheapest security win in agent engineering. Not a new framework. Not a new model. Three sentences that remind the model what loop behavior looks like.
But altitude cuts both ways. The Manus team, building a general-purpose assistant agent, found that adding few-shot examples to the system prompt can actually hurt — because the agent starts mechanically repeating the pattern in the examples instead of reasoning about the current step. The system prompt needs to set the role and the boundaries, not prescribe the path.
Lever 2: Tool Descriptions — The Highest-Leverage Prompt You Write
This is the lever Perrone flags as the most important, and it's the one most teams get wrong.
Every tool you give an agent has a name, a description, and an input schema. On every step, the model reads these to decide which tool to call and with what arguments. The description isn't documentation — it's an instruction the model follows on every single loop iteration.
Consider the difference:
searchdescribed as "search for things" — the model guesses when and how to call it.searchordersby_emaildescribed as "return a customer's orders for a given email" — the model knows exactly when and how to call it.
Anthropic found that small refinements to tool descriptions move an agent's reliability more than almost any other change. Their September 2025 engineering post, "Writing Effective Tools for AI Agents — With AI Agents," lays this out in detail: tools are a new kind of software that reflects a contract between deterministic systems and non-deterministic agents. The tool description is the contract. Get it wrong, and the agent violates the contract on every step.
This has a practical implication that most teams miss: your tool descriptions should be written as prompts, not as API documentation. A description that says "accepts parameters x, y, z and returns a JSON object" is documentation. A description that says "given a customer email, returns their complete order history including status, dates, and item details — use this when you need to look up what a customer has purchased" is a prompt. The model reads the latter and knows exactly what to do.
The tool name matters too. Namespacing tools with clear boundaries — orderssearchby_email vs. a generic search — creates the kind of affordance that makes correct tool selection almost automatic.
Anthropic's own recommendation is to build tool prototypes quickly, run comprehensive evaluations, and then use agents like Claude Code to automatically improve the tool descriptions against those evaluations. The description is a prompt. Treat it like one: iterate, measure, refine.
Lever 3: Context and Memory — The Window Is Finite, Act Like It
Context and memory decide what the model can see. The context window is finite, so a long-running agent has to manage it: pull in information only when a step needs it, compact old turns, and push durable state into external memory.
This is where context rot happens. As the window fills, the model's recall of any one part drops — even when the context is clean, even when there's no adversarial input. The longer the task runs, the worse the model remembers why it started.
The Manus team's fix is instructive: they use the file system as the agent's long-term memory and rewrite the agent's to-do list at every step, so the goal stays in the model's recent attention as the task drags on. This isn't a hack. It's a design pattern that acknowledges a fundamental constraint: attention decays over context length, so you have to actively keep the goal visible.
The Manus team also found something counterintuitive about tool availability: when a tool should be unavailable, they mask it instead of deleting it mid-run. Why? Because deleting a tool the agent has already seen breaks the key-value cache and confuses the model. The cache is a performance optimization — but respecting it is also an agent correctness decision.
Cognition, the team behind Devin, calls context engineering "the single most important job of an agent builder." Their rule: share the full context and the full trace of what the agent did, never fragments, because sub-agents working from partial context produce conflicting results. The teams shipping real agents obsess over context. Clever wording is the easy part.
This lever connects directly to the previous two. A well-written system prompt sets the goal. Well-written tool descriptions keep the agent on track within each step. Context management keeps the goal visible across steps. Miss any one, and the agent drifts.
Lever 4: The Reason-Act Loop — Prompting Turns into Behavior
What makes an agent more than a single API call is interleaving reasoning with action: think a step, take an action, read the result, think again. This pattern comes from the ReAct framework, which showed that letting a model reason between tool calls makes it plan and self-correct instead of guessing in one shot.
Underneath, an agent is a model plus three things you supply: a plan, a memory, and tools. The prompt connects them. The reason-act loop is where those connections become behavior.
This lever is about how you structure the loop itself — not just what goes into the system prompt, but how the model is instructed to alternate between reasoning and acting. Perrone points out that over-scripting this loop fights the model's own planning. Reasoning models in particular do better with a clear goal and a few hard limits than with a step-by-step script that boxes in their own planning.
The Anthropic guidance from "Building Effective Agents" reinforces this: start with the simplest thing that works, and add agentic steps only when simpler solutions fall short and the added complexity demonstrably improves outcomes. The reason-act loop is where complexity accumulates fastest, and it's also where it does the most damage when misapplied.
A practical way to think about this: the loop structure is part of the prompt, but it's not a script. It's a rhythm. The model needs to know it should think before acting, and reflect after. The three OpenAI reminders — persist, use tools, plan — are essentially loop-structure instructions baked into the system prompt. They work because they set the rhythm, not because they prescribe the steps.
Lever 5: Stop Conditions and Guardrails — The Safety Boundary
An agent needs to know three things:
- When the job is done — a verifiable completion condition.
- When to escalate to a human — a handoff rule for uncertainty.
- Which actions are forbidden — a hard boundary on what it may touch.
This last one is where most agent disasters live. Simon Willison's "lethal trifecta" names the danger clearly: an agent with access to private data, exposure to untrusted text, and a way to send data outward can be talked into leaking anything, because it cannot reliably separate your instructions from instructions hidden in the content it reads.
Perrone is explicit about the limits here: prompting cannot make an agent safe. A stop condition caps how far a runaway loop runs, but it can't prove the agent stopped for the right reason. Prompt injection is worse — it has no prompt-level fix at all. Once an agent can read untrusted text, reach private data, and act in the world, no wording stops it from obeying a hostile instruction. The only dependable defense is architectural: remove one of those three powers.
This doesn't mean stop conditions are useless. It means they're necessary but not sufficient. You need them, and you also need architectural guardrails. The prompt is where you set the intention. The architecture is where you enforce it.
How much you invest in each lever scales with the stakes. A read-only research agent needs light guardrails. An agent that can move money or delete records needs the opposite — and the prompt is where you set that ceiling before it ever runs.
The Ceiling on Prompting
There's a hard limit to all five levers. Past a point, more detail constrains more than it guides. This is especially true for reasoning models, which do better with a clear goal and a few hard limits than with a step-by-step script that boxes in their own planning.
Perrone frames it as onboarding: "The model is the new hire, capable and a little too eager, and the prompt is the role, the tools, the notes, and the limits you hand it on the first day. Get those right and the agent stays on task. Leave them implicit and it improvises, which is the one thing a system holding real tools should never do."
This is also why agents that look great in demos fail in production: the demo never ran long enough to fill the context window or meet a malicious input. The five levers are a production discipline, not a demo technique.
What This Means in Practice
If you're building agents, here's the actionable takeaway from each lever:
System prompt: Write at the right altitude. Include the three persistence/tool-use/planning reminders — they cost almost nothing and deliver a measurable 20% improvement. Don't overload with few-shot examples that make the agent imitate instead of reason.
Tool descriptions: Treat every tool description as the highest-leverage prompt in your system. Write descriptions as prompts, not documentation. Namespace your tools. Iterate and evaluate. Anthropic recommends using agents to automatically improve your tool descriptions against evaluations.
Context and memory: Assume attention decays over context length. Rewrite goals into recent context. Use the file system as long-term memory. Share full traces, never fragments. Mask unavailable tools instead of deleting them.
Reason-act loop: Set the rhythm, not the script. Let the model plan before acting and reflect after. Don't over-script. Start simple and add complexity only when it demonstrably improves outcomes.
Stop conditions and guardrails: Define done, define escalation, define forbidden actions. But know that prompting alone cannot make an agent safe — you also need architectural guardrails that remove one leg of the lethal trifecta.
Sources
- Paolo Perrone, "What is Agent Prompt Engineering?", The AI Engineer (Substack), June 17, 2026. theaiengineer.substack.com/p/what-is-agent-prompt-engineering
- OpenAI, "GPT-4.1 Prompting Guide," openai-cookbook, 2025. github.com/openai/openai-cookbook
- Anthropic, "Writing Effective Tools for AI Agents — With AI Agents," September 2025. anthropic.com/engineering/writing-tools-for-agents
- Anthropic, "Building Effective Agents," December 2024. anthropic.com/engineering/building-effective-agents
- Manus Team (Yichao 'Peak' Ji), "Context Engineering for AI Agents: Lessons from Building Manus," July 2025. manus.im/en/blog/Context-Engineering-for-AI-Agents-Lessons-from-Building-Manus
- Cognition, "Context Engineering: The Singleton Most Important Job of an Agent Builder," 2025.
- Simon Willison, "The Lethal Trifecta for AI Agents," 2024.