Prompt Engineering Systematic Methodology: From Few-shot to ReAct
Why Is Prompt Engineering Important?
The same LLM with different prompts can produce vastly different results. Prompt Engineering is not "writing a few prompts"; it is a systematic methodology.
Foundation Layer: Zero-shot vs Few-shot
Zero-shot
Ask directly without providing examples:
Translate the following sentence into English: "The weather is really nice today."
Few-shot (2-3 examples)
English → Chinese:
Hello → Hello
Goodbye → Goodbye
Thank you → Thank you
How are you? →
When to use Few-shot: when the task format is complex and the output has specific structural requirements.
Reasoning Layer: Chain-of-Thought (CoT)
Have the LLM think first, then answer.
Standard CoT
Problem: A farm has 15 chickens and 8 cows. Each chicken has 2 legs, and each cow has 4 legs. Please calculate how many legs there are in total.
Let's think step by step:
1. Chicken legs: 15 × 2 = 30 legs
2. Cow legs: 8 × 4 = 32 legs
3. Total number of legs: 30 + 32 = 62 legs
Answer: 62 legs
Zero-shot CoT
Simply add the magic phrase Let's think step by step:
Problem: A farm has 15 chickens and 8 cows... Let's think step by step.
Effect: On mathematical reasoning tasks, Zero-shot CoT increases accuracy from 18% to 79% (Kojima et al., 2022).
Advanced Level
Tree-of-Thought (ToT)
Instead of a single reasoning path, explore multiple at once and choose the best:
Problem: How can you use 4, 6, 8, 9 with the four arithmetic operations to get 24?
Approach A: 9 - 6 = 3, 8 × 3 = 24, 24 / 4 = 6 (failed)
Approach B: 8 - 6 = 2, 9 + 4 = 13, 2 × 13 = 26 (failed)
Approach C: 9 × 8 = 72, 6 × 4 = 24, 72 / 3 (failed)
Approach D: 8 × (9 - 6) = 24, 24 ✓ (success! no need to use 4)
ReAct (Reasoning + Acting)
Combines reasoning and acting, enabling LLMs to call tools during their reasoning process:
Question: Who is the director of the 2026 Oscar Best Picture?
Thought: I need to know what the 2026 Oscar Best Picture is
Action: search("2026 Oscar Best Picture winner")
Observation: "The Last Signal" won Best Picture at the 2026 Academy Awards
Thought: Now I need to know the director of this movie
Action: search("The Last Signal director")
Observation: "The Last Signal" was directed by Sarah Chen
Answer: Sarah Chen
Self-Consistency
For the same question, generate multiple reasoning paths and take the majority result:
Question: If 5 machines produce 5 parts in 5 minutes, how many minutes does it take 100 machines to produce 100 parts?
Path 1: 100 machines produce 100 parts in 5 minutes → 5 minutes
Path 2: 5 machines 5 minutes 5 parts → 1 machine 5 minutes 1 part → 100 machines 5 minutes 100 parts → 5 minutes
Path 3: 5 machines 5 minutes 5 parts → 5 machines 1 minute 1 part → 100 machines 1 minute 20 parts → 100 minutes (incorrect)
Majority result: 5 minutes ✓
Practical Framework
CRISPE Framework
| Element | Description | Example |
|---|---|---|
| Capacity & Role | Define the role | "You are a senior Python engineer" |
| Request | Clarify the task | "Please refactor the following code" |
| Insight | Provide context | "This code performs poorly when processing large files" |
| Statement | Format requirements | "Output the refactored code and explain the reasons for the changes" |
| Personality | Style | "Use concise English comments" |
| Example | Example | (Optional) Provide input and output examples |
Complete CRISPE Example
[C] You are a senior Python backend engineer specializing in performance optimization.
[R] Please refactor the following data processing function to improve its performance when processing a 10GB JSON file.
[I] The current code takes more than 30 minutes to process large files, and the bottleneck is loading the entire dataset into memory.
[S] Please output the refactored code, an explanation of the changes, and the expected performance improvement percentage.
[P] Use type hints and clear function naming.
Hands-On with Claude Code
System Prompt Template (CRISPE Format)
[C] You are my dedicated development assistant, skilled in React + TypeScript + Next.js.
[R] I will give you tasks; please execute them according to the following process:
1. First confirm your understanding (1-2 sentences)
2. List the implementation steps
3. Write the code step by step
4. After each step, explain the changes
[S] The code uses TypeScript strict mode, Tailwind CSS, and functional components.
[P] Respond concisely, focusing on code quality.
Recommended Reading
More in Learn
- Complete LangChain Tutorial 2026: Building Enterprise-Grade LLM Applications from Scratch
- MemoryHub v2.0 System Architecture In-Depth Analysis: From Capture Daemon to MCP Real-Time Memory Capture
- May 2026 LLM API Pricing Landscape: Complete Comparison of DeepSeek, Qwen, GLM, Kimi, MiniMax, and Doubao
- Cross-Channel Memory Hub: A Full Record of the Memory System Architecture Design for OpenClaw Agent