@ckelsoe/prompt-architect 3.0.2 → 3.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/CHANGELOG.md +264 -264
- package/LICENSE +21 -21
- package/README.md +1064 -1184
- package/adapters/README.md +75 -267
- package/adapters/for-windsurf.md +136 -136
- package/adapters/system-prompt.md +243 -243
- package/package.json +139 -138
- package/scripts/build-skill.js +64 -0
- package/scripts/install.js +4 -54
- package/scripts/test.js +205 -213
- package/scripts/validate-skill.js +350 -350
- package/skills/prompt-architect/SKILL.md +331 -331
- package/skills/prompt-architect/assets/templates/ape_template.txt +5 -5
- package/skills/prompt-architect/assets/templates/bab_template.txt +15 -15
- package/skills/prompt-architect/assets/templates/broke_template.txt +15 -15
- package/skills/prompt-architect/assets/templates/cai-critique-revise_template.txt +18 -18
- package/skills/prompt-architect/assets/templates/care_template.txt +16 -16
- package/skills/prompt-architect/assets/templates/chain-of-density_template.txt +46 -46
- package/skills/prompt-architect/assets/templates/chain-of-thought_template.txt +49 -49
- package/skills/prompt-architect/assets/templates/co-star_template.txt +17 -17
- package/skills/prompt-architect/assets/templates/crispe_template.txt +14 -14
- package/skills/prompt-architect/assets/templates/ctf_template.txt +15 -15
- package/skills/prompt-architect/assets/templates/devils-advocate_template.txt +25 -25
- package/skills/prompt-architect/assets/templates/hybrid_template.txt +101 -101
- package/skills/prompt-architect/assets/templates/least-to-most_template.txt +16 -16
- package/skills/prompt-architect/assets/templates/plan-and-solve_template.txt +7 -7
- package/skills/prompt-architect/assets/templates/pre-mortem_template.txt +27 -27
- package/skills/prompt-architect/assets/templates/race_template.txt +19 -19
- package/skills/prompt-architect/assets/templates/rcot_template.txt +31 -31
- package/skills/prompt-architect/assets/templates/react_template.txt +27 -27
- package/skills/prompt-architect/assets/templates/reverse-role_template.txt +11 -11
- package/skills/prompt-architect/assets/templates/rise-ie_template.txt +23 -23
- package/skills/prompt-architect/assets/templates/rise-ix_template.txt +28 -28
- package/skills/prompt-architect/assets/templates/risen_template.txt +21 -21
- package/skills/prompt-architect/assets/templates/rpef_template.txt +26 -26
- package/skills/prompt-architect/assets/templates/rtf_template.txt +13 -13
- package/skills/prompt-architect/assets/templates/self-refine_template.txt +16 -16
- package/skills/prompt-architect/assets/templates/skeleton-of-thought_template.txt +15 -15
- package/skills/prompt-architect/assets/templates/step-back_template.txt +10 -10
- package/skills/prompt-architect/assets/templates/tidd-ec_template.txt +45 -45
- package/skills/prompt-architect/assets/templates/tree-of-thought_template.txt +30 -30
- package/skills/prompt-architect/references/frameworks/ape.md +200 -200
- package/skills/prompt-architect/references/frameworks/bab.md +242 -242
- package/skills/prompt-architect/references/frameworks/broke.md +242 -242
- package/skills/prompt-architect/references/frameworks/cai-critique-revise.md +230 -230
- package/skills/prompt-architect/references/frameworks/care.md +235 -235
- package/skills/prompt-architect/references/frameworks/chain-of-density.md +479 -479
- package/skills/prompt-architect/references/frameworks/chain-of-thought.md +424 -424
- package/skills/prompt-architect/references/frameworks/co-star.md +256 -256
- package/skills/prompt-architect/references/frameworks/crispe.md +253 -253
- package/skills/prompt-architect/references/frameworks/ctf.md +207 -207
- package/skills/prompt-architect/references/frameworks/devils-advocate.md +206 -206
- package/skills/prompt-architect/references/frameworks/least-to-most.md +226 -226
- package/skills/prompt-architect/references/frameworks/plan-and-solve.md +210 -210
- package/skills/prompt-architect/references/frameworks/pre-mortem.md +197 -197
- package/skills/prompt-architect/references/frameworks/race.md +243 -243
- package/skills/prompt-architect/references/frameworks/rcot.md +203 -203
- package/skills/prompt-architect/references/frameworks/react.md +304 -304
- package/skills/prompt-architect/references/frameworks/reverse-role.md +189 -189
- package/skills/prompt-architect/references/frameworks/rise.md +555 -555
- package/skills/prompt-architect/references/frameworks/risen.md +297 -297
- package/skills/prompt-architect/references/frameworks/rpef.md +195 -195
- package/skills/prompt-architect/references/frameworks/rtf.md +358 -358
- package/skills/prompt-architect/references/frameworks/self-refine.md +205 -205
- package/skills/prompt-architect/references/frameworks/skeleton-of-thought.md +186 -186
- package/skills/prompt-architect/references/frameworks/step-back.md +206 -206
- package/skills/prompt-architect/references/frameworks/tidd-ec.md +470 -470
- package/skills/prompt-architect/references/frameworks/tree-of-thought.md +260 -260
- package/skills/prompt-architect/scripts/framework_analyzer.py +807 -807
- package/skills/prompt-architect/scripts/prompt_evaluator.py +336 -336
- package/adapters/for-cursor.mdc +0 -138
- package/adapters/for-gemini-cli.md +0 -70
- package/adapters/for-github-copilot.md +0 -141
- package/adapters/for-openai-codex-cli.md +0 -158
|
@@ -1,424 +1,424 @@
|
|
|
1
|
-
# Chain of Thought (CoT) Framework
|
|
2
|
-
|
|
3
|
-
## Overview
|
|
4
|
-
|
|
5
|
-
Chain of Thought is a prompting technique that encourages step-by-step reasoning and makes the thinking process explicit. Instead of jumping to answers, it guides Claude to break down complex problems, show intermediate steps, and verify logic along the way.
|
|
6
|
-
|
|
7
|
-
## Core Concept
|
|
8
|
-
|
|
9
|
-
CoT works by:
|
|
10
|
-
1. Breaking complex problems into smaller steps
|
|
11
|
-
2. Making reasoning explicit at each step
|
|
12
|
-
3. Showing work rather than just final answers
|
|
13
|
-
4. Verifying logic progressively
|
|
14
|
-
5. Enabling error detection and correction
|
|
15
|
-
|
|
16
|
-
## When to Use Chain of Thought
|
|
17
|
-
|
|
18
|
-
**Ideal for:**
|
|
19
|
-
- Mathematical problem-solving
|
|
20
|
-
- Logical reasoning tasks
|
|
21
|
-
- Complex multi-step analysis
|
|
22
|
-
- Debugging and troubleshooting
|
|
23
|
-
- Decision-making with trade-offs
|
|
24
|
-
- Tasks where "showing your work" matters
|
|
25
|
-
|
|
26
|
-
**Not needed for:**
|
|
27
|
-
- Simple lookups or facts
|
|
28
|
-
- Straightforward transformations
|
|
29
|
-
- Tasks with obvious single steps
|
|
30
|
-
- Creative writing without logic requirements
|
|
31
|
-
|
|
32
|
-
## Implementation Approaches
|
|
33
|
-
|
|
34
|
-
### Approach 1: Explicit Instruction
|
|
35
|
-
Directly instruct Claude to think step-by-step.
|
|
36
|
-
|
|
37
|
-
**Example:**
|
|
38
|
-
```
|
|
39
|
-
Solve this problem step-by-step, showing your reasoning at each stage:
|
|
40
|
-
|
|
41
|
-
A company's revenue grew 15% in Q1, decreased 8% in Q2, grew 20% in Q3, and grew 5% in Q4. If they started the year with $1M in quarterly revenue, what was their Q4 revenue?
|
|
42
|
-
|
|
43
|
-
Think through this carefully:
|
|
44
|
-
1. Calculate Q1 revenue
|
|
45
|
-
2. Calculate Q2 revenue
|
|
46
|
-
3. Calculate Q3 revenue
|
|
47
|
-
4. Calculate Q4 revenue
|
|
48
|
-
5. Verify your calculation
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
### Approach 2: Zero-Shot CoT
|
|
52
|
-
Use trigger phrases that activate reasoning.
|
|
53
|
-
|
|
54
|
-
**Magic phrases:**
|
|
55
|
-
- "Let's think step by step."
|
|
56
|
-
- "Let's work through this systematically."
|
|
57
|
-
- "Let's break this down."
|
|
58
|
-
- "Think carefully about this."
|
|
59
|
-
|
|
60
|
-
**Example:**
|
|
61
|
-
```
|
|
62
|
-
What's the best database choice for a real-time analytics platform handling 1M events/second with complex aggregations? Let's think step by step.
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
### Approach 3: Few-Shot CoT
|
|
66
|
-
Provide examples showing step-by-step reasoning.
|
|
67
|
-
|
|
68
|
-
**Example:**
|
|
69
|
-
```
|
|
70
|
-
Example 1:
|
|
71
|
-
Q: If a train travels 120 miles in 2 hours, what's its speed?
|
|
72
|
-
A: Let's break this down:
|
|
73
|
-
1. Speed = Distance / Time
|
|
74
|
-
2. Distance = 120 miles
|
|
75
|
-
3. Time = 2 hours
|
|
76
|
-
4. Speed = 120 / 2 = 60 mph
|
|
77
|
-
Therefore: 60 mph
|
|
78
|
-
|
|
79
|
-
Example 2:
|
|
80
|
-
Q: A store offers 20% off, then an additional 10% off. What's the total discount on a $100 item?
|
|
81
|
-
A: Let's work through this:
|
|
82
|
-
1. First discount: 20% of $100 = $20
|
|
83
|
-
2. Price after first discount: $100 - $20 = $80
|
|
84
|
-
3. Second discount: 10% of $80 = $8
|
|
85
|
-
4. Final price: $80 - $8 = $72
|
|
86
|
-
5. Total discount: $100 - $72 = $28
|
|
87
|
-
6. Total discount percentage: 28/100 = 28%
|
|
88
|
-
Therefore: 28% total discount (not 30%)
|
|
89
|
-
|
|
90
|
-
Now solve:
|
|
91
|
-
Q: [Your problem]
|
|
92
|
-
A: Let's break this down:
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
### Approach 4: Structured CoT
|
|
96
|
-
Provide a template for reasoning.
|
|
97
|
-
|
|
98
|
-
**Example:**
|
|
99
|
-
```
|
|
100
|
-
Analyze whether we should migrate to microservices using this reasoning structure:
|
|
101
|
-
|
|
102
|
-
STEP 1 - CURRENT STATE:
|
|
103
|
-
[Describe current architecture]
|
|
104
|
-
|
|
105
|
-
STEP 2 - PROBLEMS:
|
|
106
|
-
[What problems exist?]
|
|
107
|
-
|
|
108
|
-
STEP 3 - MICROSERVICES BENEFITS:
|
|
109
|
-
[How would microservices help?]
|
|
110
|
-
|
|
111
|
-
STEP 4 - MICROSERVICES COSTS:
|
|
112
|
-
[What are the downsides?]
|
|
113
|
-
|
|
114
|
-
STEP 5 - ALTERNATIVES:
|
|
115
|
-
[What else could we do?]
|
|
116
|
-
|
|
117
|
-
STEP 6 - COMPARISON:
|
|
118
|
-
[Compare options systematically]
|
|
119
|
-
|
|
120
|
-
STEP 7 - RECOMMENDATION:
|
|
121
|
-
[Final decision with reasoning]
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
## Best Practices
|
|
125
|
-
|
|
126
|
-
### 1. Be Explicit About Steps
|
|
127
|
-
```
|
|
128
|
-
Good:
|
|
129
|
-
"Calculate the ROI step by step:
|
|
130
|
-
1. Calculate total costs
|
|
131
|
-
2. Calculate total revenue
|
|
132
|
-
3. Calculate profit (revenue - costs)
|
|
133
|
-
4. Calculate ROI (profit / costs * 100)
|
|
134
|
-
5. Interpret the result"
|
|
135
|
-
|
|
136
|
-
Poor:
|
|
137
|
-
"Calculate the ROI"
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
### 2. Request Verification
|
|
141
|
-
```
|
|
142
|
-
Good:
|
|
143
|
-
"After solving, verify your answer makes sense and check your math."
|
|
144
|
-
|
|
145
|
-
Poor:
|
|
146
|
-
[No verification step]
|
|
147
|
-
```
|
|
148
|
-
|
|
149
|
-
### 3. Encourage Self-Correction
|
|
150
|
-
```
|
|
151
|
-
Good:
|
|
152
|
-
"If you find an error in your reasoning, acknowledge it and correct your approach."
|
|
153
|
-
|
|
154
|
-
Poor:
|
|
155
|
-
[No mention of error handling]
|
|
156
|
-
```
|
|
157
|
-
|
|
158
|
-
### 4. Ask for Uncertainty Acknowledgment
|
|
159
|
-
```
|
|
160
|
-
Good:
|
|
161
|
-
"If you're uncertain at any step, state your assumptions and why you made them."
|
|
162
|
-
|
|
163
|
-
Poor:
|
|
164
|
-
[Assumes certainty at all steps]
|
|
165
|
-
```
|
|
166
|
-
|
|
167
|
-
## Complete Examples
|
|
168
|
-
|
|
169
|
-
### Example 1: Debugging
|
|
170
|
-
|
|
171
|
-
**Without CoT:**
|
|
172
|
-
```
|
|
173
|
-
Why isn't this code working?
|
|
174
|
-
[code snippet]
|
|
175
|
-
```
|
|
176
|
-
|
|
177
|
-
**With CoT:**
|
|
178
|
-
```
|
|
179
|
-
Debug this code by thinking through it step-by-step:
|
|
180
|
-
|
|
181
|
-
[code snippet]
|
|
182
|
-
|
|
183
|
-
Use this process:
|
|
184
|
-
1. Read the code and state what it's supposed to do
|
|
185
|
-
2. Identify the input and expected output
|
|
186
|
-
3. Trace through execution line by line
|
|
187
|
-
4. Note any suspicious patterns or red flags
|
|
188
|
-
5. Form hypotheses about the bug
|
|
189
|
-
6. Test each hypothesis against the code
|
|
190
|
-
7. Identify the root cause
|
|
191
|
-
8. Propose a fix
|
|
192
|
-
9. Verify the fix addresses the issue
|
|
193
|
-
```
|
|
194
|
-
|
|
195
|
-
### Example 2: System Design
|
|
196
|
-
|
|
197
|
-
**Without CoT:**
|
|
198
|
-
```
|
|
199
|
-
Design a URL shortener.
|
|
200
|
-
```
|
|
201
|
-
|
|
202
|
-
**With CoT:**
|
|
203
|
-
```
|
|
204
|
-
Design a URL shortener by working through these steps:
|
|
205
|
-
|
|
206
|
-
STEP 1 - REQUIREMENTS:
|
|
207
|
-
Think through what the system needs to do.
|
|
208
|
-
- Functional requirements?
|
|
209
|
-
- Non-functional requirements?
|
|
210
|
-
- Scale expectations?
|
|
211
|
-
|
|
212
|
-
STEP 2 - API DESIGN:
|
|
213
|
-
What endpoints do we need?
|
|
214
|
-
- Consider: creation, retrieval, analytics
|
|
215
|
-
|
|
216
|
-
STEP 3 - DATA MODEL:
|
|
217
|
-
How should we store URLs?
|
|
218
|
-
- What fields are needed?
|
|
219
|
-
- What indexes?
|
|
220
|
-
|
|
221
|
-
STEP 4 - URL GENERATION:
|
|
222
|
-
How do we create short codes?
|
|
223
|
-
- Base62 encoding? Hash? Counter?
|
|
224
|
-
- Collision handling?
|
|
225
|
-
|
|
226
|
-
STEP 5 - SCALABILITY:
|
|
227
|
-
How does this scale?
|
|
228
|
-
- Bottlenecks?
|
|
229
|
-
- Caching strategy?
|
|
230
|
-
- Database sharding?
|
|
231
|
-
|
|
232
|
-
STEP 6 - TRADE-OFFS:
|
|
233
|
-
What are we optimizing for vs. sacrificing?
|
|
234
|
-
|
|
235
|
-
For each step, explain your reasoning.
|
|
236
|
-
```
|
|
237
|
-
|
|
238
|
-
### Example 3: Decision Making
|
|
239
|
-
|
|
240
|
-
**Without CoT:**
|
|
241
|
-
```
|
|
242
|
-
Should we use MongoDB or PostgreSQL?
|
|
243
|
-
```
|
|
244
|
-
|
|
245
|
-
**With CoT:**
|
|
246
|
-
```
|
|
247
|
-
Decide between MongoDB and PostgreSQL by reasoning through:
|
|
248
|
-
|
|
249
|
-
STEP 1 - USE CASE ANALYSIS:
|
|
250
|
-
What are we building and what data patterns will we have?
|
|
251
|
-
- Data structure (structured/unstructured?)
|
|
252
|
-
- Relationships (complex/simple?)
|
|
253
|
-
- Query patterns (known/unknown?)
|
|
254
|
-
|
|
255
|
-
STEP 2 - MONGODB EVALUATION:
|
|
256
|
-
Pros for our use case:
|
|
257
|
-
[List and explain]
|
|
258
|
-
Cons for our use case:
|
|
259
|
-
[List and explain]
|
|
260
|
-
|
|
261
|
-
STEP 3 - POSTGRESQL EVALUATION:
|
|
262
|
-
Pros for our use case:
|
|
263
|
-
[List and explain]
|
|
264
|
-
Cons for our use case:
|
|
265
|
-
[List and explain]
|
|
266
|
-
|
|
267
|
-
STEP 4 - CRITICAL REQUIREMENTS:
|
|
268
|
-
What are our non-negotiables?
|
|
269
|
-
- [Requirement 1 and why it matters]
|
|
270
|
-
- [Requirement 2 and why it matters]
|
|
271
|
-
|
|
272
|
-
STEP 5 - SCORING:
|
|
273
|
-
Rate each database against our requirements.
|
|
274
|
-
|
|
275
|
-
STEP 6 - DECISION:
|
|
276
|
-
Based on the analysis above, choose one and explain why.
|
|
277
|
-
|
|
278
|
-
STEP 7 - VALIDATE:
|
|
279
|
-
Does this decision make sense? Any red flags?
|
|
280
|
-
```
|
|
281
|
-
|
|
282
|
-
## Combining CoT with Other Frameworks
|
|
283
|
-
|
|
284
|
-
### CoT + CO-STAR
|
|
285
|
-
```
|
|
286
|
-
CONTEXT: [Situation]
|
|
287
|
-
OBJECTIVE: [Goal]
|
|
288
|
-
...
|
|
289
|
-
|
|
290
|
-
PROCESS (Chain of Thought):
|
|
291
|
-
Work through this step-by-step:
|
|
292
|
-
1. [Step 1]
|
|
293
|
-
2. [Step 2]
|
|
294
|
-
...
|
|
295
|
-
```
|
|
296
|
-
|
|
297
|
-
### CoT + RISEN
|
|
298
|
-
```
|
|
299
|
-
ROLE: [Expertise]
|
|
300
|
-
INSTRUCTIONS: Use step-by-step reasoning for each stage
|
|
301
|
-
STEPS:
|
|
302
|
-
1. [Step 1] - Think through: [reasoning points]
|
|
303
|
-
2. [Step 2] - Consider: [reasoning points]
|
|
304
|
-
...
|
|
305
|
-
```
|
|
306
|
-
|
|
307
|
-
### CoT + RISE
|
|
308
|
-
```
|
|
309
|
-
ROLE: [Analyst]
|
|
310
|
-
INPUT: [Data]
|
|
311
|
-
STEPS:
|
|
312
|
-
1. [Action] - Reasoning: [Why this step?]
|
|
313
|
-
2. [Action] - Reasoning: [What are we looking for?]
|
|
314
|
-
...
|
|
315
|
-
```
|
|
316
|
-
|
|
317
|
-
## Advanced Techniques
|
|
318
|
-
|
|
319
|
-
### Self-Consistency
|
|
320
|
-
Generate multiple reasoning paths and choose the most common answer:
|
|
321
|
-
|
|
322
|
-
```
|
|
323
|
-
Solve this problem using three different approaches:
|
|
324
|
-
|
|
325
|
-
APPROACH 1:
|
|
326
|
-
[Method 1 with step-by-step reasoning]
|
|
327
|
-
|
|
328
|
-
APPROACH 2:
|
|
329
|
-
[Method 2 with step-by-step reasoning]
|
|
330
|
-
|
|
331
|
-
APPROACH 3:
|
|
332
|
-
[Method 3 with step-by-step reasoning]
|
|
333
|
-
|
|
334
|
-
COMPARISON:
|
|
335
|
-
Which approach is most reliable and why?
|
|
336
|
-
|
|
337
|
-
FINAL ANSWER:
|
|
338
|
-
Based on the most consistent result.
|
|
339
|
-
```
|
|
340
|
-
|
|
341
|
-
### Uncertainty Quantification
|
|
342
|
-
```
|
|
343
|
-
For each step, rate your confidence:
|
|
344
|
-
1. [Step 1] - Confidence: High/Medium/Low - Because: [reason]
|
|
345
|
-
2. [Step 2] - Confidence: High/Medium/Low - Because: [reason]
|
|
346
|
-
|
|
347
|
-
If any step has low confidence, explore alternatives.
|
|
348
|
-
```
|
|
349
|
-
|
|
350
|
-
### Backward Chaining
|
|
351
|
-
```
|
|
352
|
-
Start with the desired outcome and work backwards:
|
|
353
|
-
|
|
354
|
-
GOAL: [What we want to achieve]
|
|
355
|
-
|
|
356
|
-
STEP -1: To achieve this, what must be true immediately before?
|
|
357
|
-
STEP -2: To achieve that, what must be true before it?
|
|
358
|
-
STEP -3: Keep working backwards...
|
|
359
|
-
STEP -N: What's our starting point?
|
|
360
|
-
|
|
361
|
-
Now verify the forward path makes sense.
|
|
362
|
-
```
|
|
363
|
-
|
|
364
|
-
## Common Patterns
|
|
365
|
-
|
|
366
|
-
### Mathematical Problem Solving
|
|
367
|
-
```
|
|
368
|
-
1. Understand: Restate the problem in your own words
|
|
369
|
-
2. Identify: What do we know? What do we need to find?
|
|
370
|
-
3. Plan: What formula or approach applies?
|
|
371
|
-
4. Execute: Work through the math step-by-step
|
|
372
|
-
5. Verify: Does the answer make sense? Check units, magnitude
|
|
373
|
-
```
|
|
374
|
-
|
|
375
|
-
### Logical Reasoning
|
|
376
|
-
```
|
|
377
|
-
1. Premises: State what we know to be true
|
|
378
|
-
2. Inference: What can we deduce from premises?
|
|
379
|
-
3. Test: Do our deductions hold up?
|
|
380
|
-
4. Conclusion: What can we conclude?
|
|
381
|
-
5. Verify: Are there any logical fallacies?
|
|
382
|
-
```
|
|
383
|
-
|
|
384
|
-
### Troubleshooting
|
|
385
|
-
```
|
|
386
|
-
1. Observe: What's the symptom?
|
|
387
|
-
2. Hypothesize: What could cause this?
|
|
388
|
-
3. Test: How can we test each hypothesis?
|
|
389
|
-
4. Eliminate: Rule out what doesn't fit
|
|
390
|
-
5. Identify: What's the root cause?
|
|
391
|
-
6. Solve: How do we fix it?
|
|
392
|
-
7. Verify: Did it work?
|
|
393
|
-
```
|
|
394
|
-
|
|
395
|
-
## Quality Indicators
|
|
396
|
-
|
|
397
|
-
**Good CoT reasoning shows:**
|
|
398
|
-
- ✅ Each step builds on previous ones
|
|
399
|
-
- ✅ Assumptions are stated explicitly
|
|
400
|
-
- ✅ Calculations/logic are shown
|
|
401
|
-
- ✅ Intermediate results are verified
|
|
402
|
-
- ✅ Uncertainties are acknowledged
|
|
403
|
-
- ✅ Final answer follows logically
|
|
404
|
-
|
|
405
|
-
**Poor CoT reasoning shows:**
|
|
406
|
-
- ❌ Jumping to conclusions
|
|
407
|
-
- ❌ Skipping intermediate steps
|
|
408
|
-
- ❌ Hiding assumptions
|
|
409
|
-
- ❌ No verification
|
|
410
|
-
- ❌ Unjustified leaps in logic
|
|
411
|
-
|
|
412
|
-
## Assessment Checklist
|
|
413
|
-
|
|
414
|
-
When using Chain of Thought:
|
|
415
|
-
- [ ] Problem is complex enough to warrant CoT
|
|
416
|
-
- [ ] Steps are explicitly requested
|
|
417
|
-
- [ ] Reasoning structure is provided or suggested
|
|
418
|
-
- [ ] Verification is included
|
|
419
|
-
- [ ] Self-correction is encouraged
|
|
420
|
-
- [ ] Each step is actionable
|
|
421
|
-
- [ ] Logic flow is clear
|
|
422
|
-
- [ ] Assumptions are acknowledged
|
|
423
|
-
- [ ] Final answer connects to reasoning
|
|
424
|
-
- [ ] Work shown, not just answer
|
|
1
|
+
# Chain of Thought (CoT) Framework
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
Chain of Thought is a prompting technique that encourages step-by-step reasoning and makes the thinking process explicit. Instead of jumping to answers, it guides Claude to break down complex problems, show intermediate steps, and verify logic along the way.
|
|
6
|
+
|
|
7
|
+
## Core Concept
|
|
8
|
+
|
|
9
|
+
CoT works by:
|
|
10
|
+
1. Breaking complex problems into smaller steps
|
|
11
|
+
2. Making reasoning explicit at each step
|
|
12
|
+
3. Showing work rather than just final answers
|
|
13
|
+
4. Verifying logic progressively
|
|
14
|
+
5. Enabling error detection and correction
|
|
15
|
+
|
|
16
|
+
## When to Use Chain of Thought
|
|
17
|
+
|
|
18
|
+
**Ideal for:**
|
|
19
|
+
- Mathematical problem-solving
|
|
20
|
+
- Logical reasoning tasks
|
|
21
|
+
- Complex multi-step analysis
|
|
22
|
+
- Debugging and troubleshooting
|
|
23
|
+
- Decision-making with trade-offs
|
|
24
|
+
- Tasks where "showing your work" matters
|
|
25
|
+
|
|
26
|
+
**Not needed for:**
|
|
27
|
+
- Simple lookups or facts
|
|
28
|
+
- Straightforward transformations
|
|
29
|
+
- Tasks with obvious single steps
|
|
30
|
+
- Creative writing without logic requirements
|
|
31
|
+
|
|
32
|
+
## Implementation Approaches
|
|
33
|
+
|
|
34
|
+
### Approach 1: Explicit Instruction
|
|
35
|
+
Directly instruct Claude to think step-by-step.
|
|
36
|
+
|
|
37
|
+
**Example:**
|
|
38
|
+
```
|
|
39
|
+
Solve this problem step-by-step, showing your reasoning at each stage:
|
|
40
|
+
|
|
41
|
+
A company's revenue grew 15% in Q1, decreased 8% in Q2, grew 20% in Q3, and grew 5% in Q4. If they started the year with $1M in quarterly revenue, what was their Q4 revenue?
|
|
42
|
+
|
|
43
|
+
Think through this carefully:
|
|
44
|
+
1. Calculate Q1 revenue
|
|
45
|
+
2. Calculate Q2 revenue
|
|
46
|
+
3. Calculate Q3 revenue
|
|
47
|
+
4. Calculate Q4 revenue
|
|
48
|
+
5. Verify your calculation
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Approach 2: Zero-Shot CoT
|
|
52
|
+
Use trigger phrases that activate reasoning.
|
|
53
|
+
|
|
54
|
+
**Magic phrases:**
|
|
55
|
+
- "Let's think step by step."
|
|
56
|
+
- "Let's work through this systematically."
|
|
57
|
+
- "Let's break this down."
|
|
58
|
+
- "Think carefully about this."
|
|
59
|
+
|
|
60
|
+
**Example:**
|
|
61
|
+
```
|
|
62
|
+
What's the best database choice for a real-time analytics platform handling 1M events/second with complex aggregations? Let's think step by step.
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Approach 3: Few-Shot CoT
|
|
66
|
+
Provide examples showing step-by-step reasoning.
|
|
67
|
+
|
|
68
|
+
**Example:**
|
|
69
|
+
```
|
|
70
|
+
Example 1:
|
|
71
|
+
Q: If a train travels 120 miles in 2 hours, what's its speed?
|
|
72
|
+
A: Let's break this down:
|
|
73
|
+
1. Speed = Distance / Time
|
|
74
|
+
2. Distance = 120 miles
|
|
75
|
+
3. Time = 2 hours
|
|
76
|
+
4. Speed = 120 / 2 = 60 mph
|
|
77
|
+
Therefore: 60 mph
|
|
78
|
+
|
|
79
|
+
Example 2:
|
|
80
|
+
Q: A store offers 20% off, then an additional 10% off. What's the total discount on a $100 item?
|
|
81
|
+
A: Let's work through this:
|
|
82
|
+
1. First discount: 20% of $100 = $20
|
|
83
|
+
2. Price after first discount: $100 - $20 = $80
|
|
84
|
+
3. Second discount: 10% of $80 = $8
|
|
85
|
+
4. Final price: $80 - $8 = $72
|
|
86
|
+
5. Total discount: $100 - $72 = $28
|
|
87
|
+
6. Total discount percentage: 28/100 = 28%
|
|
88
|
+
Therefore: 28% total discount (not 30%)
|
|
89
|
+
|
|
90
|
+
Now solve:
|
|
91
|
+
Q: [Your problem]
|
|
92
|
+
A: Let's break this down:
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Approach 4: Structured CoT
|
|
96
|
+
Provide a template for reasoning.
|
|
97
|
+
|
|
98
|
+
**Example:**
|
|
99
|
+
```
|
|
100
|
+
Analyze whether we should migrate to microservices using this reasoning structure:
|
|
101
|
+
|
|
102
|
+
STEP 1 - CURRENT STATE:
|
|
103
|
+
[Describe current architecture]
|
|
104
|
+
|
|
105
|
+
STEP 2 - PROBLEMS:
|
|
106
|
+
[What problems exist?]
|
|
107
|
+
|
|
108
|
+
STEP 3 - MICROSERVICES BENEFITS:
|
|
109
|
+
[How would microservices help?]
|
|
110
|
+
|
|
111
|
+
STEP 4 - MICROSERVICES COSTS:
|
|
112
|
+
[What are the downsides?]
|
|
113
|
+
|
|
114
|
+
STEP 5 - ALTERNATIVES:
|
|
115
|
+
[What else could we do?]
|
|
116
|
+
|
|
117
|
+
STEP 6 - COMPARISON:
|
|
118
|
+
[Compare options systematically]
|
|
119
|
+
|
|
120
|
+
STEP 7 - RECOMMENDATION:
|
|
121
|
+
[Final decision with reasoning]
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## Best Practices
|
|
125
|
+
|
|
126
|
+
### 1. Be Explicit About Steps
|
|
127
|
+
```
|
|
128
|
+
Good:
|
|
129
|
+
"Calculate the ROI step by step:
|
|
130
|
+
1. Calculate total costs
|
|
131
|
+
2. Calculate total revenue
|
|
132
|
+
3. Calculate profit (revenue - costs)
|
|
133
|
+
4. Calculate ROI (profit / costs * 100)
|
|
134
|
+
5. Interpret the result"
|
|
135
|
+
|
|
136
|
+
Poor:
|
|
137
|
+
"Calculate the ROI"
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### 2. Request Verification
|
|
141
|
+
```
|
|
142
|
+
Good:
|
|
143
|
+
"After solving, verify your answer makes sense and check your math."
|
|
144
|
+
|
|
145
|
+
Poor:
|
|
146
|
+
[No verification step]
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### 3. Encourage Self-Correction
|
|
150
|
+
```
|
|
151
|
+
Good:
|
|
152
|
+
"If you find an error in your reasoning, acknowledge it and correct your approach."
|
|
153
|
+
|
|
154
|
+
Poor:
|
|
155
|
+
[No mention of error handling]
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### 4. Ask for Uncertainty Acknowledgment
|
|
159
|
+
```
|
|
160
|
+
Good:
|
|
161
|
+
"If you're uncertain at any step, state your assumptions and why you made them."
|
|
162
|
+
|
|
163
|
+
Poor:
|
|
164
|
+
[Assumes certainty at all steps]
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## Complete Examples
|
|
168
|
+
|
|
169
|
+
### Example 1: Debugging
|
|
170
|
+
|
|
171
|
+
**Without CoT:**
|
|
172
|
+
```
|
|
173
|
+
Why isn't this code working?
|
|
174
|
+
[code snippet]
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
**With CoT:**
|
|
178
|
+
```
|
|
179
|
+
Debug this code by thinking through it step-by-step:
|
|
180
|
+
|
|
181
|
+
[code snippet]
|
|
182
|
+
|
|
183
|
+
Use this process:
|
|
184
|
+
1. Read the code and state what it's supposed to do
|
|
185
|
+
2. Identify the input and expected output
|
|
186
|
+
3. Trace through execution line by line
|
|
187
|
+
4. Note any suspicious patterns or red flags
|
|
188
|
+
5. Form hypotheses about the bug
|
|
189
|
+
6. Test each hypothesis against the code
|
|
190
|
+
7. Identify the root cause
|
|
191
|
+
8. Propose a fix
|
|
192
|
+
9. Verify the fix addresses the issue
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### Example 2: System Design
|
|
196
|
+
|
|
197
|
+
**Without CoT:**
|
|
198
|
+
```
|
|
199
|
+
Design a URL shortener.
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
**With CoT:**
|
|
203
|
+
```
|
|
204
|
+
Design a URL shortener by working through these steps:
|
|
205
|
+
|
|
206
|
+
STEP 1 - REQUIREMENTS:
|
|
207
|
+
Think through what the system needs to do.
|
|
208
|
+
- Functional requirements?
|
|
209
|
+
- Non-functional requirements?
|
|
210
|
+
- Scale expectations?
|
|
211
|
+
|
|
212
|
+
STEP 2 - API DESIGN:
|
|
213
|
+
What endpoints do we need?
|
|
214
|
+
- Consider: creation, retrieval, analytics
|
|
215
|
+
|
|
216
|
+
STEP 3 - DATA MODEL:
|
|
217
|
+
How should we store URLs?
|
|
218
|
+
- What fields are needed?
|
|
219
|
+
- What indexes?
|
|
220
|
+
|
|
221
|
+
STEP 4 - URL GENERATION:
|
|
222
|
+
How do we create short codes?
|
|
223
|
+
- Base62 encoding? Hash? Counter?
|
|
224
|
+
- Collision handling?
|
|
225
|
+
|
|
226
|
+
STEP 5 - SCALABILITY:
|
|
227
|
+
How does this scale?
|
|
228
|
+
- Bottlenecks?
|
|
229
|
+
- Caching strategy?
|
|
230
|
+
- Database sharding?
|
|
231
|
+
|
|
232
|
+
STEP 6 - TRADE-OFFS:
|
|
233
|
+
What are we optimizing for vs. sacrificing?
|
|
234
|
+
|
|
235
|
+
For each step, explain your reasoning.
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
### Example 3: Decision Making
|
|
239
|
+
|
|
240
|
+
**Without CoT:**
|
|
241
|
+
```
|
|
242
|
+
Should we use MongoDB or PostgreSQL?
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
**With CoT:**
|
|
246
|
+
```
|
|
247
|
+
Decide between MongoDB and PostgreSQL by reasoning through:
|
|
248
|
+
|
|
249
|
+
STEP 1 - USE CASE ANALYSIS:
|
|
250
|
+
What are we building and what data patterns will we have?
|
|
251
|
+
- Data structure (structured/unstructured?)
|
|
252
|
+
- Relationships (complex/simple?)
|
|
253
|
+
- Query patterns (known/unknown?)
|
|
254
|
+
|
|
255
|
+
STEP 2 - MONGODB EVALUATION:
|
|
256
|
+
Pros for our use case:
|
|
257
|
+
[List and explain]
|
|
258
|
+
Cons for our use case:
|
|
259
|
+
[List and explain]
|
|
260
|
+
|
|
261
|
+
STEP 3 - POSTGRESQL EVALUATION:
|
|
262
|
+
Pros for our use case:
|
|
263
|
+
[List and explain]
|
|
264
|
+
Cons for our use case:
|
|
265
|
+
[List and explain]
|
|
266
|
+
|
|
267
|
+
STEP 4 - CRITICAL REQUIREMENTS:
|
|
268
|
+
What are our non-negotiables?
|
|
269
|
+
- [Requirement 1 and why it matters]
|
|
270
|
+
- [Requirement 2 and why it matters]
|
|
271
|
+
|
|
272
|
+
STEP 5 - SCORING:
|
|
273
|
+
Rate each database against our requirements.
|
|
274
|
+
|
|
275
|
+
STEP 6 - DECISION:
|
|
276
|
+
Based on the analysis above, choose one and explain why.
|
|
277
|
+
|
|
278
|
+
STEP 7 - VALIDATE:
|
|
279
|
+
Does this decision make sense? Any red flags?
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
## Combining CoT with Other Frameworks
|
|
283
|
+
|
|
284
|
+
### CoT + CO-STAR
|
|
285
|
+
```
|
|
286
|
+
CONTEXT: [Situation]
|
|
287
|
+
OBJECTIVE: [Goal]
|
|
288
|
+
...
|
|
289
|
+
|
|
290
|
+
PROCESS (Chain of Thought):
|
|
291
|
+
Work through this step-by-step:
|
|
292
|
+
1. [Step 1]
|
|
293
|
+
2. [Step 2]
|
|
294
|
+
...
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
### CoT + RISEN
|
|
298
|
+
```
|
|
299
|
+
ROLE: [Expertise]
|
|
300
|
+
INSTRUCTIONS: Use step-by-step reasoning for each stage
|
|
301
|
+
STEPS:
|
|
302
|
+
1. [Step 1] - Think through: [reasoning points]
|
|
303
|
+
2. [Step 2] - Consider: [reasoning points]
|
|
304
|
+
...
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
### CoT + RISE
|
|
308
|
+
```
|
|
309
|
+
ROLE: [Analyst]
|
|
310
|
+
INPUT: [Data]
|
|
311
|
+
STEPS:
|
|
312
|
+
1. [Action] - Reasoning: [Why this step?]
|
|
313
|
+
2. [Action] - Reasoning: [What are we looking for?]
|
|
314
|
+
...
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
## Advanced Techniques
|
|
318
|
+
|
|
319
|
+
### Self-Consistency
|
|
320
|
+
Generate multiple reasoning paths and choose the most common answer:
|
|
321
|
+
|
|
322
|
+
```
|
|
323
|
+
Solve this problem using three different approaches:
|
|
324
|
+
|
|
325
|
+
APPROACH 1:
|
|
326
|
+
[Method 1 with step-by-step reasoning]
|
|
327
|
+
|
|
328
|
+
APPROACH 2:
|
|
329
|
+
[Method 2 with step-by-step reasoning]
|
|
330
|
+
|
|
331
|
+
APPROACH 3:
|
|
332
|
+
[Method 3 with step-by-step reasoning]
|
|
333
|
+
|
|
334
|
+
COMPARISON:
|
|
335
|
+
Which approach is most reliable and why?
|
|
336
|
+
|
|
337
|
+
FINAL ANSWER:
|
|
338
|
+
Based on the most consistent result.
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
### Uncertainty Quantification
|
|
342
|
+
```
|
|
343
|
+
For each step, rate your confidence:
|
|
344
|
+
1. [Step 1] - Confidence: High/Medium/Low - Because: [reason]
|
|
345
|
+
2. [Step 2] - Confidence: High/Medium/Low - Because: [reason]
|
|
346
|
+
|
|
347
|
+
If any step has low confidence, explore alternatives.
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
### Backward Chaining
|
|
351
|
+
```
|
|
352
|
+
Start with the desired outcome and work backwards:
|
|
353
|
+
|
|
354
|
+
GOAL: [What we want to achieve]
|
|
355
|
+
|
|
356
|
+
STEP -1: To achieve this, what must be true immediately before?
|
|
357
|
+
STEP -2: To achieve that, what must be true before it?
|
|
358
|
+
STEP -3: Keep working backwards...
|
|
359
|
+
STEP -N: What's our starting point?
|
|
360
|
+
|
|
361
|
+
Now verify the forward path makes sense.
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
## Common Patterns
|
|
365
|
+
|
|
366
|
+
### Mathematical Problem Solving
|
|
367
|
+
```
|
|
368
|
+
1. Understand: Restate the problem in your own words
|
|
369
|
+
2. Identify: What do we know? What do we need to find?
|
|
370
|
+
3. Plan: What formula or approach applies?
|
|
371
|
+
4. Execute: Work through the math step-by-step
|
|
372
|
+
5. Verify: Does the answer make sense? Check units, magnitude
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
### Logical Reasoning
|
|
376
|
+
```
|
|
377
|
+
1. Premises: State what we know to be true
|
|
378
|
+
2. Inference: What can we deduce from premises?
|
|
379
|
+
3. Test: Do our deductions hold up?
|
|
380
|
+
4. Conclusion: What can we conclude?
|
|
381
|
+
5. Verify: Are there any logical fallacies?
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
### Troubleshooting
|
|
385
|
+
```
|
|
386
|
+
1. Observe: What's the symptom?
|
|
387
|
+
2. Hypothesize: What could cause this?
|
|
388
|
+
3. Test: How can we test each hypothesis?
|
|
389
|
+
4. Eliminate: Rule out what doesn't fit
|
|
390
|
+
5. Identify: What's the root cause?
|
|
391
|
+
6. Solve: How do we fix it?
|
|
392
|
+
7. Verify: Did it work?
|
|
393
|
+
```
|
|
394
|
+
|
|
395
|
+
## Quality Indicators
|
|
396
|
+
|
|
397
|
+
**Good CoT reasoning shows:**
|
|
398
|
+
- ✅ Each step builds on previous ones
|
|
399
|
+
- ✅ Assumptions are stated explicitly
|
|
400
|
+
- ✅ Calculations/logic are shown
|
|
401
|
+
- ✅ Intermediate results are verified
|
|
402
|
+
- ✅ Uncertainties are acknowledged
|
|
403
|
+
- ✅ Final answer follows logically
|
|
404
|
+
|
|
405
|
+
**Poor CoT reasoning shows:**
|
|
406
|
+
- ❌ Jumping to conclusions
|
|
407
|
+
- ❌ Skipping intermediate steps
|
|
408
|
+
- ❌ Hiding assumptions
|
|
409
|
+
- ❌ No verification
|
|
410
|
+
- ❌ Unjustified leaps in logic
|
|
411
|
+
|
|
412
|
+
## Assessment Checklist
|
|
413
|
+
|
|
414
|
+
When using Chain of Thought:
|
|
415
|
+
- [ ] Problem is complex enough to warrant CoT
|
|
416
|
+
- [ ] Steps are explicitly requested
|
|
417
|
+
- [ ] Reasoning structure is provided or suggested
|
|
418
|
+
- [ ] Verification is included
|
|
419
|
+
- [ ] Self-correction is encouraged
|
|
420
|
+
- [ ] Each step is actionable
|
|
421
|
+
- [ ] Logic flow is clear
|
|
422
|
+
- [ ] Assumptions are acknowledged
|
|
423
|
+
- [ ] Final answer connects to reasoning
|
|
424
|
+
- [ ] Work shown, not just answer
|