spring-projects / spring-projects/spring-ai

Tree of Thoughts (ToT) Advisor/Module

Open
#5,703 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage
Dominant language
Java
Stars
9.5k
Forks
2.9k
Avg merge
1d 7h
Merged PRs (30d)
6

Description

Feature Request: Native Tree of Thoughts (ToT) Framework & Advisor Implementation

Pre-Check

I have searched all open and closed GitHub issues, and there is no existing feature request or implementation for a framework-level Tree of Thoughts (ToT) module. Only a basic manual prompt example exists in the official documentation.


Expected Behavior

I expect Spring AI to provide a native, reusable, Spring-idiomatic Tree of Thoughts (ToT) module integrated with the existing ChatClient and Advisors API, to support complex multi-path reasoning scenarios. The expected features include:

  1. Core Pluggable Abstractions

    • Standardized domain model Thought to represent nodes in the reasoning tree, including content, parent/child relationships, score, depth and other core attributes.
    • Three core strategy interfaces for full customization:
      • ThoughtGenerator: Generate multiple candidate reasoning steps/solutions for the current node.
      • ThoughtEvaluator: Score and evaluate the validity and feasibility of each generated thought (0.0-1.0).
      • SearchStrategy: Define tree traversal logic, with built-in implementations for BFS, DFS and Beam Search.
  2. Seamless Spring AI Ecosystem Integration

    • Implement TreeOfThoughtsAdvisor that directly fits the existing Advisor system, which can be added to ChatClient with zero additional code changes, consistent with the current developer experience.
    • Provide a fluent TreeOfThoughtsConfig builder to configure core parameters: max depth, candidates per step, evaluation threshold, custom strategy injection, etc.
  3. Out-of-the-Box Default Implementations

    • Provide production-ready default implementations for all core interfaces, so developers can enable ToT capability without writing custom logic.
    • Built-in optimized prompt templates for generation and evaluation, compatible with all major model providers supported by Spring AI.
  4. Developer-Friendly Usage

    • Support one-line enablement for ToT via default advisor, while allowing full customization of each component for advanced scenarios.
    • Expose full thought tree trace for debugging and observability, to help developers understand the model's reasoning process.

Current Behavior

Currently, Spring AI does not have a framework-level Tree of Thoughts implementation:

  1. Only a simplified manual prompt example is provided in the "Prompt Engineering Patterns" chapter of the official documentation, which is a hardcoded scenario demo, not a reusable general component.
  2. There is no dedicated ToT module or Advisor in the existing codebase, and no related abstractions for the ToT pattern.
  3. Developers have to write a large amount of repeated custom prompt logic, orchestration code and evaluation rules from scratch for complex reasoning scenarios (mathematical problem solving, strategic planning, code generation with multi-path exploration), which is inefficient, difficult to maintain, and inconsistent with Spring's "convention over configuration" philosophy.

Context
  • Industry Value: Tree of Thoughts is a critical advanced reasoning pattern that significantly improves LLM performance on complex tasks that require exploration and strategic thinking, which is a must-have capability for enterprise-level AI application development.
  • Ecosystem Parity: Other mainstream AI frameworks (LangChain, LangChain4j) have provided mature ToT implementations, and Spring AI's native support will fill this major gap and enhance the competitiveness of the framework.
  • Compatibility: The proposed design fully follows Spring AI's existing architecture, does not break any existing APIs, and can be released as an independent spring-ai-advisors-tree-of-thoughts module.
  • Reference: Official manual ToT example in documentation: https://docs.spring.io/spring-ai/reference/api/chat/prompt-engineering-patterns.html#_tree_of_thoughts_tot

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked Tree of Thoughts documentation example and inspect the existing ChatClient and Advisors APIs to understand how a framework-level integration would fit. Define the module scope, abstractions, configuration, default strategies, and trace behavior before implementation; done means a reusable ToT advisor with the requested customization and ecosystem integration.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
ai, backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.