thinking

package
v0.61.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: BSD-2-Clause 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 provides unified thinking configuration processing.

This file implements suffix parsing functionality for extracting thinking configuration from model names in the format model(value).

Package thinking provides unified thinking configuration processing.

This package offers a unified interface for parsing, validating, and applying thinking configurations across various AI providers (Claude, Gemini, OpenAI, Codex, Antigravity, Kimi, xAI).

Index

Constants

View Source
const (
	// ThresholdMinimal is the upper bound for "minimal" level (1-512)
	ThresholdMinimal = 512
	// ThresholdLow is the upper bound for "low" level (513-1024)
	ThresholdLow = 1024
	// ThresholdMedium is the upper bound for "medium" level (1025-8192)
	ThresholdMedium = 8192
	// ThresholdHigh is the upper bound for "high" level (8193-24576)
	ThresholdHigh = 24576
	// ThresholdXHigh is the upper bound for "xhigh" level (24577-32768)
	ThresholdXHigh = 32768
)

BudgetThreshold constants define the upper bounds for each thinking level. These are used by ConvertBudgetToLevel for range-based mapping.

Variables

This section is empty.

Functions

func ConvertBudgetToLevel

func ConvertBudgetToLevel(budget int) (string, bool)

ConvertBudgetToLevel converts a budget value to its canonical thinking level.

This is a semantic conversion that maps numeric budgets to discrete levels. Uses threshold-based mapping for range conversion.

Budget → Level thresholds:

  • -1 → auto
  • 0 → none
  • 1-512 → minimal
  • 513-1024 → low
  • 1025-8192 → medium
  • 8193-24576 → high
  • 24577-32768 → xhigh
  • 32769+ → max

Returns:

  • level: The converted thinking level string
  • ok: true if budget is valid, false for invalid negatives (< -1)

func ConvertLevelToBudget

func ConvertLevelToBudget(level string) (int, bool)

ConvertLevelToBudget converts a thinking level to a budget value.

This is a semantic conversion that maps discrete levels to numeric budgets. Level matching is case-insensitive.

Level → Budget mapping:

  • none → 0
  • auto → -1
  • minimal → 512
  • low → 1024
  • medium → 8192
  • high → 24576
  • xhigh → 32768
  • max → 128000

Returns:

  • budget: The converted budget value
  • ok: true if level is valid, false otherwise

func HasLevel

func HasLevel(levels []string, target string) bool

HasLevel reports whether the given target level exists in the levels slice. Matching is case-insensitive with leading/trailing whitespace trimmed.

func MapToClaudeEffort

func MapToClaudeEffort(level string, supportsMax bool) (string, bool)

MapToClaudeEffort maps a generic thinking level string to a Claude adaptive thinking effort value (low/medium/high/max).

supportsMax indicates whether the target model supports "max" effort. Returns the mapped effort and true if the level is valid, or ("", false) otherwise.

func ParseNumericSuffix

func ParseNumericSuffix(rawSuffix string) (budget int, ok bool)

ParseNumericSuffix attempts to parse a raw suffix as a numeric budget value.

This function parses the raw suffix content (from ParseSuffix.RawSuffix) as an integer. Only non-negative integers are considered valid numeric suffixes.

Platform note: The budget value uses Go's int type, which is 32-bit on 32-bit systems and 64-bit on 64-bit systems. Values exceeding the platform's int range will return ok=false.

Leading zeros are accepted: "08192" parses as 8192.

Examples:

  • "8192" -> budget=8192, ok=true
  • "0" -> budget=0, ok=true (represents ModeNone)
  • "08192" -> budget=8192, ok=true (leading zeros accepted)
  • "-1" -> budget=0, ok=false (negative numbers are not valid numeric suffixes)
  • "high" -> budget=0, ok=false (not a number)
  • "9223372036854775808" -> budget=0, ok=false (overflow on 64-bit systems)

For special handling of -1 as auto mode, use ParseSpecialSuffix instead.

Types

type ModelCapability

type ModelCapability int

ModelCapability describes the thinking format support of a model.

const (
	// CapabilityUnknown indicates modelInfo is nil (passthrough behavior, internal use).
	CapabilityUnknown ModelCapability = iota - 1
	// CapabilityNone indicates model doesn't support thinking (Thinking is nil).
	CapabilityNone
	// CapabilityBudgetOnly indicates the model supports numeric budgets only.
	CapabilityBudgetOnly
	// CapabilityLevelOnly indicates the model supports discrete levels only.
	CapabilityLevelOnly
	// CapabilityHybrid indicates the model supports both budgets and levels.
	CapabilityHybrid
)

type SuffixResult

type SuffixResult struct {
	// ModelName is the model name with the suffix removed.
	// If no suffix was found, this equals the original input.
	ModelName string

	// HasSuffix indicates whether a valid suffix was found.
	HasSuffix bool

	// RawSuffix is the content inside the parentheses, without the parentheses.
	// Empty string if HasSuffix is false.
	RawSuffix string
}

