mirror of
https://github.com/wshobson/agents.git
synced 2026-03-18 09:37:15 +00:00
style: format all files with prettier
This commit is contained in:
@@ -7,6 +7,7 @@ Chain-of-Thought (CoT) prompting elicits step-by-step reasoning from LLMs, drama
|
||||
## Core Techniques
|
||||
|
||||
### Zero-Shot CoT
|
||||
|
||||
Add a simple trigger phrase to elicit reasoning:
|
||||
|
||||
```python
|
||||
@@ -29,6 +30,7 @@ prompt = zero_shot_cot(query)
|
||||
```
|
||||
|
||||
### Few-Shot CoT
|
||||
|
||||
Provide examples with explicit reasoning chains:
|
||||
|
||||
```python
|
||||
@@ -53,6 +55,7 @@ A: Let's think step by step:"""
|
||||
```
|
||||
|
||||
### Self-Consistency
|
||||
|
||||
Generate multiple reasoning paths and take the majority vote:
|
||||
|
||||
```python
|
||||
@@ -85,6 +88,7 @@ def self_consistency_cot(query, n=5, temperature=0.7):
|
||||
## Advanced Patterns
|
||||
|
||||
### Least-to-Most Prompting
|
||||
|
||||
Break complex problems into simpler subproblems:
|
||||
|
||||
```python
|
||||
@@ -125,6 +129,7 @@ Final Answer:"""
|
||||
```
|
||||
|
||||
### Tree-of-Thought (ToT)
|
||||
|
||||
Explore multiple reasoning branches:
|
||||
|
||||
```python
|
||||
@@ -176,6 +181,7 @@ Score:"""
|
||||
```
|
||||
|
||||
### Verification Step
|
||||
|
||||
Add explicit verification to catch errors:
|
||||
|
||||
```python
|
||||
@@ -220,6 +226,7 @@ Corrected solution:"""
|
||||
## Domain-Specific CoT
|
||||
|
||||
### Math Problems
|
||||
|
||||
```python
|
||||
math_cot_template = """
|
||||
Problem: {problem}
|
||||
@@ -248,6 +255,7 @@ Answer: {final_answer}
|
||||
```
|
||||
|
||||
### Code Debugging
|
||||
|
||||
```python
|
||||
debug_cot_template = """
|
||||
Code with error:
|
||||
@@ -278,6 +286,7 @@ Fixed code:
|
||||
```
|
||||
|
||||
### Logical Reasoning
|
||||
|
||||
```python
|
||||
logic_cot_template = """
|
||||
Premises:
|
||||
@@ -305,6 +314,7 @@ Answer: {final_answer}
|
||||
## Performance Optimization
|
||||
|
||||
### Caching Reasoning Patterns
|
||||
|
||||
```python
|
||||
class ReasoningCache:
|
||||
def __init__(self):
|
||||
@@ -328,6 +338,7 @@ class ReasoningCache:
|
||||
```
|
||||
|
||||
### Adaptive Reasoning Depth
|
||||
|
||||
```python
|
||||
def adaptive_cot(problem, initial_depth=3):
|
||||
depth = initial_depth
|
||||
@@ -378,6 +389,7 @@ def evaluate_cot_quality(reasoning_chain):
|
||||
## When to Use CoT
|
||||
|
||||
**Use CoT for:**
|
||||
|
||||
- Math and arithmetic problems
|
||||
- Logical reasoning tasks
|
||||
- Multi-step planning
|
||||
@@ -385,6 +397,7 @@ def evaluate_cot_quality(reasoning_chain):
|
||||
- Complex decision making
|
||||
|
||||
**Skip CoT for:**
|
||||
|
||||
- Simple factual queries
|
||||
- Direct lookups
|
||||
- Creative writing
|
||||
|
||||
Reference in New Issue
Block a user