Skip to content

Tree of Thoughts (ToT) Advisor/Module #5703

@Choujanse

Description

@Choujanse

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions