A Practical Guide for Agentic Programmers

Lien vers la section A Practical Guide for Agentic Programmers

You already know how to write a prompt. You know about system messages, few-shot examples, and telling the model to "think step by step." That's prompt engineering 101. This guide is about what comes after — the patterns that separate prompts that work in demos from prompts that work in production.

The Fundamental Shift: Prompts Are Software

Lien vers la section The Fundamental Shift: Prompts Are Software

The first thing to internalize is that a prompt in a production system is not a message you send to a chatbot. It's a software artifact. It has inputs, outputs, dependencies, and failure modes. It should be versioned, tested, reviewed, and deployed with the same rigor as application code.

WHOOP tracks over 2,500 prompt iterations across 41 production agents. Cursor open-sourced an entire library (Priompt) for compiling prompts as JSX components with priority scores. These teams treat prompts as engineering artifacts because they've learned the hard way that a casual prompt change can silently degrade a production system.

If your prompts live in a string variable inside your application code, with no version history, no eval suite, and no deployment process — you don't have a prompt engineering practice. You have a liability.

Structural Patterns That Scale

Lien vers la section Structural Patterns That Scale

Separate Concerns in the Prompt

Lien vers la section Separate Concerns in the Prompt

A well-structured prompt has distinct sections, each with a clear purpose:

  • Role and constraints: Who the model is, what it can and cannot do, what tone to use.
  • Context: The data the model needs to answer — retrieved documents, user profile, conversation history.
  • Task specification: What exactly to do with the context. Be precise about format, length, and structure.
  • Output format: If you need JSON, define the schema. If you need a specific structure, show it.

Mixing these concerns creates fragile prompts. When role instructions bleed into context, or task specifications are scattered across the prompt, small changes have unpredictable cascading effects. Keep sections distinct, even if it means being more verbose.

Use Structured Output Formats

Lien vers la section Use Structured Output Formats

Whenever your downstream system needs to parse the model's response, define the output format explicitly. For programmatic consumption, use JSON with a defined schema. For structured content, use XML tags or markdown with consistent headings.

Respond in the following JSON format:
{
  "answer": "your answer here",
  "confidence": "high | medium | low",
  "sources": ["list of source identifiers used"],
  "follow_up_needed": true | false
}

Structured outputs reduce parsing errors, make evaluation easier (you can check individual fields), and constrain the model's tendency to ramble. Many APIs now support structured output natively — use it.

Negative Space: Tell the Model What Not to Do

Lien vers la section Negative Space: Tell the Model What Not to Do

Models have strong defaults. Without explicit constraints, they'll be verbose, hedging, and eager to please. The most impactful prompt improvements are often subtractive — telling the model what to avoid.

Effective negative constraints:

  • "Do not make up information. If you don't know, say so."
  • "Do not include disclaimers or caveats unless specifically relevant."
  • "Do not repeat the question back before answering."
  • "If the retrieved context doesn't contain the answer, say 'I don't have enough information' — do not guess."

These constraints are especially important in agentic systems where the output feeds into another step. A hallucinated intermediate result compounds through the pipeline.

Context Management: The Hard Problem

Lien vers la section Context Management: The Hard Problem

The most impactful skill in advanced prompt engineering isn't wordsmithing — it's context management. The model can only use what's in the context window. Getting the right information into that window, in the right order, at the right priority, is where production prompts succeed or fail.

Prioritize Context Ruthlessly

Lien vers la section Prioritize Context Ruthlessly

Context windows are budgets. Every token spent on low-value context is a token not spent on something useful. Cursor's Priompt library makes this explicit: each prompt element has a priority score, and when the token budget is exceeded, lower-priority elements are dropped via binary search.

You don't need Priompt to apply this principle. Rank your context sources by importance. Put the most critical information first (models attend to the beginning of the context more reliably). Truncate from the bottom, not randomly. And measure: does adding this context actually improve your eval scores, or is it just noise?

Dynamic Context Assembly

Lien vers la section Dynamic Context Assembly

Production prompts are rarely static. They're assembled at runtime from multiple sources: system instructions (fixed), retrieved documents (variable), user profile (variable), conversation history (growing), tool results (dynamic).

Design your prompt as a template with slots:

