> ## Documentation Index
> Fetch the complete documentation index at: https://praison.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Thinking Module

> Extended thinking budgets for LLM reasoning

# Thinking Module

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

## Installation

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
pip install praisonaiagents
```

## Features

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

## Quick Start

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
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.

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonaiagents.thinking import ThinkingBudget

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

#### Constructor

| Parameter          | Type   | Default | Description                |
| ------------------ | ------ | ------- | -------------------------- |
| `max_tokens`       | `int`  | `8000`  | Maximum thinking tokens    |
| `max_time_seconds` | `int`  | `30`    | Maximum thinking time      |
| `adaptive`         | `bool` | `False` | Adapt budget based on task |

### ThinkingConfig

Configuration for thinking behavior.

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonaiagents.thinking import ThinkingConfig

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

#### Attributes

| Attribute       | Type             | Description                 |
| --------------- | ---------------- | --------------------------- |
| `enabled`       | `bool`           | Whether thinking is enabled |
| `budget`        | `ThinkingBudget` | Budget configuration        |
| `show_thinking` | `bool`           | Show thinking in output     |

### ThinkingUsage

Track thinking usage.

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonaiagents.thinking import ThinkingUsage

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

#### Attributes

| Attribute          | Type    | Description              |
| ------------------ | ------- | ------------------------ |
| `tokens_used`      | `int`   | Tokens used for thinking |
| `time_seconds`     | `float` | Time spent thinking      |
| `budget_remaining` | `int`   | Remaining token budget   |

### ThinkingTracker

Track thinking across multiple calls.

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonaiagents.thinking import ThinkingTracker

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

## Usage Examples

### Basic Thinking Budget

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
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

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
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

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
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

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
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

## Related

* [Agent](/docs/sdk/praisonaiagents/agent/agent) - Agent configuration
* [LLM](/docs/sdk/praisonaiagents/llm/llm) - LLM configuration
* [Telemetry](/docs/sdk/praisonaiagents/telemetry) - Usage tracking
