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 ¶
- Variables
- func AnthropicEffort(level Level) string
- func DisableBetaForUnsignedToolTurn(req *anthropic.BetaMessageNewParams)
- func DisableV1ForUnsignedToolTurn(req *anthropic.MessageNewParams)
- func ReconcileBetaWithRequest(req *anthropic.BetaMessageNewParams)
- func ReconcileV1WithRequest(req *anthropic.MessageNewParams)
- type Level
Constants ¶
This section is empty.
Variables ¶
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
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 ¶
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.