tot.mp4
Tree_Of_Thought is an external Tree-of-Thought reasoning system for structured problem solving.
Instead of relying on one opaque model completion, this project turns reasoning into an explicit, inspectable, controllable tree with live state, scoring, pruning, and deterministic tool support.
It combines:
- a FastAPI service that manages long-lived reasoning sessions
- a browser UI for creating sessions, inspecting nodes, steering, and pruning branches
- a node-level FSM and tree scheduler for controlled branch growth
- a SymPy-backed skill layer for exact symbolic and analytical computation
- role-split model routing for planning, modeling, review, and non-terminal evaluation
Built-in CoT is useful, but it has hard limits when you care about reliability, auditability, or branch diversity.
- Built-in CoT is hidden. You usually see only the final answer, not a persistent reasoning structure you can inspect, compare, rank, or edit.
- Built-in CoT is mostly linear. Once a single completion drifts, alternative paths are lost. A tree keeps multiple viable routes alive at the same time.
- Built-in CoT is difficult to control step-by-step. This system constrains each node to one local move instead of letting a model solve too much at once.
- Built-in CoT is hard to debug. Here every node has explicit status, score, route metadata, review output, and frontier state.
- Built-in CoT does not naturally support operator intervention. This system lets you inspect a node, delete a subtree, steer the follow-up prompt, reconnect to a session, or continue expansion later.
The practical result is reasoning with persistence, structure, and control.
The biggest gain comes from externalizing reasoning out of a single model pass.
- State becomes durable. Sessions, nodes, frontier entries, and run phases live outside any one completion.
- Reasoning becomes reproducible. The same scheduler settings and backend settings can be replayed and regression-tested.
- Models become swappable. Planning, modeling, review, and evaluation can each use different models with different cost and latency profiles.
- Deterministic checks become first-class. Hard rules, symbolic math, and structured post-processing do not depend on a model remembering every constraint.
- Human oversight becomes possible. The system exposes the tree over HTTP and in a browser UI instead of trapping everything inside a prompt.
- System-level optimization becomes possible. You can tune frontier size, depth, reflection limits, deletion policy, and model routing independently from the prompt text.
In short, externalization turns reasoning from a hidden behavior into a real software system.
- Role-split model routing. Planning, modeling, review, and non-terminal evaluation are separated rather than collapsed into one all-purpose model call.
- Route-local incremental refinement. Non-terminal nodes are expected to add exactly one new local delta instead of paraphrasing the parent or jumping ahead.
- Parent-child semantic-delta enforcement. The system checks whether a child is meaningfully different from its parent and soft-prunes unresolved duplicates.
- FSM-governed node lifecycle. Proposal, calculation, evaluation, reflection, and finalization are modeled as explicit states rather than ad hoc prompt retries.
- Lightweight intermediate evaluation plus stronger review. Non-terminal nodes can be scored cheaply while terminal or deletion-sensitive decisions still go through stronger review paths.
- Review-gated subtree deletion. Branch removal flows through backend review before deletion.
- Deterministic skill integration. Symbolic computation lives in
skills.py,skill_registry.md, andskills.md. Benchmark problems, expected values, and per-case tool solutions live inbenchmarks.py, outside the runtime skill registry, so the system under test cannot discover benchmark answers through skill search. - Live inspectable frontier. The scheduler exposes the current tree, frontier selection, candidate answers, and expansion state for operator debugging.
The current architecture uses four reasoning roles:
- planning model: route selection and orchestration
- modeling model: propose or revise one local next step
- review model: review, deletion review, and terminal evaluation
- non-terminal evaluation model: lightweight scoring for intermediate nodes
The scheduler keeps multiple branches alive, enforces route-local refinement, and exposes the evolving tree through the web UI and HTTP API.
- Conda or another Python environment manager
- Access to the configured planning, modeling, review, and evaluation models
The provided environment file installs the Python dependencies used by the API, scheduler, tests, and symbolic skill layer.
Create and activate the environment:
conda env create -f environment.yml
conda activate totIf the environment already exists:
conda env update -f environment.yml --prune
conda activate totStart the FastAPI server:
python tot_api.pyThen open:
http://127.0.0.1:8000/
The UI is served from the same process and loads the terminal-style tree explorer from frontend/.
- Start the local chat backend.
- Start
tot_api.py. - Open
http://127.0.0.1:8000/. - Enter a problem statement.
- Create a session.
- Inspect the tree, frontier, final result panel, and node details.
- Delete or steer branches when you want to redirect the search.
- Run the session again to continue until the frontier is exhausted.
The UI also supports reconnecting to an existing session id, polling controls, node deletion through backend review, steering after deletion, and recommended model presets.
Main endpoints:
GET /- serve the frontendGET /health- lightweight health checkPOST /api/tot/sessions- create a sessionGET /api/tot/sessions/{session_id}- fetch current statePOST /api/tot/sessions/{session_id}/run- run until the current frontier is exhaustedDELETE /api/tot/sessions/{session_id}/nodes/{node_id}- delete a subtree after reviewDELETE /api/tot/sessions/{session_id}- delete a session
A minimal session-creation example:
curl -X POST http://127.0.0.1:8000/api/tot/sessions \
-H "Content-Type: application/json" \
-d '{
"run_on_create": true,
"problem_context": {
"problem_statement": "Compare several viable solution routes before refining the best branch."
}
}'tot_api.py- FastAPI app, session store, route handlers, and frontend servingfsm/- backend adapters (backend.py), HTTP client (chat_client.py), error taxonomy (errors.py), payload coercion (payloads.py), node FSM (builder.py), models, and tree schedulerfrontend/- browser UI for tree inspection and session controlskills.py- runtime skill registry, hard-rule checking, and ToT prompt/plugin layerphysics_skills.py- generic SymPy computation skills (mechanics, EM, quantum, thermo, relativity, optics, fluids)benchmarks.py- benchmark fixtures (problems, expected values, per-case tool solutions) kept outside the skill registryskill_registry.md- human-readable map from problem classes to skill namesskills.md- skill calling conventions and usage guidancetests/- API, scheduler, FSM, and backend regression testsenvironment.yml- conda environment definitionexperiments/- reproducibility scripts and data for the paper (A/B harness, demonstrators, grounding-precision analysis); seeexperiments/README.mdreports/- A/B results andFINDINGS.mdPAPER.md- workshop paper: advisory symbolic step-verification in ToT physics reasoning
Run the API tests:
python -m unittest tests.test_apiRun the main harness regression suite:
python -m unittest tests.test_harness -v- Session state is stored in memory, not in a database.
- Session creation returns a session id immediately; deeper expansion can continue in the background when
run_on_createis enabled. - Each session stops expanding once it reaches
max_total_expansions(default 64, configurable per session or viaTOT_MAX_TOTAL_EXPANSIONS; unlimited when null). This bounds total model calls per session. - Local chat runs live-first by default.
allow_live_model_fallbackpermits deterministic local fallback only after transport failures, whileprefer_local_fallbackorPREFER_LOCAL_FALLBACK=1restores the older fast fallback-first behavior. - If you change backend code, restart
tot_api.pyso the running server picks up the new behavior. - Non-terminal evaluation is intentionally lighter-weight than terminal review.
- Node deletion is review-gated on the backend before a subtree is removed.
The repository is suitable for a controlled beta workflow: the API and FSM regression suites are in place, frontend and backend defaults are aligned, and the system is intended to be run locally against a compatible model backend.