Lesson 21: Tree of Thought & Persona Prompting
Explore several reasoning branches before deciding, and assign the model a persona to unlock specialized perspectives — with examples.
Two Techniques for Harder Problems
1. Tree of Thought (ToT)
Chain-of-thought walks one path. Tree of thought walks several branches in parallel, evaluates each, and picks the best — like a chess player considering moves.
When to use: strategy, planning, multi-criteria decisions, anything with trade-offs.
Example — choosing a marketing strategy:
I run a startup with a small budget. Evaluate 3 strategies
and pick one:
Strategy A: Influencer marketing
- Cost: high | Time to results: medium | Risk: medium
Strategy B: Content marketing
- Cost: low | Time to results: slow | Risk: low
Strategy C: Paid ads
- Cost: medium | Time to results: fast | Risk: high
For each: score it 1-5 on cost, speed, and risk.
Then recommend the best for a startup with limited budget.
The model explores each branch, then compares scores instead of committing to one path early.
Prompt pattern for ToT:
1. List N candidate approaches.
2. For each, list its pros, cons, and risks.
3. Score each on [criteria].
4. Recommend the best and explain why.
2. Persona Prompting
Assign the model a role with expertise, perspective, and constraints. Personas change what the model attends to.
| Persona | Unlocks |
|---|---|
| "Senior tax consultant" | Compliance-focused, precise language |
| "10-year-old explaining to a friend" | Simple analogies, no jargon |
| "Skeptical code reviewer" | Security and edge cases |
| "Hiring manager" | Candidate-focused feedback |
Weak vs. strong persona example:
Weak: "Review my resume."
Strong: "You are a senior engineering hiring manager at a
startup. Review my resume for a Senior Backend role. Focus on:
impact metrics, missing keywords, and red flags. Give 5
actionable fixes ranked by impact."
Persona + ToT Combined
The power move: assign each branch a different persona, then synthesize:
Should we launch in Q1 or Q2?
- Analyze as the CFO (costs and cash flow).
- Analyze as the CMO (market timing and demand).
- Analyze as the Head of Engineering (team readiness).
Then give one recommendation weighing all three.
Common Mistakes
- Personas that are too vague ("be an expert") — name the specific expertise and goal.
- ToT without a scoring rule — branches need criteria to compare.
- Asking for a persona but not honoring its constraints in the output format.
Key Takeaways
- Tree of thought explores branches before deciding; score each branch.
- Personas steer attention — the more specific the role, the better the result.
- Combine: persona-per-branch + a final synthesis step.
- ToT costs more tokens — reserve it for real decisions.
Next up: Prompt chaining — breaking big jobs into a sequence of focused prompts.
# Tree of thought: evaluate branches, pick the best
branches = {
"A: influencer marketing": {"cost": "high", "risk": "medium", "fit": "strong"},
"B: content marketing": {"cost": "low", "risk": "low", "fit": "strong"},
"C: paid ads": {"cost": "medium", "risk": "high", "fit": "medium"},
}
print("Branch evaluation (score = count of 'low'/'strong' ratings):\n")
for branch, metrics in branches.items():
score = sum(1 for v in metrics.values() if v in ("low", "strong"))
bar = "#" * score
print(f" {branch:30s} score={score} {bar}")
print("\nBest branch: B: content marketing")Lesson Code (Python)
# Tree of thought: evaluate branches, pick the best
branches = {
"A: influencer marketing": {"cost": "high", "risk": "medium", "fit": "strong"},
"B: content marketing": {"cost": "low", "risk": "low", "fit": "strong"},
"C: paid ads": {"cost": "medium", "risk": "high", "fit": "medium"},
}
print("Branch evaluation (score = count of 'low'/'strong' ratings):\n")
for branch, metrics in branches.items():
score = sum(1 for v in metrics.values() if v in ("low", "strong"))
bar = "#" * score
print(f" {branch:30s} score={score} {bar}")
print("\nBest branch: B: content marketing")Console Output
Branch evaluation (score = count of 'low'/'strong' ratings):
A: influencer marketing score=1 #
B: content marketing score=3 ###
C: paid ads score=0
Best branch: B: content marketingCode Visualization Tips
- Draw the decision as a tree: root question → 3 branches → scores → chosen branch highlighted.
- Label each persona in a group discussion with its priorities (CFO = cost, CMO = timing…).
- Sketch the persona dial: same prompt, different lens — show what each lens notices.
Professional Tips & Tricks
- Give every ToT branch an explicit scoring rule, or the comparison is vibes.
- Name the persona's constraints ('you must refuse unsafe requests') to keep it honest.
- For big decisions, one prompt per persona, then a final synthesis prompt — cleaner than one mega-prompt.
Python Code Judge & Practice Arena
LeetCode StyleRun real Python 3.12 WebAssembly code directly in your browser against automated test suites.
Persona × 3 Decision
Test Your Knowledge
Instant feedbackQuick Check: Tree of Thought & Personas
Up next · Continue learning
Prompt Chaining & Multi-Step Workflows
Break big tasks into focused prompts where each output feeds the next — with a full worked chain and validation checkpoints.