Skip to main content
Control how many tokens an agent spends on extended reasoning before producing a response.
from praisonaiagents import Agent
from praisonaiagents.thinking import ThinkingBudget

agent = Agent(
    name="DeepThinker",
    instructions="Solve problems step by step.",
)
agent.thinking_budget = ThinkingBudget.high()
agent.start("Solve this optimisation problem...")
The user asks a hard reasoning question; the agent spends extended thinking tokens up to the configured ThinkingBudget before answering.

Quick Start

1

Set a Budget Level

Use predefined levels via the thinking_budget property after creating the agent.
from praisonaiagents import Agent
from praisonaiagents.thinking import ThinkingBudget

agent = Agent(name="Thinker", instructions="Reason carefully.")
agent.thinking_budget = ThinkingBudget.medium()  # 8,000 tokens
agent.start("Explain quantum entanglement simply.")
2

Custom Budget

Fine-tune token limits and adaptive scaling.
from praisonaiagents import Agent
from praisonaiagents.thinking import ThinkingBudget

budget = ThinkingBudget(
    max_tokens=12000,
    min_tokens=1000,
    adaptive=True,
    max_time_seconds=120.0,
)

agent = Agent(name="CustomThinker", instructions="Solve complex problems.")
agent.thinking_budget = budget
agent.start("Design a load-balancing strategy.")

How It Works

PhaseWhat happens
1. SetYou assign a ThinkingBudget to the agent
2. ThinkThe model reasons up to the token limit
3. AnswerThe agent returns the reasoned response

Budget Levels

Pre-configured levels for different task complexity:
LevelTokensUse case
minimal()2,000Quick answers
low()4,000Simple reasoning
medium()8,000Default balance
high()16,000Complex analysis
maximum()32,000Deep research
from praisonaiagents.thinking import ThinkingBudget

budget = ThinkingBudget.high()
tokens = budget.get_tokens_for_complexity(0.9)  # scales with complexity

CLI Usage

praisonai thinking status      # Show current budget
praisonai thinking set high    # Set budget level
praisonai thinking stats       # Show usage statistics

praisonai run --thinking

Pass --thinking <budget> on the praisonai run command to set an exact token budget for a one-off prompt:
# Use a numeric token budget
praisonai run --thinking 4096 "Explain quantum entanglement"

# Use a named level
praisonai run --thinking high "Solve this optimisation problem: ..."

# Use in --command mode
praisonai run --command my_agent.py --thinking 8000
--thinking is now correctly threaded through the direct-prompt path (praisonai run) in both --command and bare-prompt modes. Earlier releases raised a NameError on the direct-prompt path.
ValueTokensNotes
off0Disable extended thinking
minimal2,000Quick answers
low4,000Simple reasoning
medium8,000Balanced
high16,000Complex analysis
<int>ExactAny positive integer token budget
For persistent sessions, use praisonai thinking set <level> instead.

Usage Tracking

Track thinking utilisation across sessions:
from praisonaiagents.thinking import ThinkingBudget, ThinkingTracker

tracker = ThinkingTracker()
session = tracker.start_session(budget_tokens=8000)
tracker.end_session(session, tokens_used=5000, time_seconds=30.0)

summary = tracker.get_summary()
print(f"Average utilisation: {summary['average_utilization']:.1%}")

Best Practices

Use minimal() or low() for quick lookups; reserve high() or maximum() for multi-step analysis where reasoning depth matters.
Assign agent.thinking_budget after creating the agent — budgets are applied lazily with zero overhead when unset.
Set adaptive=True so token allocation scales with task complexity via get_tokens_for_complexity().
Use praisonai thinking stats to review utilisation before increasing budgets in production.

Token Budgeting

Manage overall token spend across agent runs

Reflection

Self-review loops for higher-quality outputs