ASAmol Shukla
Projects
Courses
Prompts
Skills
Contact
Resume
Course Outline
Syllabus Overview

AI Tools: LLM & Prompt Engineering Mastery

Courses/AI Tools: LLM & Prompt Engineering Mastery/Lesson 21: Tree of Thought & Persona Prompting
50 mins lesson duration•10 mins read

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.

Interactive Lesson Code Snippet
# 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")
Language: python

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 marketing

Code 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 Style

Run real Python 3.12 WebAssembly code directly in your browser against automated test suites.

Solved:0 / 1
0 / 20 XP
Challenges:
Problem 1 of 1

Persona × 3 Decision

Medium+20 XP
Write a tree-of-thought prompt that evaluates 'hire a freelancer vs. hire full-time vs. use an agency' using three personas (CFO, Head of Product, Founder) and a scoring step.
main.pyPython 3.12 (WASM)
1
2
3
4
5
6
7
8
9
10
11
12
Press Run Code to test or Submit to verify test cases

Test Your Knowledge

Instant feedback

Quick Check: Tree of Thought & Personas

1 / 2
How is tree of thought different from chain-of-thought?

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.

10 mins read55 mins
Start next lesson
Previous: Self-Consistency — Sample & VoteNext: Prompt Chaining & Multi-Step Workflows
Made withbyAmol Shukla·amolshukla.online
ASAmol Shukla

AI Developer, Trainer & Agentic AI Expert building practical learning systems and real-world AI applications.

Explore

  • Projects
  • Courses
  • Prompts
  • Skills
  • Contact
  • Experience
  • Blogs

Connect

  • Resume
  • Contact
© 2026 Amol Shukla·Created withbyamolshukla.online
Back to top