Configure step-by-step reasoning and discover where pure LLM logic breaks down.
This example demonstrates how to configure an LLM as a reasoning agent capable of analytical thinking and quantitative problem-solving. It shows the bridge between simple text generation and complex cognitive tasks.
A reasoning agent is an LLM configured to perform logical analysis, mathematical computation, and multi-step problem-solving through careful system prompt design.
Regular Chat Reasoning Agent
───────────── ──────────────────
"Can you help me?" "I am a mathematician.
"Sure! What do you need?" I analyze problems methodically
and compute exact answers."
LLMs are trained on text prediction, not explicit reasoning:
┌───────────────────────────────────────┐
│ LLM Training │
│ "Predict next word in text" │
│ │
│ NOT explicitly trained for: │
│ • Step-by-step logic │
│ • Arithmetic computation │
│ • Tracking multiple variables │
│ • Systematic problem decomposition │
└───────────────────────────────────────┘
However, they can learn reasoning patterns from training data and be guided by system prompts.
┌─────────────────────────────────────────┐
│ System Prompt Components │
├─────────────────────────────────────────┤
│ 1. Role: "Expert reasoner" │
│ 2. Task: "Analyze and solve problems" │
│ 3. Method: "Compute exact answers" │
│ 4. Output: "Single numeric value" │
└─────────────────────────────────────────┘
↓
Reasoning Behavior
Quantitative Reasoning (this example):
Problem → Count entities → Calculate → Convert units → Answer
Logical Reasoning:
Premises → Apply rules → Deduce conclusions → Answer
Analytical Reasoning:
Data → Identify patterns → Form hypothesis → Conclude
LLMs don't reason like humans, but they can:
┌─────────────────────────────────────────────┐
│ What LLMs Actually Do │
│ │
│ 1. Pattern Recognition │
│ "This looks like a counting problem" │
│ │
│ 2. Template Application │
│ "Similar problems follow this pattern" │
│ │
│ 3. Statistical Inference │
│ "These numbers likely combine this way" │
│ │
│ 4. Learned Procedures │
│ "I've seen this type of calculation" │
└─────────────────────────────────────────────┘
Input: Complex Word Problem
↓
┌────────────┐
│ Parse │ Identify entities and relationships
└────────────┘
↓
┌────────────┐
│ Decompose │ Break into sub-problems
└────────────┘
↓
┌────────────┐
│ Calculate │ Apply arithmetic operations
└────────────┘
↓
┌────────────┐
│ Synthesize│ Combine results
└────────────┘
↓
Final Answer
Easy Hard
│ │
│ Simple Multi-step Nested Implicit │
│ Arithmetic Logic Conditions Reasoning│
│ │
└─────────────────────────────────────────────┘
Examples:
Easy: "What is 5 + 3?"
Medium: "If 3 apples cost $2 each, what's the total?"
Hard: "Count family members with complex relationships"
The potato problem is highly complex:
┌─────────────────────────────────────────┐
│ Complexity Factors │
├─────────────────────────────────────────┤
│ ✓ Multiple entities (15+ people) │
│ ✓ Relationship reasoning (family tree)│
│ ✓ Conditional logic (if married then..)│
│ ✓ Negative conditions (deceased people)│
│ ✓ Special cases (dietary restrictions)│
│ ✓ Multiple calculations │
│ ✓ Unit conversions │
└─────────────────────────────────────────┘
┌────────────────────────────────────┐
│ Problem: No External Tools │
│ │
│ LLM must hold everything in │
│ "mental" context: │
│ • All entity counts │
│ • Intermediate calculations │
│ • Conversion factors │
│ • Final arithmetic │
│ │
│ Result: Prone to errors │
└────────────────────────────────────┘
1. Counting Errors:
Problem: "Count 15 people with complex relationships"
LLM: "14" or "16" (off by one)
2. Arithmetic Mistakes:
Problem: "13 adults × 1.5 + 3 kids × 0.5"
LLM: May get intermediate steps wrong
3. Lost Context:
Problem: Multi-step with many facts
LLM: Forgets earlier information
User → LLM → Answer
↑
System Prompt
Limitations:
User → LLM → Show Work → Answer
↑
"Explain your reasoning"
Improvements:
User → LLM ⟷ Tools → Answer
↑ (Calculator)
System Prompt
Improvements:
User → LLM → Think → Act → Observe
↑ ↓ ↓ ↓
System Reason Tool Result
Prompt Use
↑ ↓ ↓
└───────────Iterate──┘
Best approach:
1. Role Definition:
"You are an expert logical and quantitative reasoner"
Sets the mental framework.
2. Task Specification:
"Analyze real-world word problems involving..."
Defines the problem domain.
3. Output Format:
"Return the correct final number as a single value"
Controls response structure.
Pattern A: Direct Answer (This Example)
Prompt: [Problem]
Output: [Number]
Pros: Concise, fast Cons: No insight into reasoning
Pattern B: Show Work
Prompt: [Problem] "Show your steps"
Output: Step 1: ... Step 2: ... Answer: [Number]
Pros: Transparent, debuggable Cons: Longer, may still have errors
Pattern C: Self-Verification
Prompt: [Problem] "Solve, then verify"
Output: Solution + Verification + Final Answer
Pros: More reliable Cons: Slower, uses more tokens
1. Data Analysis:
Input: Dataset summary
Task: Compute statistics, identify trends
Output: Numerical insights
2. Planning:
Input: Goal + constraints
Task: Reason about optimal sequence
Output: Action plan
3. Decision Support:
Input: Options + criteria
Task: Evaluate and compare
Output: Recommended choice
4. Problem Solving:
Input: Complex scenario
Task: Break down and solve
Output: Solution
Reasoning Tools Memory Multi-turn
───────── ───── ────── ──────────
intro.js ✗ ✗ ✗ ✗
translation.js ~ ✗ ✗ ✗
think.js (here) ✓ ✗ ✗ ✗
simple-agent.js ✓ ✓ ✗ ~
memory-agent.js ✓ ✓ ✓ ✓
react-agent.js ✓✓ ✓ ~ ✓
Legend:
After understanding basic reasoning:
This example is the foundation for more sophisticated agent architectures that combine reasoning with external capabilities.