Skip to main content
Reasoning (extended thinking) lets supported models spend additional compute on internal reasoning before producing a final answer. Configure it per agent with WithLLMSampling and LLMReasoning. Fields are provider-agnostic — each LLM client maps them to its native API.

Configure

a, err := agent.NewAgent(
    agent.WithLLMClient(llmClient),
    agent.WithLLMSampling(&agent.LLMSampling{
        Reasoning: &interfaces.LLMReasoning{
            Enabled:      true,
            Effort:       "medium",  // OpenAI reasoning_effort; Gemini thinking level
            BudgetTokens: 4096,      // Anthropic / Gemini thinking budget
        },
    }),
)

Field mapping

FieldOpenAIAnthropicGemini
EnabledDoes not infer reasoning_effort alone — standard chat models reject that parameterIf BudgetTokens is 0, uses minimum 1024 tokens for extended thinkingHelps turn on thought output (IncludeThoughts)
EffortMaps to reasoning_effort when non-empty — use with reasoning-capable models onlyNot used for the thinking APIMaps to ThinkingLevel (low / medium / high / minimal) — only when BudgetTokens is 0
BudgetTokensNot usedExtended-thinking budget (≥1024 when non-zero; values below 1024 are clamped up)Maps to ThinkingBudget — wins over Effort when set
Gemini forbids setting both BudgetTokens and Effort (ThinkingLevel) together. If you set BudgetTokens, Effort is not sent as ThinkingLevel. Prefer BudgetTokens over Effort when targeting Gemini.
Anthropic extended thinking requires BudgetTokens ≥ 1024. The SDK clamps lower values to 1024 automatically.

Streaming

When the provider returns thinking deltas, streaming emits reasoning events:
EventWhen
AgentEventTypeReasoningStartReasoning block begins
AgentEventTypeReasoningMessageContentPartial thinking delta — Anthropic emits this as ThinkingDelta
AgentEventTypeReasoningEndReasoning block ends
See Streaming for event handling patterns.

Token usage

Reasoning tokens appear in LLMUsage.ReasoningTokens when the provider reports them. They are included in the aggregate on AgentRunResult.LLMUsage.

Example

Reasoning

Extended thinking on supported models

LLM Providers

Provider clients and model selection

Streaming

Reasoning stream events

Token Usage

ReasoningTokens in usage reports

Configuration

WithLLMSampling reference