Skip to main content

Make your AI think before it speaks - advanced reasoning for LLMs

Project description

ThinkThread 🧵

Make your AI think before it speaks.

from thinkthread import reason

answer = reason("How can we solve climate change?")
# AI explores 20+ solutions, evaluates each one, and gives you the best path forward

Why ThinkThread?

Current LLMs give you their first thought. ThinkThread makes them actually think:

# ❌ Regular LLM
"To solve climate change, we need renewable energy."

# ✅ With ThinkThread
"I've explored 23 different approaches including renewable energy, nuclear power, 
carbon capture, and policy changes. Based on feasibility and impact analysis, 
here's a comprehensive strategy that could reduce emissions by 78% by 2040..."

Installation

pip install thinkthread

Set your LLM API key:

export OPENAI_API_KEY='sk-...'  # or ANTHROPIC_API_KEY

Quick Start

Python API

from thinkthread import reason, explore, solve, debate, refine

# One-liner reasoning
answer = reason("How do we make our app 10x faster?")

# Explore creative solutions
ideas = explore("New features for a todo app")

# Get actionable solutions
plan = solve("Reduce AWS costs by 50%")

# See multiple perspectives
analysis = debate("Should we use microservices?")

# Polish your content
better = refine("We need to fix the bug", "Make it professional")

Command Line

# General reasoning
think "What are the pros and cons of remote work?"

# Explore ideas
think explore "10 ways to improve developer productivity"

# Solve problems
think solve "Our API response time is 2.3 seconds"

# Analyze decisions
think debate "Kubernetes vs Docker Swarm"

# Test mode (no API calls)
think --test "How do we scale to 1M users?"

Key Features

  • 🔄 Chain-of-Recursive-Thoughts: Iteratively refines answers through multiple rounds
  • 🌳 Tree-of-Thoughts: Explores multiple reasoning paths in parallel
  • 🧪 Test Mode: Develop without API calls using test_mode=True
  • Simple API: Just 5 functions that do everything
  • 🛠️ Production Ready: Used in production by multiple companies
  • 📦 Zero Config: Works out of the box with just an API key

Real Examples

🔧 Problem Solving

problem = "Our deployment takes 45 minutes"
solution = solve(problem)

# Output: Comprehensive plan with:
# - Root cause analysis (Docker layers, test suite, artifacts)
# - 5 solutions ranked by impact
# - Step-by-step implementation
# - Expected deployment time: 8 minutes

💡 Creative Exploration

ideas = explore("SaaS product ideas for developers")

# Output: Tree of 15+ ideas like:
# - AI code review tool ($50K MRR potential)
# - Smart debugging assistant (integrates with IDEs)  
# - Automated documentation generator
# Each with market analysis and MVP requirements

🤔 Decision Analysis

decision = debate("Should we rewrite in Rust?")

# Output: Balanced analysis:
# - Performance gains: 3.2x faster, 70% less memory
# - Migration cost: 6 dev-months, $180K
# - Risk assessment: High initial, low long-term
# - Recommendation: Yes, if you have 6+ month runway

Advanced Usage

Direct SDK Access

For more control, access the underlying SDK:

from thinkthread import ThinkThreadSession, TreeThinker
from thinkthread.llm import OpenAIClient

# Custom configuration
client = OpenAIClient(api_key="...", model_name="gpt-4-turbo")
session = ThinkThreadSession(
    llm_client=client,
    alternatives=5,  # Generate 5 alternatives
    rounds=3,        # Refine for 3 rounds
)

# Run with full control
answer = session.run("Complex question requiring deep thought")

Async Operations

import asyncio
from thinkthread import ThinkThreadSession

async def think_async():
    session = ThinkThreadSession(llm_client=client)
    answer = await session.run_async("Explain quantum computing")
    return answer

# Run asynchronously
answer = asyncio.run(think_async())

Custom Evaluation

from thinkthread.evaluation import BaseEvaluator

class CustomEvaluator(BaseEvaluator):
    def evaluate(self, alternatives):
        # Your custom logic
        return best_alternative

session = ThinkThreadSession(
    llm_client=client,
    evaluation_strategy=CustomEvaluator()
)

How It Works

ThinkThread implements two powerful reasoning strategies:

  1. Chain-of-Recursive-Thoughts (CoRT)

    • Generates initial answer
    • Creates alternative answers
    • Evaluates all options
    • Selects the best one
    • Repeats for N rounds
  2. Tree-of-Thoughts (ToT)

    • Explores multiple solution paths
    • Expands promising branches
    • Prunes weak solutions
    • Finds optimal path

Both are proven techniques from cognitive science, now available for your AI.

When to Use Each Function

Function Best For Example
reason() General questions "Explain quantum computing"
explore() Creative tasks "Marketing campaign ideas"
solve() Specific problems "Fix memory leak in prod"
debate() Decisions "PostgreSQL vs MongoDB?"
refine() Improvement "Make this email better"

Contributing

We welcome contributions! Please see our Contributing Guide for details.

License

MIT - Use it freely in your projects.


Ready to make your AI think? Install with pip install thinkthread and start building smarter applications today.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

thinkthread-0.8.0.tar.gz (34.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

thinkthread-0.8.0-py3-none-any.whl (44.6 kB view details)

Uploaded Python 3

File details

Details for the file thinkthread-0.8.0.tar.gz.

File metadata

  • Download URL: thinkthread-0.8.0.tar.gz
  • Upload date:
  • Size: 34.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.12.7 Darwin/24.5.0

File hashes

Hashes for thinkthread-0.8.0.tar.gz
Algorithm Hash digest
SHA256 3069a48382ac57d71021edc2a9770636279799949348506ad99713a6dfb7ca0a
MD5 02aad9f6a3a7ca074e5e305b79272c3f
BLAKE2b-256 b24ee7bc64a14ddff4cba3d6b7869e1be97e2a6a3bd71cbaaabeab25917ee83a

See more details on using hashes here.

File details

Details for the file thinkthread-0.8.0-py3-none-any.whl.

File metadata

  • Download URL: thinkthread-0.8.0-py3-none-any.whl
  • Upload date:
  • Size: 44.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.12.7 Darwin/24.5.0

File hashes

Hashes for thinkthread-0.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f57df0231df9b4c752c5535a2c6f9e35f33f0622d1016a437b960992674d4af1
MD5 5a8842ea608824d596a9633c7b7d5661
BLAKE2b-256 bbd56623c821dd33b54470f73cf538cb41408ce1de03341285cf10952a631a5e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page