0
Phase 9

Graph of Thoughts

~3 min read

Concept & How It Works

    Why Does It Exist?

    Real problem-solving combines insights from different approaches. GoT lets an agent explore parallel ideas and then merge compatible partial solutions, outperforming ToT on tasks requiring integration of multiple perspectives.

    Real-World Analogy

    GoT is a research team where members work on different angles, then merge findings into a unified report — rather than one person following a single outline.
    Loading diagram...

    Visual Workflows

    What is Graph of Thoughts?

    Loading diagram...

    Example

    Scenario

    Write a business plan: branch A researches market, branch B researches competitors, branch C drafts financials. Aggregate node merges all three into a coherent document.

    Solution

    In Agent Design Patterns, apply Graph of Thoughts to this scenario: Write a business plan: branch A researches market, branch B researches competitors, branch C drafts financials. Identify the inputs, run the technique, validate the output, and note one thing you would monitor in production.

    Practice Task

    Do this before moving to the next module — reading alone is not enough.

    Open the Code Walkthrough below and run it locally. Change one parameter related to Graph of Thoughts (e.g. model, temperature, top_k, or tool name), observe the difference in output, and write 2–3 sentences explaining what changed.

    Code Walkthrough

    Highlighted lines show where Graph of Thoughts happens in the code.

    Graph of Thoughts
    1# Graph of Thoughts — minimal example2from openai import OpenAI3
    4client = OpenAI()  # create API client5
    6# Ask the model to explain this topic7response = client.chat.completions.create(  # core API call for Graph of Thoughts8    model="gpt-4o-mini",9    messages=[10        {"role": "system", "content": "You explain graph of thoughts clearly."},11        {"role": "user", "content": f"What is graph of thoughts?"},12    ],13    temperature=0,14)15print(response.choices[0].message.content)  # show output for debugging

    Commands to Remember

    Commands to Remember

    • pip install langchain langchain-openai # patterns work with any LLM SDK
    • python react_agent.py # run a ReAct-style agent loop
    • pip install tenacity # retry logic for agent steps

    Common Mistakes

    • Treating Graph of Thoughts as a black box without evaluation
    • Ignoring cost and latency in production
    • Skipping error handling for graph of thoughts

    Cheat Sheet

    Quick recap — the most important points from this module.

    Cheat Sheet

    quick ref
    • Graph of Thoughts
    • DAG
    • Aggregation
    • Thought Node