@ckelsoe/prompt-architect 3.0.2 → 3.2.0
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 +343 -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,304 +1,304 @@
|
|
|
1
|
-
# ReAct Framework
|
|
2
|
-
|
|
3
|
-
## Overview
|
|
4
|
-
|
|
5
|
-
ReAct (Reasoning + Acting) is an agentic prompting framework that interleaves reasoning steps with concrete actions. Rather than reasoning once and then acting, ReAct prompts the model to alternate between: thinking about what to do next (Thought), taking a specific action (Action), and observing the result (Observation) — in a cycle until the goal is reached.
|
|
6
|
-
|
|
7
|
-
ReAct is the framework of choice when the task requires using tools, querying external sources, writing and executing code, or navigating a multi-step process where each step's result informs the next.
|
|
8
|
-
|
|
9
|
-
**Research basis:** Introduced in "ReAct: Synergizing Reasoning and Acting in Language Models" (Yao et al., 2022).
|
|
10
|
-
|
|
11
|
-
## Components
|
|
12
|
-
|
|
13
|
-
### Goal
|
|
14
|
-
**Purpose:** Define what needs to be achieved — the end state the agent should reach.
|
|
15
|
-
|
|
16
|
-
### Tools / Resources Available
|
|
17
|
-
**Purpose:** List what the agent can use to accomplish the goal. This tells the model what actions are possible.
|
|
18
|
-
|
|
19
|
-
**Common tool types:**
|
|
20
|
-
- Search / web lookup
|
|
21
|
-
- Code execution
|
|
22
|
-
- File read/write
|
|
23
|
-
- API calls
|
|
24
|
-
- Calculator / computation
|
|
25
|
-
- Database queries
|
|
26
|
-
|
|
27
|
-
### ReAct Cycle
|
|
28
|
-
**Purpose:** The repeating Thought → Action → Observation loop.
|
|
29
|
-
|
|
30
|
-
- **Thought:** Reason about the current state and what to do next
|
|
31
|
-
- **Action:** Take a specific, concrete action using an available tool
|
|
32
|
-
- **Observation:** Record the result of the action
|
|
33
|
-
- *(Repeat until goal is reached)*
|
|
34
|
-
|
|
35
|
-
### Final Answer
|
|
36
|
-
**Purpose:** Once the goal is achieved, provide the answer or deliverable.
|
|
37
|
-
|
|
38
|
-
## Template Structure
|
|
39
|
-
|
|
40
|
-
```
|
|
41
|
-
GOAL:
|
|
42
|
-
[What needs to be achieved — the end state]
|
|
43
|
-
|
|
44
|
-
AVAILABLE TOOLS:
|
|
45
|
-
- [Tool 1]: [What it does]
|
|
46
|
-
- [Tool 2]: [What it does]
|
|
47
|
-
- [Tool 3]: [What it does]
|
|
48
|
-
|
|
49
|
-
CONSTRAINTS:
|
|
50
|
-
- [Any rules, limits, or guardrails on actions]
|
|
51
|
-
|
|
52
|
-
APPROACH:
|
|
53
|
-
Use the Thought → Action → Observation cycle:
|
|
54
|
-
|
|
55
|
-
Thought: [Reason about current state and next step]
|
|
56
|
-
Action: [Tool name] — [specific query or operation]
|
|
57
|
-
Observation: [Result of the action]
|
|
58
|
-
|
|
59
|
-
Thought: [Reason about observation and what to do next]
|
|
60
|
-
Action: [Tool name] — [next operation]
|
|
61
|
-
Observation: [Result]
|
|
62
|
-
|
|
63
|
-
[Continue until goal is reached]
|
|
64
|
-
|
|
65
|
-
Final Answer: [Deliver the result]
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
## Complete Examples
|
|
69
|
-
|
|
70
|
-
### Example 1: Research Task (Agentic)
|
|
71
|
-
|
|
72
|
-
**Before ReAct:**
|
|
73
|
-
"Find out which JavaScript framework is most popular right now."
|
|
74
|
-
|
|
75
|
-
**After ReAct:**
|
|
76
|
-
```
|
|
77
|
-
GOAL:
|
|
78
|
-
Determine which JavaScript frontend framework has the highest current adoption
|
|
79
|
-
and provide a brief evidence-based recommendation for a new project.
|
|
80
|
-
|
|
81
|
-
AVAILABLE TOOLS:
|
|
82
|
-
- web_search: Search for current information
|
|
83
|
-
- fetch_page: Retrieve content from a specific URL
|
|
84
|
-
|
|
85
|
-
CONSTRAINTS:
|
|
86
|
-
- Use at least 2 independent sources
|
|
87
|
-
- Prioritize data from the last 12 months
|
|
88
|
-
- Do not rely on a single survey
|
|
89
|
-
|
|
90
|
-
APPROACH:
|
|
91
|
-
Thought: I need current data on JS framework popularity. I'll start with
|
|
92
|
-
the Stack Overflow Developer Survey and npm download stats.
|
|
93
|
-
|
|
94
|
-
Action: web_search — "JavaScript framework popularity 2024 Stack Overflow survey"
|
|
95
|
-
Observation: [Search results]
|
|
96
|
-
|
|
97
|
-
Thought: Found Stack Overflow survey data. Let me also check npm trends for
|
|
98
|
-
download numbers to corroborate.
|
|
99
|
-
|
|
100
|
-
Action: web_search — "React vs Vue vs Angular npm downloads 2024"
|
|
101
|
-
Observation: [Search results]
|
|
102
|
-
|
|
103
|
-
Thought: I have data from two sources. Let me synthesize the findings.
|
|
104
|
-
|
|
105
|
-
Final Answer: Based on [sources], React leads in adoption at X%, followed by...
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
### Example 2: Debugging with Tool Use
|
|
109
|
-
|
|
110
|
-
**Before ReAct:**
|
|
111
|
-
"Debug why the tests are failing."
|
|
112
|
-
|
|
113
|
-
**After ReAct:**
|
|
114
|
-
```
|
|
115
|
-
GOAL:
|
|
116
|
-
Identify and fix the root cause of the failing unit tests in the auth module.
|
|
117
|
-
All 3 tests in auth.test.js are failing after the refactor.
|
|
118
|
-
|
|
119
|
-
AVAILABLE TOOLS:
|
|
120
|
-
- read_file: Read any file in the codebase
|
|
121
|
-
- run_tests: Execute test suite and return output
|
|
122
|
-
- search_code: Search codebase for patterns
|
|
123
|
-
|
|
124
|
-
CONSTRAINTS:
|
|
125
|
-
- Fix the root cause, not the symptoms
|
|
126
|
-
- Do not change test code unless tests themselves are wrong
|
|
127
|
-
- Verify fix by running tests again after changes
|
|
128
|
-
|
|
129
|
-
APPROACH:
|
|
130
|
-
Thought: I need to understand what the tests expect before I look at the implementation.
|
|
131
|
-
|
|
132
|
-
Action: read_file — auth.test.js
|
|
133
|
-
Observation: [File contents]
|
|
134
|
-
|
|
135
|
-
Thought: Tests are calling `auth.validateToken(token)` but based on the refactor
|
|
136
|
-
PR description, the function was renamed. Let me check the new implementation.
|
|
137
|
-
|
|
138
|
-
Action: read_file — auth.js
|
|
139
|
-
Observation: [File contents]
|
|
140
|
-
|
|
141
|
-
Thought: Confirmed — function was renamed to `auth.verifyToken()`. Tests use old name.
|
|
142
|
-
Let me check if this was an intentional API change or a mistake.
|
|
143
|
-
|
|
144
|
-
Action: search_code — "validateToken"
|
|
145
|
-
Observation: [All usages across codebase]
|
|
146
|
-
|
|
147
|
-
Thought: validateToken is used in 3 other places too. This is a breaking rename.
|
|
148
|
-
The tests are correct — the implementation changed names without updating callers.
|
|
149
|
-
I'll restore the original name in the implementation and add an alias if needed.
|
|
150
|
-
|
|
151
|
-
[Apply fix]
|
|
152
|
-
|
|
153
|
-
Action: run_tests — auth.test.js
|
|
154
|
-
Observation: All 3 tests passing.
|
|
155
|
-
|
|
156
|
-
Final Answer: Root cause was function rename in auth.js that broke all callers.
|
|
157
|
-
Restored original function name and added `verifyToken` as an alias for forward
|
|
158
|
-
compatibility.
|
|
159
|
-
```
|
|
160
|
-
|
|
161
|
-
### Example 3: Data Investigation
|
|
162
|
-
|
|
163
|
-
**Before ReAct:**
|
|
164
|
-
"Why are sales down this month?"
|
|
165
|
-
|
|
166
|
-
**After ReAct:**
|
|
167
|
-
```
|
|
168
|
-
GOAL:
|
|
169
|
-
Identify the primary factor(s) driving the 23% month-over-month decline in
|
|
170
|
-
sales this quarter. Provide a ranked list of likely causes with supporting data.
|
|
171
|
-
|
|
172
|
-
AVAILABLE TOOLS:
|
|
173
|
-
- query_database: Run SQL queries against the sales database
|
|
174
|
-
- fetch_analytics: Pull data from the analytics dashboard
|
|
175
|
-
- read_file: Read exported reports and CSV files
|
|
176
|
-
|
|
177
|
-
CONSTRAINTS:
|
|
178
|
-
- Base conclusions on data, not assumptions
|
|
179
|
-
- Consider at least 3 potential causes before concluding
|
|
180
|
-
- If data is insufficient to conclude, state what additional data is needed
|
|
181
|
-
|
|
182
|
-
APPROACH:
|
|
183
|
-
Thought: 23% decline is significant. I should check whether it's volume (fewer
|
|
184
|
-
orders), value (smaller orders), or both. Also check if it's across all segments
|
|
185
|
-
or concentrated.
|
|
186
|
-
|
|
187
|
-
Action: query_database — "SELECT COUNT(*), AVG(order_value), segment FROM orders
|
|
188
|
-
WHERE month = current AND month = previous GROUP BY segment"
|
|
189
|
-
Observation: [Query results]
|
|
190
|
-
|
|
191
|
-
Thought: Volume is down 18% but average order value is down only 5%. The decline
|
|
192
|
-
is concentrated in the Enterprise segment. Let me check acquisition vs. churn.
|
|
193
|
-
|
|
194
|
-
Action: query_database — "SELECT new_customers, churned_customers, segment FROM
|
|
195
|
-
customer_events WHERE period = last_30_days"
|
|
196
|
-
Observation: [Query results]
|
|
197
|
-
|
|
198
|
-
Thought: Enterprise churn is 3x normal. Let me check if there's a product or
|
|
199
|
-
pricing event that coincides.
|
|
200
|
-
|
|
201
|
-
[Continue investigation...]
|
|
202
|
-
|
|
203
|
-
Final Answer: Primary driver is Enterprise churn (elevated 3x), concentrated
|
|
204
|
-
in accounts that received the new pricing email on [date]. Secondary factor is
|
|
205
|
-
reduced trial-to-paid conversion, down 12%.
|
|
206
|
-
```
|
|
207
|
-
|
|
208
|
-
## Best Use Cases
|
|
209
|
-
|
|
210
|
-
1. **Agentic / Tool-Use Tasks**
|
|
211
|
-
- Tasks where the model needs to use tools iteratively
|
|
212
|
-
- Research with multiple lookups
|
|
213
|
-
- Debugging with read-test-fix cycles
|
|
214
|
-
|
|
215
|
-
2. **Multi-Step Investigation**
|
|
216
|
-
- Data investigation where each finding informs the next query
|
|
217
|
-
- Root cause analysis
|
|
218
|
-
- Audit tasks
|
|
219
|
-
|
|
220
|
-
3. **Autonomous Task Execution**
|
|
221
|
-
- Tasks that should complete without human intervention per step
|
|
222
|
-
- Workflows that use Claude Code's tool ecosystem
|
|
223
|
-
|
|
224
|
-
4. **When the Path Is Unknown**
|
|
225
|
-
- Tasks where you can't specify every step upfront
|
|
226
|
-
- Exploratory analysis
|
|
227
|
-
- Open-ended problem-solving with tools
|
|
228
|
-
|
|
229
|
-
## Selection Criteria
|
|
230
|
-
|
|
231
|
-
**Choose ReAct when:**
|
|
232
|
-
- ✅ Tools or external resources will be used
|
|
233
|
-
- ✅ Each step's result determines the next step
|
|
234
|
-
- ✅ The path to solution is not fully known upfront
|
|
235
|
-
- ✅ Reasoning should be shown alongside actions
|
|
236
|
-
- ✅ Task is agentic in nature
|
|
237
|
-
|
|
238
|
-
**Avoid ReAct when:**
|
|
239
|
-
- ❌ Task has a fixed, known sequence of steps → use RISEN
|
|
240
|
-
- ❌ No tools needed, just reasoning → use Chain of Thought
|
|
241
|
-
- ❌ Creative or writing task → use CO-STAR or BAB
|
|
242
|
-
- ❌ Simple, well-defined → use RTF, APE, or CTF
|
|
243
|
-
|
|
244
|
-
## ReAct vs. Chain of Thought vs. RISEN
|
|
245
|
-
|
|
246
|
-
| | Chain of Thought | RISEN | ReAct |
|
|
247
|
-
|---|---|---|---|
|
|
248
|
-
| Structure | Linear reasoning steps | Defined methodology | Thought-Action-Observation cycles |
|
|
249
|
-
| Tool use | No | No | Yes |
|
|
250
|
-
| Path known upfront? | Yes | Yes | No (emergent) |
|
|
251
|
-
| Best for | Complex reasoning | Multi-step procedures | Agentic tool use |
|
|
252
|
-
|
|
253
|
-
## Writing Good ReAct Prompts
|
|
254
|
-
|
|
255
|
-
### Goals Should Be Outcome-Focused
|
|
256
|
-
```
|
|
257
|
-
✅ "Identify the root cause of the auth failures and produce a fix"
|
|
258
|
-
❌ "Look at the auth code"
|
|
259
|
-
```
|
|
260
|
-
|
|
261
|
-
### Tools Should Be Named and Described
|
|
262
|
-
```
|
|
263
|
-
✅ - run_tests: Execute the test suite and return pass/fail results with error output
|
|
264
|
-
❌ - testing tool
|
|
265
|
-
```
|
|
266
|
-
|
|
267
|
-
### Constraints Prevent Loops
|
|
268
|
-
```
|
|
269
|
-
✅ "If you cannot confirm a hypothesis after 3 tool calls, state it as unconfirmed and move on"
|
|
270
|
-
❌ (no constraints — model may loop indefinitely)
|
|
271
|
-
```
|
|
272
|
-
|
|
273
|
-
### Include a Stop Condition
|
|
274
|
-
```
|
|
275
|
-
✅ "Stop when: the fix is confirmed by passing tests OR you've determined the fix requires information not available to you"
|
|
276
|
-
```
|
|
277
|
-
|
|
278
|
-
## Common Mistakes
|
|
279
|
-
|
|
280
|
-
1. **Specifying Every Step**
|
|
281
|
-
- If you know all the steps, use RISEN instead
|
|
282
|
-
- ReAct is for when the path is emergent
|
|
283
|
-
|
|
284
|
-
2. **No Tool List**
|
|
285
|
-
- Without knowing what tools are available, the model invents them
|
|
286
|
-
- Always list available tools explicitly
|
|
287
|
-
|
|
288
|
-
3. **No Constraints**
|
|
289
|
-
- Unconstrained ReAct can loop or over-explore
|
|
290
|
-
- Add max iterations or a stop condition
|
|
291
|
-
|
|
292
|
-
4. **Using ReAct for Static Tasks**
|
|
293
|
-
- If no tools are needed, Chain of Thought is simpler and more effective
|
|
294
|
-
|
|
295
|
-
## Quick Reference
|
|
296
|
-
|
|
297
|
-
| Component | Focus | Key Question |
|
|
298
|
-
|-----------|-------|--------------|
|
|
299
|
-
| Goal | End state | "What does success look like?" |
|
|
300
|
-
| Tools | Available actions | "What can the agent do?" |
|
|
301
|
-
| Thought | Reasoning | "What should I do next and why?" |
|
|
302
|
-
| Action | Tool use | "What specific action to take?" |
|
|
303
|
-
| Observation | Result | "What happened?" |
|
|
304
|
-
| Final Answer | Deliverable | "Goal achieved — what's the answer?" |
|
|
1
|
+
# ReAct Framework
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
ReAct (Reasoning + Acting) is an agentic prompting framework that interleaves reasoning steps with concrete actions. Rather than reasoning once and then acting, ReAct prompts the model to alternate between: thinking about what to do next (Thought), taking a specific action (Action), and observing the result (Observation) — in a cycle until the goal is reached.
|
|
6
|
+
|
|
7
|
+
ReAct is the framework of choice when the task requires using tools, querying external sources, writing and executing code, or navigating a multi-step process where each step's result informs the next.
|
|
8
|
+
|
|
9
|
+
**Research basis:** Introduced in "ReAct: Synergizing Reasoning and Acting in Language Models" (Yao et al., 2022).
|
|
10
|
+
|
|
11
|
+
## Components
|
|
12
|
+
|
|
13
|
+
### Goal
|
|
14
|
+
**Purpose:** Define what needs to be achieved — the end state the agent should reach.
|
|
15
|
+
|
|
16
|
+
### Tools / Resources Available
|
|
17
|
+
**Purpose:** List what the agent can use to accomplish the goal. This tells the model what actions are possible.
|
|
18
|
+
|
|
19
|
+
**Common tool types:**
|
|
20
|
+
- Search / web lookup
|
|
21
|
+
- Code execution
|
|
22
|
+
- File read/write
|
|
23
|
+
- API calls
|
|
24
|
+
- Calculator / computation
|
|
25
|
+
- Database queries
|
|
26
|
+
|
|
27
|
+
### ReAct Cycle
|
|
28
|
+
**Purpose:** The repeating Thought → Action → Observation loop.
|
|
29
|
+
|
|
30
|
+
- **Thought:** Reason about the current state and what to do next
|
|
31
|
+
- **Action:** Take a specific, concrete action using an available tool
|
|
32
|
+
- **Observation:** Record the result of the action
|
|
33
|
+
- *(Repeat until goal is reached)*
|
|
34
|
+
|
|
35
|
+
### Final Answer
|
|
36
|
+
**Purpose:** Once the goal is achieved, provide the answer or deliverable.
|
|
37
|
+
|
|
38
|
+
## Template Structure
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
GOAL:
|
|
42
|
+
[What needs to be achieved — the end state]
|
|
43
|
+
|
|
44
|
+
AVAILABLE TOOLS:
|
|
45
|
+
- [Tool 1]: [What it does]
|
|
46
|
+
- [Tool 2]: [What it does]
|
|
47
|
+
- [Tool 3]: [What it does]
|
|
48
|
+
|
|
49
|
+
CONSTRAINTS:
|
|
50
|
+
- [Any rules, limits, or guardrails on actions]
|
|
51
|
+
|
|
52
|
+
APPROACH:
|
|
53
|
+
Use the Thought → Action → Observation cycle:
|
|
54
|
+
|
|
55
|
+
Thought: [Reason about current state and next step]
|
|
56
|
+
Action: [Tool name] — [specific query or operation]
|
|
57
|
+
Observation: [Result of the action]
|
|
58
|
+
|
|
59
|
+
Thought: [Reason about observation and what to do next]
|
|
60
|
+
Action: [Tool name] — [next operation]
|
|
61
|
+
Observation: [Result]
|
|
62
|
+
|
|
63
|
+
[Continue until goal is reached]
|
|
64
|
+
|
|
65
|
+
Final Answer: [Deliver the result]
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Complete Examples
|
|
69
|
+
|
|
70
|
+
### Example 1: Research Task (Agentic)
|
|
71
|
+
|
|
72
|
+
**Before ReAct:**
|
|
73
|
+
"Find out which JavaScript framework is most popular right now."
|
|
74
|
+
|
|
75
|
+
**After ReAct:**
|
|
76
|
+
```
|
|
77
|
+
GOAL:
|
|
78
|
+
Determine which JavaScript frontend framework has the highest current adoption
|
|
79
|
+
and provide a brief evidence-based recommendation for a new project.
|
|
80
|
+
|
|
81
|
+
AVAILABLE TOOLS:
|
|
82
|
+
- web_search: Search for current information
|
|
83
|
+
- fetch_page: Retrieve content from a specific URL
|
|
84
|
+
|
|
85
|
+
CONSTRAINTS:
|
|
86
|
+
- Use at least 2 independent sources
|
|
87
|
+
- Prioritize data from the last 12 months
|
|
88
|
+
- Do not rely on a single survey
|
|
89
|
+
|
|
90
|
+
APPROACH:
|
|
91
|
+
Thought: I need current data on JS framework popularity. I'll start with
|
|
92
|
+
the Stack Overflow Developer Survey and npm download stats.
|
|
93
|
+
|
|
94
|
+
Action: web_search — "JavaScript framework popularity 2024 Stack Overflow survey"
|
|
95
|
+
Observation: [Search results]
|
|
96
|
+
|
|
97
|
+
Thought: Found Stack Overflow survey data. Let me also check npm trends for
|
|
98
|
+
download numbers to corroborate.
|
|
99
|
+
|
|
100
|
+
Action: web_search — "React vs Vue vs Angular npm downloads 2024"
|
|
101
|
+
Observation: [Search results]
|
|
102
|
+
|
|
103
|
+
Thought: I have data from two sources. Let me synthesize the findings.
|
|
104
|
+
|
|
105
|
+
Final Answer: Based on [sources], React leads in adoption at X%, followed by...
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Example 2: Debugging with Tool Use
|
|
109
|
+
|
|
110
|
+
**Before ReAct:**
|
|
111
|
+
"Debug why the tests are failing."
|
|
112
|
+
|
|
113
|
+
**After ReAct:**
|
|
114
|
+
```
|
|
115
|
+
GOAL:
|
|
116
|
+
Identify and fix the root cause of the failing unit tests in the auth module.
|
|
117
|
+
All 3 tests in auth.test.js are failing after the refactor.
|
|
118
|
+
|
|
119
|
+
AVAILABLE TOOLS:
|
|
120
|
+
- read_file: Read any file in the codebase
|
|
121
|
+
- run_tests: Execute test suite and return output
|
|
122
|
+
- search_code: Search codebase for patterns
|
|
123
|
+
|
|
124
|
+
CONSTRAINTS:
|
|
125
|
+
- Fix the root cause, not the symptoms
|
|
126
|
+
- Do not change test code unless tests themselves are wrong
|
|
127
|
+
- Verify fix by running tests again after changes
|
|
128
|
+
|
|
129
|
+
APPROACH:
|
|
130
|
+
Thought: I need to understand what the tests expect before I look at the implementation.
|
|
131
|
+
|
|
132
|
+
Action: read_file — auth.test.js
|
|
133
|
+
Observation: [File contents]
|
|
134
|
+
|
|
135
|
+
Thought: Tests are calling `auth.validateToken(token)` but based on the refactor
|
|
136
|
+
PR description, the function was renamed. Let me check the new implementation.
|
|
137
|
+
|
|
138
|
+
Action: read_file — auth.js
|
|
139
|
+
Observation: [File contents]
|
|
140
|
+
|
|
141
|
+
Thought: Confirmed — function was renamed to `auth.verifyToken()`. Tests use old name.
|
|
142
|
+
Let me check if this was an intentional API change or a mistake.
|
|
143
|
+
|
|
144
|
+
Action: search_code — "validateToken"
|
|
145
|
+
Observation: [All usages across codebase]
|
|
146
|
+
|
|
147
|
+
Thought: validateToken is used in 3 other places too. This is a breaking rename.
|
|
148
|
+
The tests are correct — the implementation changed names without updating callers.
|
|
149
|
+
I'll restore the original name in the implementation and add an alias if needed.
|
|
150
|
+
|
|
151
|
+
[Apply fix]
|
|
152
|
+
|
|
153
|
+
Action: run_tests — auth.test.js
|
|
154
|
+
Observation: All 3 tests passing.
|
|
155
|
+
|
|
156
|
+
Final Answer: Root cause was function rename in auth.js that broke all callers.
|
|
157
|
+
Restored original function name and added `verifyToken` as an alias for forward
|
|
158
|
+
compatibility.
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### Example 3: Data Investigation
|
|
162
|
+
|
|
163
|
+
**Before ReAct:**
|
|
164
|
+
"Why are sales down this month?"
|
|
165
|
+
|
|
166
|
+
**After ReAct:**
|
|
167
|
+
```
|
|
168
|
+
GOAL:
|
|
169
|
+
Identify the primary factor(s) driving the 23% month-over-month decline in
|
|
170
|
+
sales this quarter. Provide a ranked list of likely causes with supporting data.
|
|
171
|
+
|
|
172
|
+
AVAILABLE TOOLS:
|
|
173
|
+
- query_database: Run SQL queries against the sales database
|
|
174
|
+
- fetch_analytics: Pull data from the analytics dashboard
|
|
175
|
+
- read_file: Read exported reports and CSV files
|
|
176
|
+
|
|
177
|
+
CONSTRAINTS:
|
|
178
|
+
- Base conclusions on data, not assumptions
|
|
179
|
+
- Consider at least 3 potential causes before concluding
|
|
180
|
+
- If data is insufficient to conclude, state what additional data is needed
|
|
181
|
+
|
|
182
|
+
APPROACH:
|
|
183
|
+
Thought: 23% decline is significant. I should check whether it's volume (fewer
|
|
184
|
+
orders), value (smaller orders), or both. Also check if it's across all segments
|
|
185
|
+
or concentrated.
|
|
186
|
+
|
|
187
|
+
Action: query_database — "SELECT COUNT(*), AVG(order_value), segment FROM orders
|
|
188
|
+
WHERE month = current AND month = previous GROUP BY segment"
|
|
189
|
+
Observation: [Query results]
|
|
190
|
+
|
|
191
|
+
Thought: Volume is down 18% but average order value is down only 5%. The decline
|
|
192
|
+
is concentrated in the Enterprise segment. Let me check acquisition vs. churn.
|
|
193
|
+
|
|
194
|
+
Action: query_database — "SELECT new_customers, churned_customers, segment FROM
|
|
195
|
+
customer_events WHERE period = last_30_days"
|
|
196
|
+
Observation: [Query results]
|
|
197
|
+
|
|
198
|
+
Thought: Enterprise churn is 3x normal. Let me check if there's a product or
|
|
199
|
+
pricing event that coincides.
|
|
200
|
+
|
|
201
|
+
[Continue investigation...]
|
|
202
|
+
|
|
203
|
+
Final Answer: Primary driver is Enterprise churn (elevated 3x), concentrated
|
|
204
|
+
in accounts that received the new pricing email on [date]. Secondary factor is
|
|
205
|
+
reduced trial-to-paid conversion, down 12%.
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
## Best Use Cases
|
|
209
|
+
|
|
210
|
+
1. **Agentic / Tool-Use Tasks**
|
|
211
|
+
- Tasks where the model needs to use tools iteratively
|
|
212
|
+
- Research with multiple lookups
|
|
213
|
+
- Debugging with read-test-fix cycles
|
|
214
|
+
|
|
215
|
+
2. **Multi-Step Investigation**
|
|
216
|
+
- Data investigation where each finding informs the next query
|
|
217
|
+
- Root cause analysis
|
|
218
|
+
- Audit tasks
|
|
219
|
+
|
|
220
|
+
3. **Autonomous Task Execution**
|
|
221
|
+
- Tasks that should complete without human intervention per step
|
|
222
|
+
- Workflows that use Claude Code's tool ecosystem
|
|
223
|
+
|
|
224
|
+
4. **When the Path Is Unknown**
|
|
225
|
+
- Tasks where you can't specify every step upfront
|
|
226
|
+
- Exploratory analysis
|
|
227
|
+
- Open-ended problem-solving with tools
|
|
228
|
+
|
|
229
|
+
## Selection Criteria
|
|
230
|
+
|
|
231
|
+
**Choose ReAct when:**
|
|
232
|
+
- ✅ Tools or external resources will be used
|
|
233
|
+
- ✅ Each step's result determines the next step
|
|
234
|
+
- ✅ The path to solution is not fully known upfront
|
|
235
|
+
- ✅ Reasoning should be shown alongside actions
|
|
236
|
+
- ✅ Task is agentic in nature
|
|
237
|
+
|
|
238
|
+
**Avoid ReAct when:**
|
|
239
|
+
- ❌ Task has a fixed, known sequence of steps → use RISEN
|
|
240
|
+
- ❌ No tools needed, just reasoning → use Chain of Thought
|
|
241
|
+
- ❌ Creative or writing task → use CO-STAR or BAB
|
|
242
|
+
- ❌ Simple, well-defined → use RTF, APE, or CTF
|
|
243
|
+
|
|
244
|
+
## ReAct vs. Chain of Thought vs. RISEN
|
|
245
|
+
|
|
246
|
+
| | Chain of Thought | RISEN | ReAct |
|
|
247
|
+
|---|---|---|---|
|
|
248
|
+
| Structure | Linear reasoning steps | Defined methodology | Thought-Action-Observation cycles |
|
|
249
|
+
| Tool use | No | No | Yes |
|
|
250
|
+
| Path known upfront? | Yes | Yes | No (emergent) |
|
|
251
|
+
| Best for | Complex reasoning | Multi-step procedures | Agentic tool use |
|
|
252
|
+
|
|
253
|
+
## Writing Good ReAct Prompts
|
|
254
|
+
|
|
255
|
+
### Goals Should Be Outcome-Focused
|
|
256
|
+
```
|
|
257
|
+
✅ "Identify the root cause of the auth failures and produce a fix"
|
|
258
|
+
❌ "Look at the auth code"
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
### Tools Should Be Named and Described
|
|
262
|
+
```
|
|
263
|
+
✅ - run_tests: Execute the test suite and return pass/fail results with error output
|
|
264
|
+
❌ - testing tool
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
### Constraints Prevent Loops
|
|
268
|
+
```
|
|
269
|
+
✅ "If you cannot confirm a hypothesis after 3 tool calls, state it as unconfirmed and move on"
|
|
270
|
+
❌ (no constraints — model may loop indefinitely)
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
### Include a Stop Condition
|
|
274
|
+
```
|
|
275
|
+
✅ "Stop when: the fix is confirmed by passing tests OR you've determined the fix requires information not available to you"
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
## Common Mistakes
|
|
279
|
+
|
|
280
|
+
1. **Specifying Every Step**
|
|
281
|
+
- If you know all the steps, use RISEN instead
|
|
282
|
+
- ReAct is for when the path is emergent
|
|
283
|
+
|
|
284
|
+
2. **No Tool List**
|
|
285
|
+
- Without knowing what tools are available, the model invents them
|
|
286
|
+
- Always list available tools explicitly
|
|
287
|
+
|
|
288
|
+
3. **No Constraints**
|
|
289
|
+
- Unconstrained ReAct can loop or over-explore
|
|
290
|
+
- Add max iterations or a stop condition
|
|
291
|
+
|
|
292
|
+
4. **Using ReAct for Static Tasks**
|
|
293
|
+
- If no tools are needed, Chain of Thought is simpler and more effective
|
|
294
|
+
|
|
295
|
+
## Quick Reference
|
|
296
|
+
|
|
297
|
+
| Component | Focus | Key Question |
|
|
298
|
+
|-----------|-------|--------------|
|
|
299
|
+
| Goal | End state | "What does success look like?" |
|
|
300
|
+
| Tools | Available actions | "What can the agent do?" |
|
|
301
|
+
| Thought | Reasoning | "What should I do next and why?" |
|
|
302
|
+
| Action | Tool use | "What specific action to take?" |
|
|
303
|
+
| Observation | Result | "What happened?" |
|
|
304
|
+
| Final Answer | Deliverable | "Goal achieved — what's the answer?" |
|