SuffixResult represents the result of parsing a model name for thinking suffix.

A thinking suffix is specified in the format model-name(value), where value can be a numeric budget (e.g., "16384") or a level name (e.g., "high").

func ParseSuffix

func ParseSuffix(model string) SuffixResult

ParseSuffix extracts thinking suffix from a model name.

The suffix format is: model-name(value) Examples:

  • "claude-sonnet-4-5(16384)" -> ModelName="claude-sonnet-4-5", RawSuffix="16384"
  • "gpt-5.2(high)" -> ModelName="gpt-5.2", RawSuffix="high"
  • "gemini-2.5-pro" -> ModelName="gemini-2.5-pro", HasSuffix=false

This function only extracts the suffix; it does not validate or interpret the suffix content. Use ParseNumericSuffix, ParseLevelSuffix, etc. for content interpretation.

type ThinkingConfig

type ThinkingConfig struct {
	// Mode specifies the configuration mode
	Mode ThinkingMode
	// Budget is the thinking budget (token count), only effective when Mode is ModeBudget.
	// Special values: 0 means disabled, -1 means automatic
	Budget int
	// Level is the thinking level, only effective when Mode is ModeLevel
	Level ThinkingLevel
}

ThinkingConfig represents a unified thinking configuration.

This struct is used to pass thinking configuration information between components. Depending on Mode, either Budget or Level field is effective:

  • ModeNone: Budget=0, Level is ignored
  • ModeAuto: Budget=-1, Level is ignored
  • ModeBudget: Budget is a positive integer, Level is ignored
  • ModeLevel: Budget is ignored, Level is a valid level

type ThinkingLevel

type ThinkingLevel string

ThinkingLevel represents a discrete thinking level.

const (
	// LevelNone disables thinking
	LevelNone ThinkingLevel = "none"
	// LevelAuto enables automatic/dynamic thinking
	LevelAuto ThinkingLevel = "auto"
	// LevelMinimal sets minimal thinking effort
	LevelMinimal ThinkingLevel = "minimal"
	// LevelLow sets low thinking effort
	LevelLow ThinkingLevel = "low"
	// LevelMedium sets medium thinking effort
	LevelMedium ThinkingLevel = "medium"
	// LevelHigh sets high thinking effort
	LevelHigh ThinkingLevel = "high"
	// LevelXHigh sets extra-high thinking effort
	LevelXHigh ThinkingLevel = "xhigh"
	// LevelMax sets maximum thinking effort on models that support it.
	LevelMax ThinkingLevel = "max"
)

func ParseLevelSuffix

func ParseLevelSuffix(rawSuffix string) (level ThinkingLevel, ok bool)

ParseLevelSuffix attempts to parse a raw suffix as a discrete thinking level.

This function parses the raw suffix content (from ParseSuffix.RawSuffix) as a level. Only discrete effort levels are valid: minimal, low, medium, high, xhigh, max. Level matching is case-insensitive.

Special values (none, auto) are NOT handled by this function; use ParseSpecialSuffix instead. This separation allows callers to prioritize special value handling.

Examples:

  • "high" -> level=LevelHigh, ok=true
  • "HIGH" -> level=LevelHigh, ok=true (case insensitive)
  • "medium" -> level=LevelMedium, ok=true
  • "none" -> level="", ok=false (special value, use ParseSpecialSuffix)
  • "auto" -> level="", ok=false (special value, use ParseSpecialSuffix)
  • "8192" -> level="", ok=false (numeric, use ParseNumericSuffix)
  • "ultra" -> level="", ok=false (unknown level)

type ThinkingMode

type ThinkingMode int

ThinkingMode represents the type of thinking configuration mode.

const (
	// ModeBudget indicates using a numeric budget (corresponds to suffix "(1000)" etc.)
	ModeBudget ThinkingMode = iota
	// ModeLevel indicates using a discrete level (corresponds to suffix "(high)" etc.)
	ModeLevel
	// ModeNone indicates thinking is disabled (corresponds to suffix "(none)" or budget=0)
	ModeNone
	// ModeAuto indicates automatic/dynamic thinking (corresponds to suffix "(auto)" or budget=-1)
	ModeAuto
)

func ParseSpecialSuffix

func ParseSpecialSuffix(rawSuffix string) (mode ThinkingMode, ok bool)

ParseSpecialSuffix attempts to parse a raw suffix as a special thinking mode value.

This function handles special strings that represent a change in thinking mode:

  • "none" -> ModeNone (disables thinking)
  • "auto" -> ModeAuto (automatic/dynamic thinking)
  • "-1" -> ModeAuto (numeric representation of auto mode)

String values are case-insensitive.

func (ThinkingMode) String

func (m ThinkingMode) String() string

String returns the string representation of ThinkingMode.

Jump to

Keyboard shortcuts

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