[SYSTEM INSTRUCTIONS - fixed, ~500 tokens]
[USER PROFILE - fetched at runtime, ~200 tokens]
[RETRIEVED CONTEXT - from RAG, top-k chunks, ~2000 tokens]
[CONVERSATION HISTORY - last N turns, ~1000 tokens]
[CURRENT QUERY - user's message]
[OUTPUT INSTRUCTIONS - format, constraints]

This pattern makes it explicit where each piece of context comes from, how much budget it gets, and what gets cut first when the window is tight. WHOOP's inline tools take this further — data retrieval is embedded directly in the prompt template via markup, executed in parallel before generation begins.

Manage Conversation History Deliberately

Lien vers la section Manage Conversation History Deliberately

In multi-turn conversations, history grows with every exchange. Naive approaches append everything, eventually pushing critical context out of the window. Smarter approaches:

  • Sliding window: Keep only the last N turns. Simple, but loses early context.
  • Summarization: Periodically summarize older turns into a compact representation. Cursor's Composer 2 does this during RL training — the model learns when and how to self-summarize.
  • Selective retention: Keep turns that contain important decisions or context, drop purely transactional ones.
  • Memory extraction: Pull key facts from the conversation into a structured memory store (as WHOOP does with memory nuggets), and inject them as context rather than keeping raw history.

Few-Shot Engineering

Lien vers la section Few-Shot Engineering

Few-shot examples are often more effective than detailed instructions. The model learns format, tone, reasoning patterns, and edge case handling from examples in ways that instructions alone can't convey.

Quality Over Quantity

Lien vers la section Quality Over Quantity

Two perfect examples beat ten mediocre ones. Each example should demonstrate exactly the behavior you want, including how to handle difficult cases. Include at least one example that shows the model not doing something — refusing a bad request, saying "I don't know," or handling an edge case gracefully.

Cover the Distribution

Lien vers la section Cover the Distribution

Your examples should represent the range of inputs the model will encounter. If 80% of queries are simple lookups and 20% are complex reasoning, your examples should roughly match that distribution. Don't only show the hard cases — the model needs to know how simple cases should look too.

Use Negative Examples

Lien vers la section Use Negative Examples

Show the model what a bad response looks like and why it's bad:

Example (BAD response):
User: What was my heart rate during sleep?
Response: Your heart rate was probably around 60 BPM based on typical values.
Why this is bad: Uses generic data instead of the user's actual metrics.

Example (GOOD response):
User: What was my heart rate during sleep?
Response: Your average heart rate during sleep last night was 54 BPM, which is 3 BPM lower than your 30-day average.
Why this is good: Uses the user's actual data with contextual comparison.

This contrast pattern is one of the most effective prompt engineering techniques. The model learns not just what to do, but what to avoid and why.

Chain of Thought and Reasoning Control

Lien vers la section Chain of Thought and Reasoning Control

When to Use Chain of Thought

Lien vers la section When to Use Chain of Thought

Chain of thought (CoT) — asking the model to show its reasoning before giving an answer — improves accuracy on tasks that require multi-step reasoning: math, logic, planning, complex analysis. It doesn't help (and can hurt) on simple lookup tasks, classification, or extraction.

WHOOP learned this when evaluating GPT-5: the model's reasoning mode underperformed GPT-4.1 on low-latency chat queries. The reasoning overhead added latency without improving quality for straightforward questions. Use CoT deliberately, not as a default.

Structured Reasoning

Lien vers la section Structured Reasoning

Rather than "think step by step" (which is vague), give the model a specific reasoning structure:

Before answering, analyze the question using these steps:
1. Identify what data is needed to answer this question
2. Check whether the provided context contains that data
3. If the data is present, formulate an answer citing specific values
4. If the data is missing, state what's missing and don't guess

This produces more consistent and debuggable reasoning chains. You can evaluate each step independently, catching failures in reasoning even when the final answer happens to be correct.

Hide the Reasoning When Needed

Lien vers la section Hide the Reasoning When Needed

In user-facing applications, you often want the model to reason internally but only show the conclusion. Use XML tags or delimiters to separate reasoning from output:

<reasoning>
[Internal analysis — not shown to user]
</reasoning>
<response>
[Clean answer shown to user]
</response>

Parse out the reasoning in your application layer. Keep it in your logs for debugging. This gives you the accuracy benefits of CoT without the UX cost of verbose responses.

Production Prompt Practices

Lien vers la section Production Prompt Practices

Version Everything

Lien vers la section Version Everything

Every prompt change should be tracked — who changed it, when, why, and what the eval results were before and after. Use a prompt management system (Priompt, PromptLayer, Humanloop, or even a Git repo with a naming convention). The goal: you should be able to roll back to any previous version in minutes.

Test Before You Ship

Lien vers la section Test Before You Ship

Run your eval suite on every prompt change. Compare metrics against the baseline. Look for regressions across the full test set, not just spot-checks on a few examples. The Memory agent regression at WHOOP — where a "better" prompt was measurably worse — was caught by automated evals, not manual review.

Treat Prompt Debt Like Tech Debt

Lien vers la section Treat Prompt Debt Like Tech Debt

Prompts accumulate cruft: instructions added for edge cases that were later fixed elsewhere, redundant constraints, examples that no longer match the model's behavior. Periodically audit your prompts. Remove instructions that evals show have no effect. Simplify where possible. A shorter prompt that performs the same is a better prompt — it's cheaper, faster, and less likely to confuse the model.

The Takeaway

Lien vers la section The Takeaway

Advanced prompt engineering is systems engineering applied to natural language. The skills that matter aren't creative writing — they're context management, structured decomposition, systematic evaluation, and disciplined version control. The best prompt is not the cleverest one. It's the one that works reliably at scale, fails predictably, and improves measurably when you change it.

Further Reading

Lien vers la section Further Reading