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

# Thinking

> Add a reasoning phase before the agent generates responses.

The thinking layer adds a context-aware reasoning phase before the model generates its response. The agent analyzes the request, plans its approach, and considers available tools before executing.

## Enable Thinking

```python theme={null}
from definable.agent import Agent

# Simple enable
agent = Agent(model="gpt-4o", thinking=True)

output = await agent.arun("What are the pros and cons of microservices?")
print(output.content)

# Access reasoning steps
for step in output.reasoning_steps:
    print(f"[{step.title}] {step.reasoning}")
```

## Custom Configuration

```python theme={null}
from definable.agent.reasoning import Thinking

agent = Agent(
    model="gpt-4o",
    thinking=Thinking(
        model="gpt-4o-mini",            # Cheaper model for thinking
        instructions="Focus on trade-offs and practical considerations.",
    ),
)
```

<ParamField path="model" type="str | Model">
  Model for the thinking phase. Defaults to the agent's model.
</ParamField>

<ParamField path="instructions" type="str">
  Custom prompt for the thinking phase.
</ParamField>

## How It Works

1. Before calling the main model, the agent runs a thinking phase.
2. The thinking model receives the user message, system prompt, and available tool descriptions.
3. It produces reasoning steps (analysis, plan, considerations).
4. These steps are injected into the system prompt for the main model call.
5. The main model generates its response with the reasoning context.

## Streaming Thinking Events

```python theme={null}
async for event in agent.arun_stream("Explain quantum computing."):
    if event.event == "ReasoningStarted":
        print("Thinking...")
    elif event.event == "ReasoningStep":
        print(f"  [{event.step.title}] {event.step.reasoning}")
    elif event.event == "ReasoningCompleted":
        print("Done thinking.\n")
    elif event.event == "RunContent" and event.content:
        print(event.content, end="", flush=True)
```

## Imports

```python theme={null}
from definable.agent.reasoning import Thinking
```
