thinking

package
v1.261203.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 4, 2026 License: MPL-2.0 Imports: 2 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package thinking holds the canonical thinking-effort ladder shared across the gateway. It is a leaf package (no internal deps) so both internal/typ and the protocol conversion layer can import it without cycles.

Effort is the primary axis across providers: OpenAI reasoning_effort (none/minimal/low/medium/high/xhigh/max), Anthropic output_config.effort (low/medium/high/xhigh/max, Claude 4.5+), and Gemini 3 thinking_level (minimal/low/medium/high) are all effort-based. Token budgets remain only as the fallback dialect for budget-based targets (Claude ≤ 4.5 thinking.budget_tokens, Gemini 2.5 thinking_budget) via BudgetMapping / EffortFromBudget.

Index

Constants

This section is empty.

Variables

View Source
var BudgetMapping = map[Level]int64{
	LevelMinimal: 1024,
	LevelLow:     4096,
	LevelMedium:  10240,
	LevelHigh:    20480,
	LevelXHigh:   24576,
	LevelMax:     31999,
}

BudgetMapping defines fallback budget_tokens for each effort level, used only when the target speaks budgets instead of effort levels. "off" / "" are intentionally absent — they signal disabled / pass-through, not a budget value, and are handled out-of-band by the transform layer.

Functions

func AnthropicEffort added in v1.261001.1

func AnthropicEffort(level Level) string

AnthropicEffort maps a ladder level to Anthropic's output_config.effort value. Anthropic's ladder has no "minimal" (collapses to "low"); every other native value stays distinct so the model-aware vendor transform can clamp it against cataloged support. Unknown values fall back to "medium".

func DisableBetaForUnsignedToolTurn added in v1.261006.2

func DisableBetaForUnsignedToolTurn(req *anthropic.BetaMessageNewParams)

DisableBetaForUnsignedToolTurn is DisableV1ForUnsignedToolTurn for Beta requests.

func DisableV1ForUnsignedToolTurn added in v1.261006.2

func DisableV1ForUnsignedToolTurn(req *anthropic.MessageNewParams)

DisableV1ForUnsignedToolTurn turns budget thinking off when the request continues a tool-use turn whose assistant message carries no thinking block. With budget thinking enabled, Anthropic requires that final assistant message to start with a (signed) thinking block, and a client that never sees thinking blocks — an OpenAI client, or a rule forcing thinking_effort onto one — has none to send back. Run it before any model-specific thinking-block filtering, on the client's own history; a model with mandatory thinking then turns "disabled" into adaptive.

func ReconcileBetaWithRequest added in v1.261006.2

func ReconcileBetaWithRequest(req *anthropic.BetaMessageNewParams)

ReconcileBetaWithRequest is ReconcileV1WithRequest for Beta requests.

func ReconcileV1WithRequest added in v1.261006.2

func ReconcileV1WithRequest(req *anthropic.MessageNewParams)

ReconcileV1WithRequest makes the request's thinking legal on the Anthropic wire given the rest of the request. Callers decide where it runs (the OpenAI → Anthropic conversions and the Claude Code vendor path):

  • a tool-use turn with no thinking block turns budget thinking off (DisableV1ForUnsignedToolTurn);
  • forced tool use (tool_choice any / tool) turns thinking off, since Anthropic rejects it with thinking and the tool call is what the client needs;
  • otherwise the sampling parameters thinking forbids are dropped: temperature other than 1 and top_k; top_p is raised to 0.95.

Types

type Level

type Level = string

Level represents a thinking effort level for extended thinking.

const (
	// LevelDefault is the "by client" sentinel: pass the client's thinking
	// config through unchanged. Empty string so omitempty hides it.
	LevelDefault Level = ""
	// LevelOff is the "explicitly disabled" sentinel: strip thinking from the
	// outbound request regardless of what the client sent. (OpenAI's "none"
	// level maps here, not to a ladder entry.)
	LevelOff     Level = "off"
	LevelMinimal Level = "minimal"
	LevelLow     Level = "low"
	LevelMedium  Level = "medium"
	LevelHigh    Level = "high"
	LevelXHigh   Level = "xhigh"
	LevelMax     Level = "max"
)

func EffortFromBudget

func EffortFromBudget(budget int64) Level

EffortFromBudget is the inverse of BudgetMapping: it tiers an explicit budget_tokens value back onto the effort ladder. This is the single canonical budget→effort conversion for effort-based targets fed by budget-based clients. Thresholds are inclusive of each tier's own budget so the two mappings round-trip.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL