Skip to main content

Thinking Module

The thinking module provides configurable thinking budgets for LLM reasoning, allowing control over token and time budgets for extended thinking.

Installation

pip install praisonaiagents

Features

  • Token budgets for extended thinking
  • Time budgets for reasoning
  • Adaptive budget allocation
  • Budget tracking and reporting

Quick Start

from praisonaiagents import Agent
from praisonaiagents.thinking import ThinkingBudget

# Create a thinking budget
budget = ThinkingBudget(
    max_tokens=16000,
    max_time_seconds=60,
    adaptive=True
)

# Apply to agent
agent = Agent(
    name="Reasoner",
    instructions="You are a reasoning assistant.",
)
# Set thinking budget via property
agent.thinking_budget = budget

Classes

ThinkingBudget

Configure thinking budgets for agents.
from praisonaiagents.thinking import ThinkingBudget

budget = ThinkingBudget(
    max_tokens=16000,
    max_time_seconds=60,
    adaptive=True
)

Constructor

ParameterTypeDefaultDescription
max_tokensint8000Maximum thinking tokens
max_time_secondsint30Maximum thinking time
adaptiveboolFalseAdapt budget based on task

ThinkingConfig

Configuration for thinking behavior.
from praisonaiagents.thinking import ThinkingConfig

config = ThinkingConfig(
    enabled=True,
    budget=budget,
    show_thinking=False
)

Attributes

AttributeTypeDescription
enabledboolWhether thinking is enabled
budgetThinkingBudgetBudget configuration
show_thinkingboolShow thinking in output

ThinkingUsage

Track thinking usage.
from praisonaiagents.thinking import ThinkingUsage

usage = ThinkingUsage(
    tokens_used=5000,
    time_seconds=15.5
)

Attributes

AttributeTypeDescription
tokens_usedintTokens used for thinking
time_secondsfloatTime spent thinking
budget_remainingintRemaining token budget

ThinkingTracker

Track thinking across multiple calls.
from praisonaiagents.thinking import ThinkingTracker

tracker = ThinkingTracker()
tracker.record(usage)
print(tracker.total_tokens)
print(tracker.total_time)

Usage Examples

Basic Thinking Budget

from praisonaiagents import Agent
from praisonaiagents.thinking import ThinkingBudget

agent = Agent(
    name="Analyst",
    instructions="You are an analytical assistant.",
)
agent.thinking_budget = ThinkingBudget(max_tokens=16000)

# Agent will use extended thinking for complex tasks
result = agent.chat("Analyze the implications of quantum computing on cryptography")

Adaptive Budget

from praisonaiagents.thinking import ThinkingBudget

# Budget adapts based on task complexity
budget = ThinkingBudget(
    max_tokens=32000,
    adaptive=True  # Automatically adjusts based on task
)

agent = Agent(
    name="Researcher",
    instructions="You are a research assistant.",
)
agent.thinking_budget = budget

Time-Limited Thinking

from praisonaiagents.thinking import ThinkingBudget

# Limit thinking time for faster responses
budget = ThinkingBudget(
    max_tokens=16000,
    max_time_seconds=30  # Stop thinking after 30 seconds
)

Track Usage

from praisonaiagents.thinking import ThinkingTracker

tracker = ThinkingTracker()

# After agent runs
usage = agent.get_thinking_usage()
tracker.record(usage)

print(f"Total thinking tokens: {tracker.total_tokens}")
print(f"Total thinking time: {tracker.total_time}s")

Best Practices

  1. Set appropriate budgets - Balance quality vs. cost
  2. Use adaptive mode - Let the system optimize for task complexity
  3. Monitor usage - Track thinking costs over time
  4. Time limits - Set time limits for time-sensitive applications