Graph of Thoughts Prompting: Beyond Tree of Thought
By Learnia Team
Graph of Thoughts Prompting: Beyond Tree of Thought
This article is written in English. Our training modules are available in French.
As AI problem-solving techniques advance, researchers have moved from linear Chain-of-Thought to branching Tree-of-Thought to the latest paradigm: Graph of Thoughts (GoT). This technique allows AI to not only explore multiple reasoning paths but also combine, refine, and loop between ideas—enabling solutions to problems that were previously intractable.
This comprehensive guide explores how Graph of Thoughts works, when to use it, and how to implement it effectively in your prompting practice.
The Evolution of Reasoning Techniques
From Chain to Tree to Graph
Chain of Thought (CoT):
A → B → C → D → Answer
(Linear, single path)
Tree of Thought (ToT):
A
/|\
B C D
/| |\
E F G H
(Branching, but no merging)
Graph of Thoughts (GoT):
A
/|\
B C D
/|\ /|\
E F G H
\|/|\|/
I J
\|
Answer
(Branching AND merging)
What Is Graph of Thoughts?
Core Concept
Graph of Thoughts (GoT) represents AI reasoning as a directed graph where:
- →Nodes = Thoughts (intermediate reasoning steps)
- →Edges = Dependencies or transformations between thoughts
- →Operations = Generate, aggregate, refine, score
Unlike trees that only branch, graphs allow:
- →Merging of multiple ideas into one
- →Looping back to refine earlier thoughts
- →Voting across multiple solutions
- →Aggregating the best elements from different paths
The GoT Framework
┌───────────────────────────────────────────────────┐
│ Graph of Thoughts Framework │
├───────────────────────────────────────────────────┤
│ │
│ Operations: │
│ ┌─────────────────────────────────────────────┐ │
│ │ GENERATE: Create new thoughts from existing │ │
│ │ AGGREGATE: Combine multiple thoughts │ │
│ │ REFINE: Improve a thought with feedback │ │
│ │ SCORE: Evaluate thought quality │ │
│ └─────────────────────────────────────────────┘ │
│ │
│ Graph Structure: │
│ ┌─────────────────────────────────────────────┐ │
│ │ Nodes: Individual thoughts/partial solutions│ │
│ │ Edges: Transformations between thoughts │ │
│ │ Paths: Sequences through the graph │ │
│ │ Cycles: Allowed for refinement │ │
│ └─────────────────────────────────────────────┘ │
│ │
└───────────────────────────────────────────────────┘
Why Graph Outperforms Tree
The Merging Advantage
Consider sorting a list of numbers. With ToT:
Problem: Sort [3, 1, 4, 1, 5, 9, 2, 6]
ToT Approach:
Branch 1: Try bubble sort → [1, 1, 2, 3, 4, 5, 6, 9]
Branch 2: Try merge sort → [1, 1, 2, 3, 4, 5, 6, 9]
Branch 3: Try quick sort → [1, 1, 2, 3, 4, 5, 6, 9]
Result: Pick best branch (all same, wasted computation)
With GoT:
Problem: Sort [3, 1, 4, 1, 5, 9, 2, 6]
GoT Approach:
1. Split: [3, 1, 4, 1] and [5, 9, 2, 6]
2. Process each: [1, 1, 3, 4] and [2, 5, 6, 9]
3. MERGE operation: Combine sorted sublists
4. Result: [1, 1, 2, 3, 4, 5, 6, 9]
Actually uses divide-and-conquer efficiently!
The Refinement Loop
GoT allows thoughts to be improved:
Initial thought: "Revenue increased due to marketing"
REFINE with data:
"Revenue increased 23% after campaign launch"
REFINE with context:
"Revenue increased 23% Q3 after influencer campaign,
exceeding 15% projection by 8 percentage points"
Each refinement adds precision without restarting.
The Four GoT Operations
1. GENERATE
Create new thoughts from existing ones:
Prompt Pattern:
"Given this thought: [THOUGHT]
Generate [N] new thoughts that extend or develop this idea.
Each should explore a different direction."
Example:
Input: "The app is slow"
Generate 3 thoughts:
1. "The app is slow due to database queries taking too long"
2. "The app is slow because of frontend rendering bottleneck"
3. "The app is slow from network latency with API calls"
2. AGGREGATE
Combine multiple thoughts into one:
Prompt Pattern:
"You have these [N] partial solutions:
[THOUGHT 1]
[THOUGHT 2]
[THOUGHT 3]
Combine the best elements into a single, coherent solution."
Example:
Thought 1: "Use caching for database queries"
Thought 2: "Implement lazy loading for frontend"
Thought 3: "Enable compression for API responses"
Aggregated: "Implement a multi-layer optimization: cache
database queries, lazy load frontend components, and compress
API payloads—addressing all three bottleneck types."
3. REFINE
Improve a thought based on feedback:
Prompt Pattern:
"Here is a thought: [THOUGHT]
Here is feedback: [FEEDBACK]
Refine the thought to address the feedback while
maintaining its core insight."
Example:
Thought: "We should use Redis for caching"
Feedback: "Redis requires additional infrastructure"
Refined: "We should use Redis for caching, with AWS
ElastiCache for managed infrastructure to minimize
operational overhead."
4. SCORE
Evaluate thought quality:
Prompt Pattern:
"Evaluate this thought on these criteria:
- Correctness (0-10)
- Completeness (0-10)
- Feasibility (0-10)
Thought: [THOUGHT]
Provide scores and brief justification for each."
Example:
Thought: "Migrate to microservices architecture"
Scores:
- Correctness: 7 (valid solution to scalability)
- Completeness: 5 (missing migration strategy)
- Feasibility: 4 (significant effort for small team)
Average: 5.3
Implementing GoT Prompting
Basic Implementation
class GraphOfThoughts:
def __init__(self, llm):
self.llm = llm
self.thoughts = {} # id -> thought
self.graph = {} # id -> [successor_ids]
def generate(self, parent_id: str, n: int = 3) -> list:
parent = self.thoughts[parent_id]
new_thoughts = self.llm.complete(
f"Given: {parent}\nGenerate {n} distinct extensions:"
)
# Parse and store new thoughts
ids = []
for thought in self.parse_thoughts(new_thoughts):
id = self.add_thought(thought, parent_id)
ids.append(id)
return ids
def aggregate(self, thought_ids: list) -> str:
thoughts = [self.thoughts[id] for id in thought_ids]
combined = self.llm.complete(
f"Combine these thoughts:\n" +
"\n".join(thoughts) +
"\nInto one coherent solution:"
)
return self.add_thought(combined, thought_ids)
def refine(self, thought_id: str, feedback: str) -> str:
thought = self.thoughts[thought_id]
refined = self.llm.complete(
f"Thought: {thought}\nFeedback: {feedback}\nRefined:"
)
return self.add_thought(refined, [thought_id])
def score(self, thought_id: str) -> float:
thought = self.thoughts[thought_id]
scores = self.llm.complete(
f"Score (0-10) for correctness, completeness, " +
f"feasibility:\n{thought}"
)
return self.parse_scores(scores)
Prompt-Only GoT
Without code, you can apply GoT principles in prompts:
## Step 1: Generate Multiple Approaches
"For this problem: [PROBLEM]
Generate 3 different approaches to solving it.
Make each approach meaningfully different."
## Step 2: Develop Each Approach
"Take approach #2 and develop it further. What are the key
steps? What are potential issues?"
## Step 3: Aggregate Best Elements
"Considering all three approaches:
- Approach 1: [summary]
- Approach 2: [summary]
- Approach 3: [summary]
Combine the best elements from each into a single solution.
Keep strengths, address weaknesses."
## Step 4: Refine with Constraints
"This solution: [AGGREGATED]
Must also satisfy these constraints: [CONSTRAINTS]
Refine the solution to meet all constraints while
preserving effectiveness."
## Step 5: Evaluate
"Score the final solution:
- Does it solve the original problem? (0-10)
- Is it complete? (0-10)
- Is it practical? (0-10)
If any score is below 7, what specific improvement is needed?"
When to Use GoT
Ideal Problem Types
Decomposable Problems:
- →Can be split into subproblems
- →Solutions to parts can be combined
- →Examples: sorting, planning, optimization
Multi-Perspective Problems:
- →Benefit from diverse viewpoints
- →Truth emerges from synthesis
- →Examples: design decisions, strategy
Refinement-Sensitive Problems:
- →Initial answers need iteration
- →Feedback improves quality
- →Examples: writing, debugging
GoT Decision Framework
Is the problem simple and linear?
└── Yes → Use Chain of Thought
└── No ↓
Does the problem benefit from exploring alternatives?
└── No → Use Chain of Thought
└── Yes ↓
Can partial solutions be meaningfully combined?
└── No → Use Tree of Thought
└── Yes ↓
Does the solution benefit from refinement loops?
└── No → Consider Tree of Thought
└── Yes → Use Graph of Thoughts
Practical Examples
Example 1: Business Strategy Analysis
Problem: How should we respond to a new competitor?
GoT Approach:
[GENERATE] Initial thoughts:
T1: "Lower prices to compete on cost"
T2: "Differentiate on quality and service"
T3: "Expand to markets they haven't entered"
[GENERATE] Extend each:
T1a: "10% price reduction, accept margin hit"
T1b: "Efficiency improvements to enable lower prices"
T2a: "Premium tier with enhanced support"
T2b: "Focus on features they lack"
T3a: "International expansion"
T3b: "Enter adjacent market segments"
[AGGREGATE] Combine T2a + T2b + T3b:
"Launch premium tier focusing on unmatched features
and support, while expanding into adjacent segments
they're ignoring—avoiding direct price competition."
[REFINE] With budget constraint:
"Prioritize premium tier launch (Q2) with existing
resources, defer segment expansion to Q4 pending
results. Maintain current pricing."
[SCORE]:
- Addresses threat: 8/10 (indirect but effective)
- Feasibility: 9/10 (phased approach)
- Risk: 7/10 (market reaction uncertain)
Final strategy ready for executive review.
Example 2: Code Architecture Design
Problem: Design authentication system for new app
[GENERATE] Architecture options:
T1: JWT-based stateless auth
T2: Session-based server auth
T3: OAuth2 with third-party providers only
[GENERATE] Pros/cons for each:
T1-pro: Scalable, no server state
T1-con: Token revocation complex
T2-pro: Easy revocation, server control
T2-con: State management, scaling challenges
T3-pro: No password management
T3-con: Dependency on providers, user friction
[AGGREGATE] T1 + elements of T2:
"JWT for regular auth with short expiry (15 min),
paired with server-side refresh token store for
revocation capability. Get scalability of JWT with
control of session management."
[REFINE] Add security requirements:
"JWT (15 min) + refresh tokens (30 days) stored in
Redis. Refresh tokens invalidated on password change.
Add rate limiting and device fingerprinting."
[AGGREGATE] Add T3:
"Support OAuth2 providers (Google, Apple) alongside
custom JWT+refresh implementation. OAuth users get
linked accounts, can add password later."
Final: Hybrid system addressing all requirements.
Advanced GoT Patterns
Iterative Refinement Loop
repeat:
thought = generate()
score = evaluate(thought)
if score >= threshold:
return thought
feedback = identify_weaknesses(thought)
thought = refine(thought, feedback)
until max_iterations
Ensemble Aggregation
Generate N independent solutions
Score each solution
Filter to top K
Aggregate top K into mega-solution
Refine mega-solution
Return final
Hierarchical GoT
High-level graph for strategy
├── Subgraph for component A
├── Subgraph for component B
└── Subgraph for component C
Each subgraph solved independently
Results aggregated at high level
GoT vs Other Techniques
| Technique | Exploration | Combination | Refinement | Complexity | Best For |
|---|---|---|---|---|---|
| CoT | None | None | None | Low | Simple problems |
| Self-Consistency | Multiple paths | Vote | None | Medium | Uncertainty |
| ToT | Tree branches | None | None | Medium-High | Exploration |
| GoT | Graph | Aggregate | Loop | High | Complex synthesis |
Key Takeaways
- →
Graph of Thoughts extends Tree of Thought by adding aggregation, refinement, and loops
- →
Four core operations: Generate, Aggregate, Refine, Score
- →
Key advantage is combination: GoT can merge partial solutions into stronger wholes
- →
Best for decomposable problems where solutions can be combined and refined
- →
Can be implemented in code or pure prompts using structured multi-step approaches
- →
Higher complexity means higher cost—use when simpler methods fall short
- →
Practical for real problems like strategy, architecture, and complex analysis
Master Advanced Prompting Techniques
Graph of Thoughts is one of several advanced prompting techniques that dramatically improve AI reasoning for complex problems. Understanding the full toolkit helps you choose the right approach.
In our Module 3 — Advanced Prompting Techniques, you'll learn:
- →Chain-of-Thought fundamentals
- →Tree-of-Thought branching strategies
- →Self-consistency for robust answers
- →Step-back prompting for perspective
- →When to use each technique
- →Combining techniques for maximum effect
These skills will help you solve problems that basic prompting can't touch.
Module 3 — Chain-of-Thought & Reasoning
Master advanced reasoning techniques and Self-Consistency methods.