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

# Reasoning & Extended Thinking

> Enable chain-of-thought reasoning for complex tasks

Some models can "think" before responding -- breaking down complex problems step by step. This improves accuracy for math, logic, coding, and analysis tasks.

## Anthropic Extended Thinking

```typescript theme={null}
const agent = new Agent({
  name: 'Math Tutor',
  instructions: 'Solve problems step by step.',
  model: anthropic('claude-sonnet-4-6'),
  modelConfig: {
    thinking: { type: 'enabled', budgetTokens: 10000 }
  }
});

const result = await agent.process({ message: 'What is 17! / 15!?' });
console.log(result.message); // "272"

// Thinking content available in traces (Portal > Executions)
```

## OpenAI Reasoning Models (o-series)

OpenAI's o-series models reason natively -- no configuration needed:

```typescript theme={null}
const agent = new Agent({
  name: 'Analyst',
  instructions: 'Analyze data carefully.',
  model: openai('o4-mini'),
});
```

Models: `o1`, `o3`, `o3-mini`, `o4-mini`

<Note>
  Reasoning models don't support `temperature`, `top_p`, `frequency_penalty`, `presence_penalty`, or `stop`. These parameters are automatically stripped.
</Note>

## Gemini Thinking

Gemini 2.5+ models support thinking with a token budget:

```typescript theme={null}
const agent = new Agent({
  name: 'Coder',
  instructions: 'Write clean code.',
  model: gemini('gemini-2.5-flash'),
  modelConfig: {
    thinking: { type: 'enabled', budgetTokens: 2048 }
  }
});
```

## xAI Reasoning Models

xAI Grok models with `-reasoning` in the name use chain-of-thought:

```typescript theme={null}
const agent = new Agent({
  name: 'Researcher',
  instructions: 'Research thoroughly.',
  model: xai('grok-4-1-fast-reasoning'),
});
```

## Thinking in Streaming

When using `processStream()`, thinking content arrives as separate chunks:

```typescript theme={null}
const stream = await agent.processStream({ message: 'Solve this equation...' });

for await (const chunk of stream) {
  if (chunk.type === 'thinking') {
    console.log('[Thinking]', chunk.data.content);
  } else if (chunk.type === 'content') {
    process.stdout.write(chunk.data.content);
  }
}
```

## Testing in Prompt Studio

Test thinking directly in the Portal without deploying an agent:

1. Go to **Prompts** and open any prompt
2. Click the **config icon** (sliders) in the top bar
3. Click **Thinking** to enable it (set budget tokens if needed)
4. Send a message -- the thinking content appears as a collapsible "Pensou sobre a resposta" block

Works with Anthropic and Gemini providers. OpenAI and xAI reasoning models think natively without the toggle.

## With LLM Standalone

```typescript theme={null}
const thinker = LLM.anthropic('claude-sonnet-4-6', {
  thinking: { type: 'enabled', budgetTokens: 8000 }
});

const result = await thinker.generate('Solve: if 2x + 5 = 17, what is x?');
console.log(result.text);      // "x = 6"
console.log(result.thinking);  // "Let me solve step by step: 2x + 5 = 17, 2x = 12, x = 6"
```

## Provider Support

| Provider  | How                      | Configuration                                    |
| --------- | ------------------------ | ------------------------------------------------ |
| Anthropic | `thinking` parameter     | `thinking: { type: 'enabled', budgetTokens: N }` |
| OpenAI    | Native (o-series models) | Just use o1/o3/o4-mini models                    |
| Gemini    | `thinkingConfig`         | `thinking: { type: 'enabled', budgetTokens: N }` |
| xAI       | Reasoning model names    | Use `grok-*-reasoning` models                    |
| Groq      | Not supported            | -                                                |
| Bedrock   | Not supported            | -                                                |

## Next Steps

<CardGroup cols={2}>
  <Card title="Structured Output" icon="brackets-curly" href="/advanced/structured-output">
    Get guaranteed JSON responses
  </Card>

  <Card title="Streaming" icon="bolt" href="/advanced/streaming">
    Real-time streaming responses
  </Card>
</CardGroup>
