ProjekinAja. Agentic AI Stage 2 · How Agents Work Lesson 2.6
● Stage 2 · Lesson 2.6

Reasoning: Chain-of-Thought, Reflection & Self-Correction

A loop is only as good as the thinking inside it. Reasoning is how an agent decides well, catches its own mistakes, and doesn't just spin in circles.

⏱ ~15 min read 🧠 The thinking layer 🔁 Why agents feel smart

🎯 By the end you'll understand

Why making a model think out loud step by step (chain-of-thought) sharply improves hard reasoning, how an agent reviews and revises its own work (reflection), how it fixes course from a tool result or failed check (self-correction), the patterns that package this up — ReAct, Reflexion, verifier passes — and the honest limits: confident reasoning can still be flat wrong.

KEY INSIGHTThe one idea to take away

The same model gets dramatically smarter when you let it think before it speaks — and smarter still when you let it check what it just said.

In Lesson 2.1 you met the loop: act → observe → decide → repeat. This lesson is about the decide step — the quality of the thinking that fills the loop. An agent that reasons carefully and reviews its own work runs a productive loop. An agent that blurts out the first thing that comes to mind runs a loop that wanders, repeats mistakes, and burns tokens going nowhere.

🔑 Hold onto this

Reasoning is not a different brain — it's the same model given room to work the problem out. Chain-of-thought gives it room to think; reflection gives it room to double-check; self-correction lets a real-world result pull it back on track. Together they're why modern agents feel so much smarter than the chatbots of a few years ago.

CORE CONCEPTChain-of-thought: thinking out loud

Ask a model a tricky multi-step question and demand an instant answer, and it often blurts — it pattern-matches to something that looks right and commits to it. Ask the same model to "think step by step" first, and accuracy on hard problems jumps, sometimes enormously.

That technique has a name: chain-of-thought (CoT). Instead of question → answer, you get question → reasoning steps → answer. The model writes out its working — the intermediate steps a careful person would scribble on paper — before committing to a final answer.

📖 Chain-of-thought (CoT)

Prompting or training a model to produce intermediate reasoning steps before its final answer. The steps aren't decoration — generating them is what lets the model reach a better answer. "Let's think step by step" is the classic one-line trigger.

Here's the same problem two ways. The question: "A shop sells pens at 3 for $2. I have $10. How many pens can I buy?"

Blurt 💨Chain-of-thought 🧠
Shapestraight to an answerreasoning, then answer
Response"About 6 pens.""3 pens = $2, so 1 pen ≈ $0.67. $10 ÷ $0.67 ≈ 14.9 → 15 pens. Check: 15 = 5 sets of 3 = $10 exactly. 15 pens."
Whymatched "$10 / pens" to a plausible-looking number, no workingworked the units, then verified against the budget

The blurt isn't stupid — it's a confident guess from a system asked to answer before it has worked anything out. The chain-of-thought version simply gave the model the steps it needed to get there honestly.

CORE CONCEPTWhy thinking out loud actually helps

This surprises people: why would writing more text make a model more correct? The answer is in how these models generate output. A language model produces one token at a time, left to right, and each token it writes becomes part of the context for the next one (you met context in Lesson 1.3).

When you force a single, immediate answer, the model has to compress an entire multi-step problem into one leap — there's nowhere to "do the math." When you let it write reasoning first, each step becomes scratch paper it can read back. Step 3 can build on the result it computed in step 2, because step 2 is now sitting right there in the context.

💡 The mental model

Asking a model for an instant answer to a hard problem is like asking you to multiply 47 × 89 in your head and shout the result. Chain-of-thought is handing you a pencil. Same brain — but now there's somewhere to carry the work.

One more wrinkle for 2026: many current models are reasoning models — trained to do this thinking automatically, often in a hidden scratch space before they answer. You don't have to say "think step by step"; they already do. That's a big part of why agents got noticeably better at hard, multi-step tasks. But the underlying mechanic is the same: room to work the problem out.

📖 Reasoning model

A model trained to spend extra computation "thinking" — generating internal reasoning — before producing a final answer. It trades more time and tokens for better answers on hard problems. Not always worth it for easy ones (see the limits).

SEE ITThink vs Blurt — watch the difference

