Graph of Thoughts (GoT) Reasoning
Advanced multi-path reasoning beyond tree structure. Explores, combines, and synthesizes solutions.
Research Foundation
Based on: Besta et al. (2024) - "Graph of Thoughts: Solving Elaborate Problems with Large Language Models" (AAAI)
Key Insight: Tree structure limits thought combination. Graphs allow:
- - Merging insights from different branches
- Feedback loops for iterative refinement
- Non-linear dependencies between thoughts
- Aggregation and distillation of multiple solutions
Performance: +62% quality improvement on synthesis tasks, +31% cost reduction via thought reuse.
GoT vs ToT vs CoT
Chain of Thought (CoT)
CODEBLOCK0
Tree of Thoughts (ToT)
CODEBLOCK1
Graph of Thoughts (GoT)
CODEBLOCK2
GoT Advantages:
- - ✓ Combine partial solutions
- ✓ Feedback loops for refinement
- ✓ Reuse successful sub-patterns
- ✓ Synthesize novel solutions
- ✓ Multi-dimensional optimization
Core Algorithm
CODEBLOCK3
GoT Operations
1. GENERATE Diverse Paths
Generate multiple solution approaches with diversity:
CODEBLOCK4
2. EVALUATE Paths
Multi-dimensional scoring:
| Dimension | Weight | Description |
|---|
| Feasibility | 0.25 | Can this be implemented? |
| Quality |
0.25 | How good is the solution? |
| Novelty | 0.15 | Is this innovative? |
| Coverage | 0.20 | Does it address all aspects? |
| Efficiency | 0.15 | Resource usage |
3. IDENTIFY Synergies
Find complementary insights:
CODEBLOCK5
4. COMBINE Thoughts
Create hybrid solutions:
CODEBLOCK6
5. ITERATE with Feedback
Refinement loop:
CODEBLOCK7
6. AGGREGATE Solution
Synthesize final answer:
CODEBLOCK8
Thought Graph Notation
Graph Structure
CODEBLOCK9
Node Types
| Type | Description | Example |
|---|
| INLINECODE0 | Initial problem statement | "Optimize performance" |
| INLINECODE1 |
Single solution approach | "Add caching" |
|
combined | Merged from multiple thoughts | "Caching + Indexes" |
|
critique | Identifies weaknesses | "Missing invalidation" |
|
refined | Improved based on critique | "Add smart invalidation" |
|
solution | Final synthesized answer | "Complete architecture" |
Edge Types
| Type | Description |
|---|
| INLINECODE6 | Creates new thought |
| INLINECODE7 |
Merges thoughts |
|
critiques | Identifies issues |
|
incorporates | Includes feedback |
|
refines | Improves thought |
|
aggregates | Synthesizes solution |
|
backtracks | Returns from dead end |
Complete Process Template
CODEBLOCK10
From A: Take proven caching strategy
From B: Add innovative prediction layer
Result: "Smart caching with predictive prefetching"
Score: 8.5/10 (+1.1 from best individual)
#### Combination 2: C + E
From C: Take hybrid architecture
From E: Add comprehensive error handling
Result: "Hybrid architecture with full error coverage"
Score: 8.2/10 (+0.7 from best individual)
---
### Phase 5: Iterate with Feedback
#### Iteration 1
**Input**: Combination 1 (Smart caching)
**Critique**: "What about cache invalidation?"
**Improvement**: Add event-based invalidation
**New Score**: 8.8/10
#### Iteration 2
**Input**: Improved C1
**Critique**: "Memory usage could spike"
**Improvement**: Add LRU eviction policy
**New Score**: 9.0/10
#### Iteration 3
**Input**: Further improved
**Critique**: None significant
**Improvement**: Minor polish
**New Score**: 9.1/10
**Converged**: Diminishing returns after iteration 3
---
### Phase 6: Aggregate Final Solution
**Key Insights from All Paths**:
- Caching dramatically improves performance (A, C)
- Predictive loading reduces latency (B)
- Error handling prevents cascading failures (E)
- Simplicity improves maintainability (D)
**Patterns Identified**:
1. Performance through caching + prediction
2. Reliability through error handling
3. Maintainability through simplicity
**Synthesized Solution**:
Implement a smart caching layer with:
- 1. Event-based invalidation (from feedback)
- Predictive prefetching (from B)
- LRU eviction (from feedback)
- Comprehensive error handling (from E)
- Simple API design (from D)
Architecture: [Detailed design]
**Confidence**: 87%
---
### Phase 7: Verification
**Verification Checklist**:
- [ ] Addresses original problem
- [ ] Meets success criteria
- [ ] Within constraints
- [ ] No major gaps identified
- [ ] Confidence > 80%
**Result**: ✅ PASSED
---
### Summary
| Metric | Value |
|--------|-------|
| Paths Generated | 5 |
| Combinations Created | 2 |
| Feedback Iterations | 3 |
| Final Score | 9.1/10 |
| Confidence | 87% |
| Improvement over best individual | +1.9 points |
**Selected Solution**: [Final synthesized solution]
Quick Actions
- -
got [problem] - Run full GoT reasoning - INLINECODE14 - Fast GoT (3 paths, 1 iteration)
- INLINECODE15 - Combine multiple thoughts
- INLINECODE16 - Find synergies between paths
- INLINECODE17 - Create feedback loop
- INLINECODE18 - Distill to essence
- INLINECODE19 - Visualize current thought graph
When to Use GoT
Use GoT When:
- - ✅ Problem has multiple dimensions to optimize
- ✅ Partial solutions exist in different branches
- ✅ Combination could create better solution
- ✅ Feedback loops would improve quality
- ✅ More complex than simple decision
- ✅ Synthesis of ideas needed
- ✅ Quality > Speed
Use ToT When:
- - ✅ Simple decision with discrete options
- ✅ Paths are truly independent
- ✅ Tree structure sufficient
- ✅ Faster decision needed
- ✅ Clear evaluation criteria
Use CoT When:
- - ✅ Straightforward problem
- ✅ Single clear solution path
- ✅ Speed is priority
- ✅ Simple reasoning sufficient
Integration with Other Skills
GoT + Tree of Thoughts
CODEBLOCK14
GoT + Self-Consistency
CODEBLOCK15
GoT + Error Recovery
CODEBLOCK16
GoT + Self-Criticism
CODEBLOCK17
GoT + Meta-Reasoning
Meta-reasoning decides:
- Should I use GoT or ToT?
- How many paths to generate?
- How many iterations?
- When to stop refining?
Examples
Example 1: Architecture Decision
CODEBLOCK19
External API: REST with intelligent caching
Internal API: gRPC for performance
Bridge: API Gateway for translation
CODEBLOCK20
Example 2: Algorithm Optimization
CODEBLOCK21
Primary: Inverted index for exact matches
Secondary: Vector embeddings for similarity
Ranking: Combine both scores
### Feedback Iterations
1. Critique: "Vector search slow for large scale"
Fix: Add approximate nearest neighbor
Score: 9.2
2. Critique: "Memory usage high"
Fix: Quantize vectors
Score: 9.3
### Final Solution
Hybrid search with:
- Inverted index (exact)
- ANN vector search (semantic)
- Quantized embeddings (memory)
- Combined ranking
**Confidence**: 88%
Metrics & Evaluation
GoT Session Metrics
| Metric | Description | Target |
|---|
| Paths Generated | Number of initial paths | 5-7 |
| Synergies Found |
Complementary pairs | 2-4 |
| Combinations Created | Hybrid solutions | 2-3 |
| Feedback Iterations | Refinement rounds | 2-4 |
| Final Score | Quality of solution | >8.5 |
| Confidence | Certainty level | >80% |
| Improvement | Over best individual | >1.0 |
Quality Indicators
✅ Good GoT Session:
- - Multiple synergies found
- Combinations improve on individuals
- Feedback loop converges
- High confidence final solution
❌ Poor GoT Session:
- - No synergies found
- Combinations don't improve
- Feedback doesn't converge
- Low confidence
Best Practices
- 1. Generate diverse paths - Different approaches, not variations
- Look for synergies early - Identify combination potential
- Combine thoughtfully - Not all combinations are good
- Iterate with purpose - Stop when diminishing returns
- Aggregate carefully - Don't lose key insights
- Verify the solution - Check against original problem
- Document the graph - Future reference and learning
Troubleshooting
Problem: No synergies found
Cause: Paths too similar
Solution: Generate more diverse initial paths
Problem: Combinations worse than individuals
Cause: Forced combination of incompatible thoughts
Solution: Be more selective about which to combine
Problem: Feedback loop doesn't converge
Cause: Critiques not actionable
Solution: Make critiques specific and fixable
Problem: Final solution too complex
Cause: Over-aggregation
Solution: Prioritize, keep only essential elements
Remember: The power of GoT is in COMBINATION and SYNTHESIS, not just exploration. Find synergies, merge insights, create solutions greater than the sum of parts.
v2.0 Optimizations (FoT-Enhanced)
Parallel Execution
Execute multiple thought paths concurrently for 2-4x speedup:
CODEBLOCK23
Performance Improvement:
| Operation | Sequential | Parallel | Speedup |
|---|
| Generate 5 paths | 5.0s | 1.2s | 4.2x |
| Evaluate 5 paths |
5.0s | 1.0s | 5.0x |
| Synergy check (10 pairs) | 10.0s | 2.0s | 5.0x |
| Total (typical session) | 25.0s | 6.5s | 3.8x |
Intelligent Caching
Cache intermediate results for reuse across similar problems:
CODEBLOCK24
Cache Benefits:
- - Similar problems reuse thought paths
- Evaluation results cached per path
- Synergy analysis cached per pair
- 40-60% reduction in redundant computation
Combined Parallel + Cached
CODEBLOCK25
Command Flags
CODEBLOCK26
Performance Summary (v2.0)
| Scenario | v1.0 Time | v2.0 Time | Improvement |
|---|
| New complex problem | 25s | 6.5s | 3.8x faster |
| Similar to cached |
25s | 0.1s | 250x faster |
| 5-path exploration | 10s | 2.2s | 4.5x faster |
| Full session with feedback | 45s | 12s | 3.75x faster |
v2.0 Changelog:
- - Added parallel execution for all phases (3-4x faster)
- Added intelligent caching for similar problems (40-60% reduction)
- Combined optimized mode for best performance
- New CLI flags for execution control
思维图谱 (GoT) 推理
超越树状结构的高级多路径推理。探索、组合并综合解决方案。
研究基础
基于: Besta 等人 (2024) - 思维图谱:利用大型语言模型解决复杂问题 (AAAI)
核心洞察: 树状结构限制了思维组合。图谱允许:
- - 融合不同分支的见解
- 用于迭代优化的反馈循环
- 思维之间的非线性依赖关系
- 多个解决方案的聚合与提炼
性能: 合成任务质量提升 +62%,通过思维复用成本降低 +31%。
GoT vs ToT vs CoT
思维链 (CoT)
问题 → 步骤 1 → 步骤 2 → 步骤 3 → 解决方案
(单一线性路径,快速但有限)
思维树 (ToT)
问题
/ | \
A B C (独立分支)
/ \ | / \
A1 A2 B1 C1 C2 (无跨分支组合)
|
最佳 A1
思维图谱 (GoT)
问题
/ | \
A ─── B ─── C (分支可以连接)
/ \ │ / \
A1─┴──B1──┴─C1 (思维组合)
\ │ /
└──↓──┘
最终 (聚合/综合)
GoT 优势:
- - ✓ 组合部分解决方案
- ✓ 用于优化的反馈循环
- ✓ 复用成功的子模式
- ✓ 综合新颖解决方案
- ✓ 多维度优化
核心算法
python
class 思维图谱:
基于图谱的思维组合推理。
def init(self, 路径数=5, 最大迭代次数=3, 质量阈值=0.85):
self.路径数 = 路径数
self.最大迭代次数 = 最大迭代次数
self.质量阈值 = 质量阈值
self.思维图谱 = 思维图()
self.评估器 = 路径评估器()
def 推理(self, 问题):
主要推理入口。
# 阶段 1:生成多个思维路径
路径 = self.生成思维路径(问题, 路径数=self.路径数)
# 阶段 2:独立评估每条路径
评估结果 = [self.评估路径(路径) for 路径 in 路径]
# 阶段 3:识别路径间的协同效应
协同效应 = self.识别协同效应(路径, 评估结果)
# 阶段 4:组合有前景的思维
组合结果 = self.组合思维(路径, 协同效应)
# 阶段 5:评估组合结果
组合评估 = [self.评估路径(c) for c in 组合结果]
# 阶段 6:通过反馈循环迭代
优化结果 = self.反馈迭代(组合结果, 组合评估)
# 阶段 7:聚合最终解决方案
结果 = self.聚合解决方案(优化结果)
# 阶段 8:执行并验证
验证结果 = self.执行并验证(结果)
return 验证结果
def 生成思维路径(self, 问题, 路径数):
生成 N 条多样化的解决方案路径。
路径 = []
for i in range(路径数):
路径 = self.生成多样化路径(问题, 路径)
路径.append(路径)
return 路径
def 评估路径(self, 路径):
在多个维度上对思维路径进行评分。
return {
可行性: self.评分可行性(路径),
质量: self.评分质量(路径),
新颖性: self.评分新颖性(路径),
覆盖度: self.评分覆盖度(路径),
置信度: self.计算置信度(路径)
}
def 识别协同效应(self, 路径, 评估结果):
跨路径寻找互补性见解。
协同效应 = []
for i, 路径_a in enumerate(路径):
for j, 路径_b in enumerate(路径):
if i < j:
协同 = self.检查协同效应(路径a, 路径b)
if 协同[分数] > 0.6:
协同效应.append(协同)
return 协同效应
def 组合思维(self, 路径, 协同效应):
从协同对创建混合思维。
组合结果 = []
for 协同 in sorted(协同效应, key=lambda s: s[分数], reverse=True):
混合 = self.创建混合(
路径[协同[路径_a]],
路径[协同[路径_b]],
协同[组合策略]
)
组合结果.append(混合)
return 组合结果
def 反馈迭代(self, 思维, 评估结果):
通过反馈循环进行优化。
优化结果 = 思维.copy()
for 迭代 in range(self.最大迭代次数):
# 识别弱点
批评 = [self.批评(t, e) for t, e in zip(思维, 评估结果)]
# 生成改进
改进 = [self.改进(t, c) for t, c in zip(思维, 批评)]
# 重新评估
新评估 = [self.评估路径(imp) for imp in 改进]
# 保留提升质量的改进
for imp, 旧评估, 新评估 in zip(改进, 评估结果, 新评估):
if 新评估[质量] > 旧评估[质量]:
优化结果.append(imp)
# 检查是否达到阈值
if max(新评估, key=lambda e: e[质量])[质量] >= self.质量阈值:
break
return 优化结果
def 聚合解决方案(self, 思维):
从最佳思维中综合最终解决方案。
# 从每个思维中提取关键见解
见解 = [self.提取见解(t) for t in 思维]
# 寻找共同模式
模式 = self.寻找模式(见解)
# 综合统一解决方案
解决方案 = self.综合(模式, 见解)
return 解决方案
def 执行并验证(self, 解决方案):
执行解决方案并验证结果。
结果 = self.执行(解决方案)
验证 = self.验证(结果)
if not 验证[通过]:
# 回溯并尝试替代方案
return self.回溯(解决方案, 验证[问题])
return {
解决方案: 解决方案,
结果: 结果,
置信度: 验证[置信度],
验证: 验证
}
GoT 操作
1. 生成多样化路径
生成具有多样性的多种解决方案方法:
问题:[复杂问题]
路径 A:[保守方法]
- 使用经过验证的方法
- 低风险,中等回报
路径 B:[创新方法]
- 新颖技术
- 高风险,潜在高回报
路径 C:[混合方法]
- 结合多个领域的元素
- 平衡的风险/回报
路径 D:[最小化方法]
- 尽可能简单的解决方案
- 低成本,可能遗漏边缘情况
路径 E:[全面方法]
- 涵盖所有方面
- 高成本,全面覆盖
2. 评估路径
多维度评分:
0.25 | 解决方案有多好? |
| 新颖性 | 0.15 | 是否创新? |
| 覆盖度 | 0.20 | 是否涵盖所有方面? |
| 效率 | 0.15 | 资源使用情况 |
3. 识别协同效应
寻找互补性见解:
yaml
协同分析:
- 对: [A, B]
协同类型: 互补
分数: 0.85
推理: A 解决速度,B 解决准确性
组合潜力: 高
- 对: [A, C]
协同类型: 冗余
分数: 0.30
推理: 两者关注同一维度
组合潜力: 低
- 对: [B, D]
协同类型: 增强
分数: 0.72
推理: B 的创新 + D 的简洁性
组合潜力: 中
4. 组合思维
创建混合解决方案:
组合策略 1:取长补短
├── 来自路径 A:性能优化
├── 来自路径 B:错误处理方法
└── 结果:快速 + 稳健的解决方案
组合策略 2:分层
├── 基础层:路径 D(最小可行)
├── 增强层:路径 B(创新)