Documentation
¶
Overview ¶
Package llm defines types and interfaces for Large Language Model interactions including message handlers, threads, configuration, and usage tracking for different LLM providers.
Index ¶
- Constants
- Variables
- func DefaultContextPatterns() []string
- func NormalizeOpenAITextVerbosity(config *Config) error
- func NormalizeReasoningConfig(config *Config) error
- func NormalizeReasoningEffort(raw string) (string, error)
- func ReasoningEffortOptions(config Config) []string
- type AnthropicAPIAccess
- type AnthropicConfig
- type BashConfig
- type Config
- type ConsoleMessageHandler
- func (h *ConsoleMessageHandler) HandleContentBlockEnd()
- func (h *ConsoleMessageHandler) HandleDone()
- func (h *ConsoleMessageHandler) HandleText(text string)
- func (h *ConsoleMessageHandler) HandleTextDelta(delta string)
- func (h *ConsoleMessageHandler) HandleThinking(thinking string)
- func (h *ConsoleMessageHandler) HandleThinkingBlockEnd()
- func (h *ConsoleMessageHandler) HandleThinkingDelta(delta string)
- func (h *ConsoleMessageHandler) HandleThinkingStart()
- func (h *ConsoleMessageHandler) HandleToolResult(_, _ string, result tooltypes.ToolResult)
- func (h *ConsoleMessageHandler) HandleToolUse(_ string, toolName string, input string)
- type ContextConfig
- type ConversationAnthropicSnapshot
- type ConversationConfigSnapshot
- type ConversationOpenAISnapshot
- type ConversationSummaryMode
- type CustomModels
- type CustomPricing
- type DeltaEntry
- type HeadlessStreamHandler
- func (h *HeadlessStreamHandler) HandleContentBlockEnd()
- func (h *HeadlessStreamHandler) HandleDone()
- func (h *HeadlessStreamHandler) HandleText(_ string)
- func (h *HeadlessStreamHandler) HandleTextDelta(delta string)
- func (h *HeadlessStreamHandler) HandleThinking(_ string)
- func (h *HeadlessStreamHandler) HandleThinkingBlockEnd()
- func (h *HeadlessStreamHandler) HandleThinkingDelta(delta string)
- func (h *HeadlessStreamHandler) HandleThinkingStart()
- func (h *HeadlessStreamHandler) HandleToolResult(_, _ string, _ tooltypes.ToolResult)
- func (h *HeadlessStreamHandler) HandleToolUse(_, _, _ string)
- type Message
- type MessageEvent
- type MessageHandler
- type MessageOpt
- type ModelPricing
- type OpenAIAPIMode
- type OpenAIConfig
- type OpenAIServiceTier
- type OpenAITextVerbosity
- type ProfileConfig
- type RetryConfig
- type SkillsConfig
- type StreamingMessageHandler
- type StringCollectorHandler
- func (h *StringCollectorHandler) CollectedText() string
- func (h *StringCollectorHandler) HandleContentBlockEnd()
- func (h *StringCollectorHandler) HandleDone()
- func (h *StringCollectorHandler) HandleText(text string)
- func (h *StringCollectorHandler) HandleTextDelta(delta string)
- func (h *StringCollectorHandler) HandleThinking(thinking string)
- func (h *StringCollectorHandler) HandleThinkingBlockEnd()
- func (h *StringCollectorHandler) HandleThinkingDelta(delta string)
- func (h *StringCollectorHandler) HandleThinkingStart()
- func (h *StringCollectorHandler) HandleToolResult(_, _ string, result tooltypes.ToolResult)
- func (h *StringCollectorHandler) HandleToolUse(_ string, toolName string, input string)
- type Thread
- type ToolMode
- type Usage
- type UsageMessageHandler
- type UserMessageHandler
Constants ¶
const ( // MinBashTimeout is the minimum timeout a bash tool call can request. MinBashTimeout = 10 * time.Second // DefaultBashTimeout is the default maximum timeout for bash tool calls. DefaultBashTimeout = 120 * time.Second // AnthropicAPIAccessAuto uses subscription auth if available, then falls back to API key AnthropicAPIAccessAuto AnthropicAPIAccess = "auto" // AnthropicAPIAccessSubscription forces use of subscription-based OAuth auth only AnthropicAPIAccessSubscription AnthropicAPIAccess = "subscription" // AnthropicAPIAccessAPIKey forces use of API key-based auth only AnthropicAPIAccessAPIKey AnthropicAPIAccess = "api-key" // ToolModeFull allows the standard direct file tools. ToolModeFull ToolMode = "full" // ToolModePatch restricts file operations to apply_patch plus search/navigation tools. ToolModePatch ToolMode = "patch" // ConversationSummaryModeLLM generates a short summary via an LLM. ConversationSummaryModeLLM ConversationSummaryMode = "llm" // ConversationSummaryModeFirstMessage uses the first user message as the summary. ConversationSummaryModeFirstMessage ConversationSummaryMode = "first_message" // DefaultCompactRatio is the default context window utilization threshold for automatic compaction. DefaultCompactRatio = 0.8 )
const ( // OpenAIAPIModeChatCompletions routes requests via chat completions API. OpenAIAPIModeChatCompletions OpenAIAPIMode = "chat_completions" // OpenAIAPIModeResponses routes requests via responses API. OpenAIAPIModeResponses OpenAIAPIMode = "responses" // OpenAIServiceTierAuto defers to the project default service tier. OpenAIServiceTierAuto OpenAIServiceTier = "auto" // OpenAIServiceTierDefault uses the standard service tier. OpenAIServiceTierDefault OpenAIServiceTier = "default" // OpenAIServiceTierFast is the Codex-friendly alias for priority processing. OpenAIServiceTierFast OpenAIServiceTier = "fast" // OpenAIServiceTierFlex requests flex processing. OpenAIServiceTierFlex OpenAIServiceTier = "flex" // OpenAIServiceTierPriority requests priority processing. OpenAIServiceTierPriority OpenAIServiceTier = "priority" // OpenAIServiceTierScale requests scale processing when supported. OpenAIServiceTierScale OpenAIServiceTier = "scale" // OpenAITextVerbosityLow requests concise text responses. OpenAITextVerbosityLow OpenAITextVerbosity = "low" // OpenAITextVerbosityMedium requests moderately detailed text responses. OpenAITextVerbosityMedium OpenAITextVerbosity = "medium" // OpenAITextVerbosityHigh requests verbose text responses. OpenAITextVerbosityHigh OpenAITextVerbosity = "high" )
const ( EventTypeThinking = "thinking" EventTypeText = "text" EventTypeToolUse = "tool_use" EventTypeToolResult = "tool_result" // Streaming event types EventTypeTextDelta = "text_delta" EventTypeThinkingStart = "thinking_start" EventTypeThinkingDelta = "thinking_delta" EventTypeThinkingBlockEnd = "thinking_block_end" EventTypeContentBlockEnd = "content_block_end" )
Event types
const ( InitiatorUser = "user" InitiatorAgent = "agent" )
const ConversationConfigSnapshotVersion = 1
const DefaultReasoningEffort = "medium"
Variables ¶
var DefaultRetryConfig = RetryConfig{
Attempts: 3,
InitialDelay: 1000,
MaxDelay: 10000,
BackoffType: "exponential",
}
DefaultRetryConfig holds the default retry configuration
Functions ¶
func DefaultContextPatterns ¶
func DefaultContextPatterns() []string
DefaultContextPatterns returns the default context file patterns.
func NormalizeOpenAITextVerbosity ¶
NormalizeOpenAITextVerbosity validates and canonicalizes an explicitly configured Responses API text verbosity while preserving the unset state.
func NormalizeReasoningConfig ¶
NormalizeReasoningConfig normalizes the configured effort and validates its optional selection policy. The policy applies when creating conversations; persisted conversation snapshots are allowed to outlive later policy changes.
func NormalizeReasoningEffort ¶
NormalizeReasoningEffort normalizes and validates a reasoning effort value.
func ReasoningEffortOptions ¶
ReasoningEffortOptions returns the selectable efforts for a new conversation. An explicit policy is authoritative. Without one, all efforts supported by the configured provider are exposed; unknown providers fall back to the configured value.
Types ¶
type AnthropicAPIAccess ¶
type AnthropicAPIAccess string
AnthropicAPIAccess defines the mode for Anthropic API access
type AnthropicConfig ¶
type AnthropicConfig struct {
Platform string `mapstructure:"platform" json:"platform" yaml:"platform"` // Canonical platform name for Anthropic-compatible APIs (e.g., anthropic, copilot)
BaseURL string `mapstructure:"base_url" json:"base_url" yaml:"base_url"` // Custom API base URL (overrides platform defaults)
AdaptiveThinking bool `mapstructure:"adaptive_thinking" json:"adaptive_thinking,omitempty" yaml:"adaptive_thinking,omitempty"` // Forces Anthropic adaptive-thinking request plumbing for the configured custom model ID when true
}
AnthropicConfig holds Anthropic-specific configuration including compatible platforms.
type BashConfig ¶
type BashConfig struct {
Timeout time.Duration `mapstructure:"timeout" json:"timeout" yaml:"timeout"` // Timeout is the maximum allowed timeout for a bash tool call
}
BashConfig holds configuration for the bash tool.
func (BashConfig) MarshalJSON ¶
func (c BashConfig) MarshalJSON() ([]byte, error)
MarshalJSON renders durations as config-friendly strings instead of nanoseconds.
func (BashConfig) MarshalYAML ¶
func (c BashConfig) MarshalYAML() (any, error)
MarshalYAML renders durations as config-friendly strings instead of nanoseconds.
type Config ¶
type Config struct {
IsSubAgent bool `mapstructure:"is_sub_agent" json:"is_sub_agent" yaml:"is_sub_agent"` // IsSubAgent is true if the LLM is a sub-agent
Provider string `mapstructure:"provider" json:"provider" yaml:"provider"` // Provider is the LLM provider (anthropic, openai)
Model string `mapstructure:"model" json:"model" yaml:"model"` // Model is the main driver
WeakModel string `mapstructure:"weak_model" json:"weak_model" yaml:"weak_model"` // WeakModel is the less capable but faster model to use
MaxTokens int `mapstructure:"max_tokens" json:"max_tokens" yaml:"max_tokens"`
WeakModelMaxTokens int `mapstructure:"weak_model_max_tokens" json:"weak_model_max_tokens" yaml:"weak_model_max_tokens"` // WeakModelMaxTokens is the maximum tokens for the weak model
ThinkingBudgetTokens int `mapstructure:"thinking_budget_tokens" json:"thinking_budget_tokens" yaml:"thinking_budget_tokens"` // ThinkingBudgetTokens is sent as Anthropic manual budget_tokens on non-adaptive Claude models; adaptive Claude models ignore it
ReasoningEffort string `mapstructure:"reasoning_effort" json:"reasoning_effort" yaml:"reasoning_effort"` // ReasoningEffort controls supported provider effort settings (e.g. OpenAI reasoning models, Anthropic adaptive thinking models where "none" disables adaptive thinking)
AllowedReasoningEfforts []string `` // AllowedReasoningEfforts restricts selectable reasoning efforts for new conversations (empty means unrestricted)
/* 126-byte string literal not displayed */
AllowedCommands []string `mapstructure:"allowed_commands" json:"allowed_commands" yaml:"allowed_commands"` // AllowedCommands is a list of allowed command patterns for the bash tool
AllowedDomainsFile string `mapstructure:"allowed_domains_file" json:"allowed_domains_file" yaml:"allowed_domains_file"` // AllowedDomainsFile is the path to the file containing allowed domains for web_fetch tool
AllowedTools []string `mapstructure:"allowed_tools" json:"allowed_tools" yaml:"allowed_tools"` // AllowedTools is a list of allowed tools for the main agent (empty means use defaults)
WorkingDirectory string `mapstructure:"working_directory" json:"working_directory" yaml:"working_directory"`
ToolMode ToolMode `mapstructure:"tool_mode" json:"tool_mode" yaml:"tool_mode"` // ToolMode controls file-interaction behavior (e.g. full or patch)
AnthropicAPIAccess AnthropicAPIAccess `mapstructure:"anthropic_api_access" json:"anthropic_api_access" yaml:"anthropic_api_access"` // AnthropicAPIAccess controls how to authenticate with Anthropic API
AnthropicAccount string `mapstructure:"anthropic_account" json:"anthropic_account" yaml:"anthropic_account"` // AnthropicAccount specifies which Anthropic subscription account to use
Aliases map[string]string `mapstructure:"aliases" json:"aliases,omitempty" yaml:"aliases,omitempty"` // Aliases maps short model names to full model names
ModelAliasesResolved bool `mapstructure:"-" json:"-" yaml:"-"` // ModelAliasesResolved prevents effective model names from being resolved as aliases again
Retry RetryConfig `mapstructure:"retry" json:"retry" yaml:"retry"` // Retry configuration for API calls
Sysprompt string `mapstructure:"sysprompt" json:"sysprompt,omitempty" yaml:"sysprompt,omitempty"` // Sysprompt is the path to a custom system prompt template file
SyspromptArgs map[string]string `mapstructure:"sysprompt_args" json:"sysprompt_args,omitempty" yaml:"sysprompt_args,omitempty"` // SyspromptArgs are custom template arguments for system prompt rendering
Bash *BashConfig `mapstructure:"bash" json:"bash,omitempty" yaml:"bash,omitempty"` // Bash contains bash tool configuration
// Profile system configuration
Profile string `mapstructure:"profile" json:"profile,omitempty" yaml:"profile,omitempty"` // Active profile name
Profiles map[string]ProfileConfig `mapstructure:"profiles" json:"profiles,omitempty" yaml:"profiles,omitempty"` // Named configuration profiles
// Provider-specific configurations
OpenAI *OpenAIConfig `mapstructure:"openai" json:"openai,omitempty" yaml:"openai,omitempty"` // OpenAI-specific configuration including compatible providers
Anthropic *AnthropicConfig `mapstructure:"anthropic" json:"anthropic,omitempty" yaml:"anthropic,omitempty"` // Anthropic-specific configuration including compatible providers
// Skills configuration
Skills *SkillsConfig `mapstructure:"skills" json:"skills,omitempty" yaml:"skills,omitempty"` // Skills configuration for agentic skills system
// Context configuration
Context *ContextConfig `mapstructure:"context" json:"context,omitempty" yaml:"context,omitempty"` // Context configuration for context file discovery
// Runtime feature toggle configuration
Extensions any `mapstructure:"-" json:"-" yaml:"-"` // Extensions is the active extension runtime for lifecycle events
EnableFSSearchTools bool `mapstructure:"enable_fs_search_tools" json:"enable_fs_search_tools" yaml:"enable_fs_search_tools"` // EnableFSSearchTools enables glob_tool and grep_tool and updates prompt/tool guidance accordingly
ConversationSummaryMode ConversationSummaryMode `mapstructure:"conversation_summary_mode" json:"conversation_summary_mode" yaml:"conversation_summary_mode"` // ConversationSummaryMode controls whether persisted conversation summaries come from the LLM or first user message
RecipeName string `mapstructure:"recipe_name" json:"recipe_name" yaml:"recipe_name"` // RecipeName is the active recipe/fragment name for extension context metadata
CompactRatio float64 `mapstructure:"compact_ratio" json:"compact_ratio" yaml:"compact_ratio"` // CompactRatio is the context utilization threshold for automatic compaction (>0.0-1.0)
}
Config holds the configuration for the LLM client
func (Config) BashTimeout ¶
BashTimeout returns the configured bash tool timeout, or the default if unset.
type ConsoleMessageHandler ¶
type ConsoleMessageHandler struct {
Silent bool
}
ConsoleMessageHandler prints messages to the console
func (*ConsoleMessageHandler) HandleContentBlockEnd ¶
func (h *ConsoleMessageHandler) HandleContentBlockEnd()
HandleContentBlockEnd prints a newline when a content block ends unless Silent is true
func (*ConsoleMessageHandler) HandleDone ¶
func (h *ConsoleMessageHandler) HandleDone()
HandleDone is called when message processing is complete
func (*ConsoleMessageHandler) HandleText ¶
func (h *ConsoleMessageHandler) HandleText(text string)
HandleText prints the text to the console unless Silent is true
func (*ConsoleMessageHandler) HandleTextDelta ¶
func (h *ConsoleMessageHandler) HandleTextDelta(delta string)
HandleTextDelta prints streamed text chunks to the console unless Silent is true
func (*ConsoleMessageHandler) HandleThinking ¶
func (h *ConsoleMessageHandler) HandleThinking(thinking string)
HandleThinking prints thinking content to the console unless Silent is true
func (*ConsoleMessageHandler) HandleThinkingBlockEnd ¶
func (h *ConsoleMessageHandler) HandleThinkingBlockEnd()
HandleThinkingBlockEnd prints a separator when a thinking block ends unless Silent is true
func (*ConsoleMessageHandler) HandleThinkingDelta ¶
func (h *ConsoleMessageHandler) HandleThinkingDelta(delta string)
HandleThinkingDelta prints streamed thinking chunks to the console unless Silent is true
func (*ConsoleMessageHandler) HandleThinkingStart ¶
func (h *ConsoleMessageHandler) HandleThinkingStart()
HandleThinkingStart prints the thinking prefix to the console unless Silent is true
func (*ConsoleMessageHandler) HandleToolResult ¶
func (h *ConsoleMessageHandler) HandleToolResult(_, _ string, result tooltypes.ToolResult)
HandleToolResult prints tool execution results to the console unless Silent is true
func (*ConsoleMessageHandler) HandleToolUse ¶
func (h *ConsoleMessageHandler) HandleToolUse(_ string, toolName string, input string)
HandleToolUse prints tool invocation details to the console unless Silent is true
type ContextConfig ¶
type ContextConfig struct {
// Patterns is a list of filenames to search for in each directory.
// Default is ["AGENTS.md"]. Files are searched in order; first match wins per directory.
Patterns []string `mapstructure:"patterns" json:"patterns" yaml:"patterns"`
}
ContextConfig holds configuration for context file discovery. Context files provide project-specific instructions and guidelines to the agent.
type ConversationAnthropicSnapshot ¶
type ConversationAnthropicSnapshot struct {
Platform string `json:"platform,omitempty" yaml:"platform,omitempty"`
AdaptiveThinking bool `json:"adaptive_thinking,omitempty" yaml:"adaptive_thinking,omitempty"`
}
ConversationAnthropicSnapshot captures Anthropic request semantics that must remain stable for custom/adaptive-thinking models.
type ConversationConfigSnapshot ¶
type ConversationConfigSnapshot struct {
Version int `json:"version" yaml:"version"`
Profile string `json:"profile,omitempty" yaml:"profile,omitempty"`
Provider string `json:"provider" yaml:"provider"`
Model string `json:"model" yaml:"model"`
WeakModel string `json:"weak_model,omitempty" yaml:"weak_model,omitempty"`
MaxTokens int `json:"max_tokens,omitempty" yaml:"max_tokens,omitempty"`
WeakModelMaxTokens int `json:"weak_model_max_tokens,omitempty" yaml:"weak_model_max_tokens,omitempty"`
ThinkingBudgetTokens int `json:"thinking_budget_tokens,omitempty" yaml:"thinking_budget_tokens,omitempty"`
ReasoningEffort string `json:"reasoning_effort" yaml:"reasoning_effort"`
ConversationSummaryMode ConversationSummaryMode `json:"conversation_summary_mode,omitempty" yaml:"conversation_summary_mode,omitempty"`
CompactRatio float64 `json:"compact_ratio,omitempty" yaml:"compact_ratio,omitempty"`
OpenAI *ConversationOpenAISnapshot `json:"openai,omitempty" yaml:"openai,omitempty"`
Anthropic *ConversationAnthropicSnapshot `json:"anthropic,omitempty" yaml:"anthropic,omitempty"`
}
ConversationConfigSnapshot captures immutable model and provider request settings for a persisted conversation. Runtime credentials, endpoints, prompt/context inputs, tool permissions, extensions, and other live policy remain sourced from current configuration.
func CloneConversationConfigSnapshot ¶
func CloneConversationConfigSnapshot(snapshot *ConversationConfigSnapshot) *ConversationConfigSnapshot
CloneConversationConfigSnapshot returns a deep copy suitable for forks and service responses.
func NewConversationConfigSnapshot ¶
func NewConversationConfigSnapshot(config Config) (*ConversationConfigSnapshot, error)
NewConversationConfigSnapshot creates a safe, versioned snapshot from the effective configuration used to construct a thread.
func (*ConversationConfigSnapshot) Apply ¶
func (s *ConversationConfigSnapshot) Apply(config Config) (Config, error)
Apply overlays immutable snapshot values onto current live configuration. Creation-time reasoning policy is cleared so an existing conversation remains resumable after allowed_reasoning_efforts changes.
func (*ConversationConfigSnapshot) Validate ¶
func (s *ConversationConfigSnapshot) Validate() error
Validate validates a persisted configuration snapshot.
type ConversationOpenAISnapshot ¶
type ConversationOpenAISnapshot struct {
Platform string `json:"platform,omitempty" yaml:"platform,omitempty"`
APIMode OpenAIAPIMode `json:"api_mode,omitempty" yaml:"api_mode,omitempty"`
TextVerbosity OpenAITextVerbosity `json:"text_verbosity,omitempty" yaml:"text_verbosity,omitempty"`
ServiceTier OpenAIServiceTier `json:"service_tier,omitempty" yaml:"service_tier,omitempty"`
ManualCache bool `json:"manual_cache,omitempty" yaml:"manual_cache,omitempty"`
Models *CustomModels `json:"models,omitempty" yaml:"models,omitempty"`
Pricing map[string]ModelPricing `json:"pricing,omitempty" yaml:"pricing,omitempty"`
}
ConversationOpenAISnapshot captures OpenAI request semantics that must remain stable to interpret and continue a persisted thread.
type ConversationSummaryMode ¶
type ConversationSummaryMode string
ConversationSummaryMode defines how persisted conversation summaries are produced.
func (ConversationSummaryMode) UsesLLM ¶
func (m ConversationSummaryMode) UsesLLM() bool
UsesLLM reports whether conversation summaries should be generated via an LLM.
type CustomModels ¶
type CustomModels struct {
Reasoning []string `mapstructure:"reasoning" json:"reasoning" yaml:"reasoning"` // Models that support reasoning (o1, o3, etc.)
NonReasoning []string `mapstructure:"non_reasoning" json:"non_reasoning" yaml:"non_reasoning"` // Models that don't support reasoning (gpt-4, etc.)
}
CustomModels holds model categorization for custom configurations
type CustomPricing ¶
type CustomPricing map[string]ModelPricing
CustomPricing maps model names to their pricing information
type DeltaEntry ¶
type DeltaEntry struct {
Kind string `json:"kind"`
Delta string `json:"delta,omitempty"`
Content string `json:"content,omitempty"`
ConversationID string `json:"conversation_id"`
Role string `json:"role"`
}
DeltaEntry represents a streaming delta event for headless mode output
type HeadlessStreamHandler ¶
type HeadlessStreamHandler struct {
// contains filtered or unexported fields
}
HeadlessStreamHandler outputs streaming events as JSON to stdout for headless mode with --stream-deltas enabled.
func NewHeadlessStreamHandler ¶
func NewHeadlessStreamHandler(conversationID string) *HeadlessStreamHandler
NewHeadlessStreamHandler creates a new HeadlessStreamHandler with the given conversation ID
func (*HeadlessStreamHandler) HandleContentBlockEnd ¶
func (h *HeadlessStreamHandler) HandleContentBlockEnd()
HandleContentBlockEnd outputs content block end event
func (*HeadlessStreamHandler) HandleDone ¶
func (h *HeadlessStreamHandler) HandleDone()
HandleDone is called when message processing is complete
func (*HeadlessStreamHandler) HandleText ¶
func (h *HeadlessStreamHandler) HandleText(_ string)
HandleText is a no-op as complete text is handled by ConversationStreamer
func (*HeadlessStreamHandler) HandleTextDelta ¶
func (h *HeadlessStreamHandler) HandleTextDelta(delta string)
HandleTextDelta outputs text delta events
func (*HeadlessStreamHandler) HandleThinking ¶
func (h *HeadlessStreamHandler) HandleThinking(_ string)
HandleThinking is a no-op as complete thinking is handled by ConversationStreamer
func (*HeadlessStreamHandler) HandleThinkingBlockEnd ¶
func (h *HeadlessStreamHandler) HandleThinkingBlockEnd()
HandleThinkingBlockEnd outputs thinking block end event
func (*HeadlessStreamHandler) HandleThinkingDelta ¶
func (h *HeadlessStreamHandler) HandleThinkingDelta(delta string)
HandleThinkingDelta outputs thinking delta events
func (*HeadlessStreamHandler) HandleThinkingStart ¶
func (h *HeadlessStreamHandler) HandleThinkingStart()
HandleThinkingStart outputs thinking block start event
func (*HeadlessStreamHandler) HandleToolResult ¶
func (h *HeadlessStreamHandler) HandleToolResult(_, _ string, _ tooltypes.ToolResult)
HandleToolResult is a no-op as tool results are handled by ConversationStreamer
func (*HeadlessStreamHandler) HandleToolUse ¶
func (h *HeadlessStreamHandler) HandleToolUse(_, _, _ string)
HandleToolUse is a no-op as tool calls are handled by ConversationStreamer
type MessageEvent ¶
MessageEvent represents an event from processing a message
type MessageHandler ¶
type MessageHandler interface {
HandleText(text string)
HandleToolUse(toolCallID string, toolName string, input string)
HandleToolResult(toolCallID string, toolName string, result tooltypes.ToolResult)
HandleThinking(thinking string)
HandleDone()
}
MessageHandler defines how message events should be processed
type MessageOpt ¶
type MessageOpt struct {
// Initiator identifies whether a Copilot-backed request originated from the user or agent internals.
// Empty means "user".
Initiator string
// PromptCache indicates if prompt caching should be used
PromptCache bool
// UseWeakModel allows temporarily overriding the model for this message
UseWeakModel bool
// NoToolUse indicates that no tool use should be performed
NoToolUse bool
// NoSaveConversation indicates that the following conversation should not be saved
NoSaveConversation bool
// Images contains image paths or URLs to include with the message
Images []string
// MaxTurns limits the number of turns within a single SendMessage call
// A value of 0 means no limit, and negative values are treated as 0
MaxTurns int
// CompactRatio is the ratio of context window at which to trigger auto-compact (>0.0-1.0).
// A zero value uses the thread/configured default; it does not disable auto-compaction.
CompactRatio float64
// DisableUsageLog disables LLM usage logging for this message
DisableUsageLog bool
}
MessageOpt represents options for sending messages
func (MessageOpt) ResolvedInitiator ¶
func (o MessageOpt) ResolvedInitiator() string
ResolvedInitiator returns the normalized initiator, defaulting to user.
func (MessageOpt) WithInitiator ¶
func (o MessageOpt) WithInitiator(initiator string) MessageOpt
WithInitiator returns a copy with the provided initiator set.
func (MessageOpt) WithTurnInitiator ¶
func (o MessageOpt) WithTurnInitiator(turnCount int) MessageOpt
WithTurnInitiator returns a copy whose initiator is derived from whether the message is the first user-facing turn or an internal follow-up turn.
type ModelPricing ¶
type ModelPricing struct {
// Input token cost per token.
Input float64 `mapstructure:"input" json:"input" yaml:"input"`
// Cached input token cost per token.
CachedInput float64 `mapstructure:"cached_input" json:"cached_input" yaml:"cached_input"`
// Cache write input token cost per token.
CacheWriteInput float64 `mapstructure:"cache_write_input" json:"cache_write_input" yaml:"cache_write_input"`
// Output token cost per token.
Output float64 `mapstructure:"output" json:"output" yaml:"output"`
// Long-context input token cost per token.
LongContextInput float64 `mapstructure:"long_context_input" json:"long_context_input,omitempty" yaml:"long_context_input,omitempty"`
// Long-context cached input token cost per token.
LongContextCachedInput float64 `` /* 126-byte string literal not displayed */
// Long-context cache write input token cost per token.
LongContextCacheWriteInput float64 `` /* 141-byte string literal not displayed */
// Long-context output token cost per token.
LongContextOutput float64 `mapstructure:"long_context_output" json:"long_context_output,omitempty" yaml:"long_context_output,omitempty"`
// Prompt token threshold for long-context pricing.
LongContextThreshold int `mapstructure:"long_context_threshold" json:"long_context_threshold,omitempty" yaml:"long_context_threshold,omitempty"`
// Maximum context window size.
ContextWindow int `mapstructure:"context_window" json:"context_window" yaml:"context_window"`
}
ModelPricing holds the per-token pricing for different operations
func (ModelPricing) ForPromptTokens ¶
func (p ModelPricing) ForPromptTokens(promptTokens int) ModelPricing
ForPromptTokens returns long-context pricing when the configured prompt token threshold is exceeded. OpenAI applies long-context rates to the full session, not just the tokens above the threshold.
type OpenAIAPIMode ¶
type OpenAIAPIMode string
OpenAIAPIMode defines which OpenAI-compatible API surface to use.
type OpenAIConfig ¶
type OpenAIConfig struct {
Platform string `mapstructure:"platform" json:"platform" yaml:"platform"` // Canonical platform name for OpenAI-compatible APIs (e.g., openai, codex, fireworks)
BaseURL string `mapstructure:"base_url" json:"base_url" yaml:"base_url"` // Custom API base URL (overrides platform defaults)
APIKeyEnvVar string `mapstructure:"api_key_env_var" json:"api_key_env_var" yaml:"api_key_env_var"` // Environment variable name for API key (overrides platform default)
APIMode OpenAIAPIMode `mapstructure:"api_mode" json:"api_mode" yaml:"api_mode"` // Preferred API mode selection (chat_completions or responses)
TextVerbosity OpenAITextVerbosity `mapstructure:"text_verbosity" json:"text_verbosity" yaml:"text_verbosity"` // Optional Responses API text verbosity (low, medium, or high); omitted values use the upstream default
ServiceTier OpenAIServiceTier `mapstructure:"service_tier" json:"service_tier" yaml:"service_tier"` // Optional service tier hint (e.g. auto, default, fast, flex, priority, scale)
EnableSearch *bool `mapstructure:"enable_search" json:"enable_search,omitempty" yaml:"enable_search,omitempty"` // Enable native OpenAI Responses web_search tool when supported (defaults to true)
WebSocketMode *bool `mapstructure:"websocket_mode" json:"websocket_mode,omitempty" yaml:"websocket_mode,omitempty"` // Use Responses API WebSocket transport when supported (defaults to true)
ManualCache bool `mapstructure:"manual_cache" json:"manual_cache" yaml:"manual_cache"` // Enables manual cache affinity headers for Chat Completions when prompt caching is requested
Models *CustomModels `mapstructure:"models" json:"models,omitempty" yaml:"models,omitempty"` // Custom model configuration
Pricing map[string]ModelPricing `mapstructure:"pricing" json:"pricing,omitempty" yaml:"pricing,omitempty"` // Custom pricing configuration
}
OpenAIConfig holds OpenAI-specific configuration including support for compatible APIs
type OpenAIServiceTier ¶
type OpenAIServiceTier string
OpenAIServiceTier defines the optional OpenAI service tier preference. Kodelet accepts the native OpenAI values plus Codex's user-facing `fast` alias, which is sent to the API as `priority`.
func ParseOpenAIServiceTier ¶
func ParseOpenAIServiceTier(raw string) (OpenAIServiceTier, bool)
ParseOpenAIServiceTier normalizes and validates a configured service tier.
func (OpenAIServiceTier) WireValue ¶
func (t OpenAIServiceTier) WireValue() string
WireValue returns the value that should be sent to the upstream API.
type OpenAITextVerbosity ¶
type OpenAITextVerbosity string
OpenAITextVerbosity controls the detail level of generated OpenAI Responses text.
func ConfiguredOpenAITextVerbosity ¶
func ConfiguredOpenAITextVerbosity(config Config) (OpenAITextVerbosity, bool, error)
ConfiguredOpenAITextVerbosity returns an explicitly configured Responses API text verbosity. The boolean is false when the setting is absent, allowing the upstream API to apply its default.
func ParseOpenAITextVerbosity ¶
func ParseOpenAITextVerbosity(raw string) (OpenAITextVerbosity, bool)
ParseOpenAITextVerbosity normalizes and validates a configured text verbosity.
type ProfileConfig ¶
ProfileConfig holds the configuration values for a named profile
type RetryConfig ¶
type RetryConfig struct {
Attempts int `mapstructure:"attempts" json:"attempts" yaml:"attempts"` // Maximum number of retry attempts (default: 3)
InitialDelay int `mapstructure:"initial_delay" json:"initial_delay" yaml:"initial_delay"` // Initial delay in milliseconds (default: 1000) - OpenAI only
MaxDelay int `mapstructure:"max_delay" json:"max_delay" yaml:"max_delay"` // Maximum delay in milliseconds (default: 10000) - OpenAI only
BackoffType string `mapstructure:"backoff_type" json:"backoff_type" yaml:"backoff_type"` // Backoff strategy: "fixed", "exponential" (default: "exponential") - OpenAI only
}
RetryConfig holds the retry configuration for API calls Note: Anthropic only uses Attempts (relies on SDK retry), OpenAI uses all fields
type SkillsConfig ¶
type SkillsConfig struct {
// Enabled controls whether skills are active. When the SkillsConfig is nil
// (not specified in config), skills default to enabled. Set to false to disable.
Enabled bool `mapstructure:"enabled" json:"enabled" yaml:"enabled"`
// Allowed is an allowlist of skill names. When empty, all discovered skills are available.
// When specified, only the listed skills will be enabled.
Allowed []string `mapstructure:"allowed" json:"allowed" yaml:"allowed"`
}
SkillsConfig holds configuration for the agentic skills system. When this config is nil or omitted, skills are enabled by default. To disable skills, explicitly set Enabled to false.
type StreamingMessageHandler ¶
type StreamingMessageHandler interface {
MessageHandler
HandleTextDelta(delta string) // Called for each text chunk as it streams
HandleThinkingStart() // Called when a thinking block starts
HandleThinkingDelta(delta string) // Called for each thinking chunk as it streams
HandleThinkingBlockEnd() // Called when a thinking block ends (for visual separation)
HandleContentBlockEnd() // Called when any content block ends
}
StreamingMessageHandler extends MessageHandler with delta streaming support. Handlers implementing this interface will receive content as it streams from the LLM.
type StringCollectorHandler ¶
type StringCollectorHandler struct {
Silent bool
// contains filtered or unexported fields
}
StringCollectorHandler collects text responses into a string
func (*StringCollectorHandler) CollectedText ¶
func (h *StringCollectorHandler) CollectedText() string
CollectedText returns the accumulated text responses as a single string
func (*StringCollectorHandler) HandleContentBlockEnd ¶
func (h *StringCollectorHandler) HandleContentBlockEnd()
HandleContentBlockEnd optionally prints a newline when a content block ends
func (*StringCollectorHandler) HandleDone ¶
func (h *StringCollectorHandler) HandleDone()
HandleDone is called when message processing is complete
func (*StringCollectorHandler) HandleText ¶
func (h *StringCollectorHandler) HandleText(text string)
HandleText collects the text in a string builder and optionally prints to console
func (*StringCollectorHandler) HandleTextDelta ¶
func (h *StringCollectorHandler) HandleTextDelta(delta string)
HandleTextDelta collects streamed text chunks and optionally prints to console
func (*StringCollectorHandler) HandleThinking ¶
func (h *StringCollectorHandler) HandleThinking(thinking string)
HandleThinking optionally prints thinking content to the console (does not affect collection)
func (*StringCollectorHandler) HandleThinkingBlockEnd ¶
func (h *StringCollectorHandler) HandleThinkingBlockEnd()
HandleThinkingBlockEnd optionally prints a separator when a thinking block ends
func (*StringCollectorHandler) HandleThinkingDelta ¶
func (h *StringCollectorHandler) HandleThinkingDelta(delta string)
HandleThinkingDelta optionally prints streamed thinking chunks to the console
func (*StringCollectorHandler) HandleThinkingStart ¶
func (h *StringCollectorHandler) HandleThinkingStart()
HandleThinkingStart optionally prints the thinking prefix to the console
func (*StringCollectorHandler) HandleToolResult ¶
func (h *StringCollectorHandler) HandleToolResult(_, _ string, result tooltypes.ToolResult)
HandleToolResult optionally prints tool execution results to the console (does not affect collection)
func (*StringCollectorHandler) HandleToolUse ¶
func (h *StringCollectorHandler) HandleToolUse(_ string, toolName string, input string)
HandleToolUse optionally prints tool invocation details to the console (does not affect collection)
type Thread ¶
type Thread interface {
// SetState sets the state for the thread
SetState(s tooltypes.State)
// GetState returns the current state of the thread
GetState() tooltypes.State
// AddUserMessage adds a user message with optional images to the thread
AddUserMessage(ctx context.Context, message string, imagePaths ...string)
// SendMessage sends a message to the LLM and processes the response
SendMessage(ctx context.Context, message string, handler MessageHandler, opt MessageOpt) (finalOutput string, err error)
// GetUsage returns the current token usage for the thread
GetUsage() Usage
// GetConversationID returns the current conversation ID
GetConversationID() string
// SetConversationID sets the conversation ID
SetConversationID(id string)
// SaveConversation saves the current thread to the conversation store
SaveConversation(ctx context.Context, summarise bool) error
// IsPersisted returns whether this thread is being persisted
IsPersisted() bool
// EnablePersistence enables conversation persistence for this thread
EnablePersistence(ctx context.Context, enabled bool)
// Provider returns the provider of the thread
Provider() string
// GetMessages returns the messages from the thread
GetMessages() ([]Message, error)
// GetConfig returns the configuration of the thread
GetConfig() Config
// AggregateSubagentUsage aggregates usage from a subagent into this thread's usage
// This aggregates token counts and costs but NOT context window (which should remain isolated)
AggregateSubagentUsage(usage Usage)
// SetMetadataValue stores provider-neutral conversation metadata for persistence.
SetMetadataValue(key string, value any)
// GetMetadata returns provider-neutral conversation metadata.
GetMetadata() map[string]any
}
Thread represents a conversation thread with an LLM
type ToolMode ¶
type ToolMode string
ToolMode defines how the agent can interact with project files.
func (ToolMode) IsPatchMode ¶
IsPatchMode reports whether the tool mode should use apply_patch-only workflows.
type Usage ¶
type Usage struct {
InputTokens int `json:"inputTokens"` // Regular input tokens count
OutputTokens int `json:"outputTokens"` // Output tokens generated
CacheCreationInputTokens int `json:"cacheCreationInputTokens"` // Tokens used for creating cache entries
CacheReadInputTokens int `json:"cacheReadInputTokens"` // Tokens used for reading from cache
InputCost float64 `json:"inputCost"` // Cost for input tokens in USD
OutputCost float64 `json:"outputCost"` // Cost for output tokens in USD
CacheCreationCost float64 `json:"cacheCreationCost"` // Cost for cache creation in USD
CacheReadCost float64 `json:"cacheReadCost"` // Cost for cache read in USD
CurrentContextWindow int `json:"currentContextWindow"` // Current context window size
MaxContextWindow int `json:"maxContextWindow"` // Max context window size
}
Usage represents token usage information from LLM API calls
func (*Usage) TotalTokens ¶
TotalTokens returns the total number of tokens used
type UsageMessageHandler ¶
type UsageMessageHandler interface {
HandleUsage(usage Usage)
}
UsageMessageHandler receives cumulative usage snapshots while a message is being processed. Implementations can use this to surface live token usage updates.
type UserMessageHandler ¶
UserMessageHandler can render user-authored messages that are injected during an active turn, such as queued steering messages.