How spcl/graph-of-thoughts works
Project Type and Purpose
• This is a Python framework/library (“Graph of Thoughts”) for solving complex problems by modeling them as a Graph of Operations (GoO) and automatically executing them via a Large Language Model (LLM).
• It is intended both as a user-facing tool (installable from PyPI) and as a developer-extensible codebase (editable installation from source).
File Structure
• Top level:
– examples/ : end-to-end scripts illustrating usage (sorting, keyword counting, set intersection, document merging)
– graph_of_thoughts/ : core framework, subdivided into controller, language_models, operations, parser, prompter
– paper/ : reproducibility and plotting scripts for publication results
– config files: pyproject.toml, LICENSE, README.md
• Key modules:
– controller.Controller: orchestrates execution
– operations.GraphOfOperations, Generate, Score, GroundTruth: define and evaluate thought graph
– language_models: abstract interface + concrete ChatGPT and HF implementations
– parser.Parser: interprets LLM outputs into graph nodes
– prompter.Prompter: constructs prompts for each operation
README for Additional Insights
• Core flow: user defines a GoO, configures an LLM, creates a Controller with a Prompter and Parser, then calls run() and output_graph().
• Extensibility: new operations, new language models, and problem-specific Prompter/Parser pairs.
a. Main Components
• User Code (examples or custom scripts)
• Controller Module
• Graph of Operations (operations package)
• Prompter Module
• Parser Module
• Language Model Adapter (ChatGPT, HF)
• External LLM Service/API (OpenAI, local‐HF)
• Storage/Output (JSON graph, plots)
b. Relationships and Data Flow
1. User Code → instantiates GraphOfOperations, selects operations
2. User Code → configures LLM adapter via language_models
3. Controller invokes Prompter → generates prompt text
4. Controller sends prompt to Language Model Adapter → calls External LLM API
5. Raw LLM response → Parser → structured Thought nodes
6. Controller updates GraphOfOperations → loops until termination
7. Controller.output_graph → writes JSON, paper/plots.py reads results
c. Architectural Patterns
• Modularity: each concern in its own package
• Strategy pattern: interchangeable Prompter and Parser for each problem
• Chain of Responsibility / Pipeline: Controller mediates between modules
• Pluggable backends: language_models package with abstract base class
d. Key Technologies and Frameworks
• Python 3.8+
• OpenAI API (ChatGPT) and Hugging Face for LLM backends
• JSON for graph serialization
• Matplotlib (paper/plots.py) for results visualization
Elements
• Clear, consistent labels for each package/module
– Rectangles for internal modules
– Clouds for external LLM services