A genuinely tricky word problem below. Pick a mode and press Run. Blurt answers instantly. Chain-of-thought reveals its reasoning one step at a time. Then, if it slips, press Reflect and watch it catch its own error.

🧠 Interactive · Same question, two ways of thinking

Question: "A bat and a ball cost $1.10 together. The bat costs $1.00 more than the ball. How much is the ball?"

YouHow much is the ball?
Model (blurt)

This widget is hand-authored and deterministic — it illustrates the shape of each approach, not a live model. The "10 cents" blurt is the famously intuitive-but-wrong answer real people (and rushed models) give.

CORE CONCEPTReflection: the agent reviews its own work

Chain-of-thought helps a model reach a better answer. Reflection goes one step further: after producing an answer or result, the agent looks back at it and asks the questions a careful reviewer would — "Is this actually right? What did I miss? What's the weakest part?" — then revises.

You saw it in the widget. The blurt says "10 cents." A reflection pass checks the constraint: if the ball is 10¢, the bat is $1.10, and together that's $1.20 — not $1.10. The check fails, so the agent corrects to 5¢. The model didn't get a new brain; it just graded its own homework before handing it in.

📖 Reflection (self-critique)

A step where an agent evaluates its own output against the goal or known constraints, identifies flaws, and produces a revised attempt. Often run as a separate "critic" pass — the same model wearing a reviewer hat instead of a doer hat.

Why does looking at your own work as a separate step help, if it's the same model? Because critiquing is an easier task than creating. Spotting "that total doesn't add up" is lower-difficulty than generating the right answer from scratch — for models, much as for people. The reviewer hat sees things the author hat raced past.

Generating is hard. Checking is easier. Reflection is the agent putting on the checker's hat — and that small shift catches a lot of confident mistakes.

CORE CONCEPTSelf-correction: letting reality push back

Reflection is the agent checking itself against its own reasoning. Self-correction in the loop is stronger: the agent checks itself against the real world — a tool result, a failed test, an error message — and fixes course. This is where reasoning fuses with the loop from Lesson 2.1.

Picture a coding agent told to fix a bug. It reasons about the cause, edits a file, and runs the tests. The tests fail with a clear error. A blurting agent might shrug and declare victory. A reasoning agent reads the failure, updates its understanding — "ah, the off-by-one is in the loop bound, not the condition" — and tries again. The failed check became fuel.

🧠 Reason 🛠️ Act 👁️ Observe 🔍 Reflect ✅ Done if wrong → revise

That dashed Reflect → Reason arrow is the whole game. Without it, an agent that hits a bad result just barrels on. With it, every observation — especially a failure — becomes a chance to think again and do better. A failed check isn't a dead end; it's information.

▸ The pattern in one line

Reason → Act → Observe → (Reflect) → Reason again. The reflect step is what turns a loop that spins into a loop that converges.

FRAMEWORKThe named patterns you'll keep meeting

These ideas got packaged into a few well-known patterns. You don't need to implement them by hand — modern agent frameworks bake them in — but you should recognize them by name:

🔀

ReAct (Reason + Act)

Interleave thinking and acting: think a little, take one action, observe the result, think again. Reasoning and tool use take turns in the same loop rather than the model planning everything up front. The default shape of most agents today.

🪞

Reflexion-style self-review

After an attempt fails or falls short, the agent writes a short critique of what went wrong and feeds that reflection back in as a lesson for the next try. It "learns" within a task by remembering its own mistakes.

🧪

Verifier passes

A separate check — sometimes another model, sometimes a hard test (run the code, validate the JSON) — judges whether the output is actually correct before it's accepted. The strongest form: verify against reality, not opinion.

💡 How they fit together

ReAct gives the agent its rhythm (think/act/observe). Reflexion gives it memory of its mistakes. Verifiers give it a standard to pass. Most capable agents use some blend of all three — which is why they recover from errors that would have stumped a one-shot chatbot.

WEAKNESSThe honest limits

Reasoning is powerful, not magic. Three uncomfortable truths keep good engineers humble:

⚠️ Reasoning can be plausible but wrong

A chain-of-thought can look airtight, read beautifully, and still reach a confidently false conclusion — with the model inventing tidy-sounding steps to justify a wrong answer. Fluent reasoning is not proof of correct reasoning. The prettier the explanation, the more careful you should be.

