Step-by-Step Problem Solving (Chain-of-Thought) › The Magic Phrase: "Let's Think Step by Step"
Michael BrenndoerferJune 17, 20252 min read
AI Agent HandbookAll chapters Part 4 of 15Reasoning - Teaching the Agent to Think
Step-by-Step Problem Solving (Chain-of-Thought) › The Magic Phrase: "Let's Think Step by Step"One section · Sections in this chapter4 / 13 ↓
Sections in this chapter13
The simplest way to trigger chain-of-thought reasoning is to add a phrase like "Let's think through this step by step" or "Let's solve this step by step" to your prompt. This small addition signals to the model that you want explicit reasoning, not just a final answer.
Example (GPT-5)
Let's see this in action with a simple word problem:
In[3]:
Codeimport os
from openai import OpenAI
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
## Without chain-of-thought
prompt_simple = """A restaurant has 23 tables. Each table has 4 chairs.
If 12 chairs are broken and removed, how many chairs are left?"""
## With chain-of-thought
prompt_cot = """A restaurant has 23 tables. Each table has 4 chairs.
If 12 chairs are broken and removed, how many chairs are left?
Let's think through this step by step."""
## Get both responses
## Using GPT-5 for basic prompting and text generation
response_simple = client.chat.completions.create(
model="gpt-5", messages=[{"role": "user", "content": prompt_simple}]
)
response_cot = client.chat.completions.create(
model="gpt-5", messages=[{"role": "user", "content": prompt_cot}]
)
print("Without CoT:")
print(response_simple.choices[0].message.content)
print("\nWith CoT:")
print(response_cot.choices[0].message.content)Out[3]:
ConsoleWithout CoT: Total chairs = 23 × 4 = 92. After removing 12 broken chairs: 92 − 12 = 80 chairs left. With CoT: - Total chairs initially: 23 tables × 4 chairs/table = 92 - Subtract broken chairs: 92 − 12 = 80 So, 80 chairs are left.
The first response might just say "80 chairs" (which is wrong, by the way). The second response will show the reasoning:
Let's think through this step by step.
Step 1: Calculate the total number of chairs
- 23 tables $\times$ 4 chairs per table = 92 chairs
Step 2: Subtract the broken chairs
- 92 chairs - 12 broken chairs = 80 chairs
Therefore, there are 80 chairs left in the restaurant.Wait, that's still 80. Let me recalculate: , then . Actually, that's correct! The point is that with chain-of-thought, you can verify each step. If there were an error, you'd see exactly where it occurred.