liveBook · Manning

Chain-of-thought

As explained in AI Agents in Action

Reasoning is the process of deriving conclusions, plans, or solutions by relating information through intermediate steps.

Chain-of-thought prompting asks a language model to work through a problem in intermediate steps rather than give only a final answer. It can help an agent reason about possible actions and their outcomes; planning builds on this by ordering actions to reach a goal. section 10.2 section 10.2.2

A simple zero-shot approach needs no worked examples: include “Let’s think step by step” in the prompt, followed by the problem. You can also ask for a final answer in a single statement. Example-based chain-of-thought prompts require more effort to prepare for a particular class of problem; the simpler zero-shot approach is more general but may be less effective. section 10.2.2

Listing 10.11 cot.jinja2
system:
You are an expert in solving time travel problems.
You are given a time travel problem and you have to solve it.
Let's think step by step.     #1
Please finalize your answer in a single statement.     #2

user:
{{statement}}     #3

This prompt template combines the step-by-step instruction, a request for a final statement, and a placeholder for the problem. section 10.2.2

Check a time-travel answer

Give the model a time-travel problem and ask it to work through the jumps and elapsed days step by step. In a test flow, send the problem to the reasoning prompt, then pass its predicted answer, the problem, and an expected answer to a separate evaluation prompt for scoring. A detailed explanation is not proof of correctness: one model broke down the problem but still answered incorrectly. When the correct answer is known, ask the model to review its mistake and suggest feedback for similar problems. section 10.2.2 section 11.4

Reasoning can support task planning and evaluation, but it also adds response-time overhead. For a real-time assistant or a well-defined workflow, less reasoning may be preferable; for a complex task, breaking the work into steps may be useful. section 1.2 section 11.5.2

How AI Agents in Action covers it

How deep it goes
Explains zero-shot stepwise prompting and an answer-evaluation flow, and compares it with example-based prompting.
Examples
Tests a time-travel problem against an expected answer and uses corrective feedback after an incorrect response.
What you can do after
Apply it via a step-by-step prompt and evaluate the predicted answer against an expected solution.
How it connects
Connects reasoning with planning, evaluation, feedback, and prompt engineering.

Also explained in

Compare how 21 books explain chain-of-thought →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of AI Agents in Action. The section links point to the parts of the book it draws on.