⚠️ Models can't always catch their own errors

Reflection helps, but it isn't reliable. A model can re-read its own flawed work and pronounce it fine — or "correct" something that was already right into something wrong. Self-critique misses exactly the errors the model is blind to in the first place. That's why a check against reality (tests, tools, data) beats a check against opinion.

⚠️ More thinking costs more — and isn't always better

Every reasoning step and reflection pass spends tokens, time, and money. For an easy question, a reasoning model can overthink a simple thing into a worse answer. More thinking has diminishing — sometimes negative — returns. Match the depth of reasoning to the difficulty of the task.

The takeaway isn't "don't trust reasoning." It's: reasoning makes agents better, but it doesn't make them trustworthy on its own. That gap is exactly why a real verification step — by a tool, a test, or a human — matters so much. You'll build those checks deliberately in Lesson 3.6 and Lesson 4.9.

WEAKNESSCommon mistakes to avoid

✗ "More thinking always equals better answers."

No. Reasoning has diminishing returns and a real cost. Easy tasks can be worse with a reasoning model that overthinks them. Spend thinking where the difficulty is, not everywhere.

✗ "If it explains itself, it must be right."

A confident, well-written chain-of-thought can lead to a wrong answer with invented justifications. The explanation is a story about the answer — not a guarantee of it. Verify, don't admire.

✗ "Reflection guarantees correctness."

Self-review catches some errors, not all — and can occasionally break something that was fine. It's a useful filter, not a proof. The reliable check is against the real world: a test, a tool result, a human.

KEY INSIGHTWhere this connects in your course

  • The loop (2.1) — reasoning is the quality of the decide step; reflection adds the "check before continuing" arrow to the loop.
  • Planning & decomposition (2.5) — chain-of-thought is reasoning within a step; planning is reasoning about the whole sequence. Re-planning is self-correction at the plan level.
  • The LLM engine (1.3) — reasoning works because the model generates token by token, reading back its own scratch work as it goes.
  • Verification & trust (3.6) — since reasoning can be confidently wrong, you'll learn to build the human and automated checks that catch it.
  • Evaluating agents (4.9) — when you build your own, you'll add verifier passes and tests so the agent's reasoning is checked against reality, not just its own opinion.

This is the lesson that explains why modern agents feel smart — and, just as importantly, why feeling smart is never enough on its own.

GLOSSARYKey terms introduced

Chain-of-thought (CoT)
Having a model produce intermediate reasoning steps before its final answer, which improves accuracy on hard problems.
Reflection
A step where the agent critiques its own output against the goal or constraints, then revises it.
Self-correction
Using a real-world signal — a tool result, failed test, or error — to fix course on the next loop iteration.
ReAct
A pattern that interleaves reasoning and acting: think, take one action, observe, think again.
Verifier
A separate check (another model, a test, a tool) that judges whether an output is correct before it's accepted.
Reasoning model
A model trained to spend extra "thinking" computation before answering — trading time and tokens for better answers on hard tasks.

ACTIVE RECALLCheck your understanding

Answer in your own words first, then reveal.

1Why does making a model "think step by step" improve its answers on hard problems?›

Because the model generates one token at a time and reads back what it has written. Writing out reasoning gives it scratch paper — each step can build on the last — instead of forcing the whole problem into one immediate leap.

2What's the difference between reflection and self-correction?›

Reflection is the agent checking its work against its own reasoning or known constraints ("does this add up?"). Self-correction is fixing course based on a real-world signal — a failed test, an error, a tool result. Reality is the stronger check.

3Name the three patterns and what each contributes.›

ReAct = rhythm (interleave reason + act + observe). Reflexion-style self-review = memory of mistakes (critique a failure, feed the lesson back). Verifier passes = a standard to pass (an independent check, ideally against reality).

4Give the single biggest reason you still can't fully trust a model's reasoning.›

A chain-of-thought can be plausible but wrong — fluent, confident, and false, with invented steps justifying a bad answer. A good explanation is not proof of a correct answer, which is why an external verification step (test, tool, human) matters.

Nicely reasoned. Next: agents that work together →