Skip to content

Tree of Thought

weego edited this page May 28, 2026 · 1 revision

Tree of Thought

Tree of Thought is an optional planning mode. It asks a reasoning model to analyze the task before the final model request and can narrow the active tool set.

When to Use It

Use Tree of Thought for:

  • multi-step tasks
  • tool selection among many tools
  • planning before external actions
  • tasks where an initial reasoning pass improves reliability

Avoid it for simple chat, low-latency calls, or tasks where cost must be minimized.

Basic Configuration

agent = LightAgent(
    model="gpt-4.1",
    api_key="your_api_key",
    base_url="https://api.openai.com/v1",
    tree_of_thought=True,
    tot_model="gpt-4.1",
    tot_api_key="your_api_key",
    tot_base_url="https://api.openai.com/v1",
)

If tot_model, tot_api_key, or tot_base_url are omitted, LightAgent can fall back to the main model configuration.

Tool Filtering

By default, filter_tools=True. The planning step can decide which tools should be active for the final run.

Disable filtering when you want all registered tools to remain available:

agent = LightAgent(
    model="gpt-4.1",
    api_key="your_api_key",
    base_url="https://api.openai.com/v1",
    tree_of_thought=True,
    filter_tools=False,
)

Debugging

Use structured results and traces:

result = agent.run("Plan and execute this task.", result_format="object", trace=True)
print(result.content)
print(result.trace)

If the planning step chooses the wrong tools, make tool descriptions narrower and more explicit.

Clone this wiki locally