Phase 1: Advanced Prompt Engineering for Agents · 55 min · Python · Anthropic SDK
Chain-of-Thought & Reasoning Patterns
Chain-of-thought turns an unverifiable answer into an auditable reasoning trace.
Hiring signal: At Anthropic and OpenAI, engineering teams use structured reasoning traces for debugging production agents. Candidates who can describe ReAct traces and scratchpad inspection demonstrate practitioner experience that sets them apart in interviews.
What you will learn
- Implement zero-shot and few-shot chain-of-thought prompting
- Apply the ReAct (Reasoning + Acting) pattern to build traceable tool-using agents
- Use scratchpad and internal monologue patterns to improve reasoning without leaking intermediate steps to users
The Problem
You ask an agent to analyze a complex contract and recommend the risk level. It outputs "High risk" — two words. You have no idea why. When a lawyer asks you to explain the recommendation, you can't. When it produces a wrong answer next week, you can't debug it. You consider logging it, but there's nothing to log.
The core problem isn't accuracy — it's opacity. A "High risk" answer with no reasoning is not just hard to trust; it's impossible to improve. You can't tell if the model is reasoning correctly and landed on the wrong conclusion, or if it's reasoning incorrectly but reaching a plausible answer by accident.
Chain-of-thought prompting changes "High risk" into a 10-step analysis: "The contract contains a unilateral termination clause in section 4.2 (risk: high), an uncapped liability provision in section 7 (risk: high), and no dispute resolution mechanism (risk: medium)..." Now you can audit it, debug it, and explain it.
Accuracy and auditability are the same investment
Wei et al. (2022) showed that chain-of-thought prompting improves accuracy on multi-step reasoning tasks by 10–30 percentage points — not because it adds external information, but because it forces the model to process sub-problems serially rather than collapsing them into a single token prediction. Auditability and accuracy are the same mechanism: explicit intermediate steps.
Why Chain-of-Thought Works
CoT prompting forces serial decomposition. When a model answers directly, it tries to compress the entire reasoning path into a single next-token prediction. When it's required to write out intermediate steps, each step becomes a conditioning context for the next — effectively giving the model a working memory in the context window.
The mechanism: language models predict the next token based on all preceding tokens. When intermediate reasoning steps exist in the context, they constrain and guide subsequent steps. A model predicting step 5 of an analysis has 4 prior steps anchoring it to the right conceptual track.
Zero-shot CoT: Adding "Let's think step by step." to a prompt triggers this behavior without examples. It works because the instruction shifts the model's generation mode.
Few-shot CoT: Including 2–3 worked examples in the format Question → Reasoning steps → Answer is more reliable for specific domains. The model matches the style and depth of reasoning from the examples.
For production agents, few-shot CoT is preferred because you can control the reasoning format: how many steps, what level of detail, whether to cite sources, and how to structure the conclusion.
Unlock the full lesson
You've read the first 2 sections. The rest of this lesson covers The ReAct Pattern, Scratchpad and Internal Monologue, Build It, What to Practice — plus a hands-on lab, quiz, and project artifact.
Create a free account to unlock Phase 0 and Phase 1 of every course — no credit card.
Browse all courses · View pricing · DeVenture Academy