llm

package
v0.6.19-beta Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2026 License: MIT Imports: 27 Imported by: 0

Documentation

Overview

Package llm provides a unified interface for Large Language Model providers. It abstracts different LLM providers (Anthropic Claude, OpenAI GPT) behind a common Thread interface for consistent interaction patterns.

Index

Constants

View Source
const (
	DefaultMaxToolResultCharacters = conversations.DefaultMaxToolResultCharacters
	DefaultMaxToolResultBytes      = conversations.DefaultMaxToolResultBytes
)
View Source
const (
	// ConfigFileEnv points at an additional trusted configuration file that is
	// layered on top of the global config, or replaces it entirely in isolated mode.
	ConfigFileEnv = "KODELET_CONFIG_FILE"
	// ConfigFileModeEnv selects how ConfigFileEnv is applied.
	ConfigFileModeEnv = "KODELET_CONFIG_FILE_MODE"
	// ConfigFileModeMerge layers the override file on top of the global config.
	ConfigFileModeMerge = "merge"
	// ConfigFileModeIsolated makes the override file the only configuration source.
	ConfigFileModeIsolated = "isolated"
	// RepoConfigFile is the repository-local configuration file name.
	RepoConfigFile = "kodelet-config.yaml"

	ProfileSourceGlobal              ProfileSource = "global"
	ProfileSourceRepo                ProfileSource = "repo"
	ProfileSourceRepoOverridesGlobal ProfileSource = "repo-overrides-global"
	ProfileSourceOverride            ProfileSource = "override"
)

Variables

This section is empty.

Functions

func CloseThread

func CloseThread(thread llmtypes.Thread) error

CloseThread releases provider-specific resources owned by a thread. Providers without explicit resources do not need to implement Close.

func ExtractConversationEntries

func ExtractConversationEntries(provider string, rawMessages []byte, metadata map[string]any, toolResults map[string]tooltypes.StructuredToolResult) ([]conversations.StreamableMessage, error)

ExtractConversationEntries parses the raw messages from a conversation record into structured conversation entries.

func ExtractConversationRecordEntries

func ExtractConversationRecordEntries(record convtypes.ConversationRecord) ([]conversations.StreamableMessage, error)

ExtractConversationRecordEntries projects full display history without changing active model input.

func ExtractConversationRecordMessages

func ExtractConversationRecordMessages(record convtypes.ConversationRecord) ([]llmtypes.Message, error)

ExtractConversationRecordMessages provides the complete transcript for text and JSON exports.

func ExtractMessages

func ExtractMessages(provider string, rawMessages []byte, metadata map[string]any, toolResults map[string]tooltypes.StructuredToolResult) ([]llmtypes.Message, error)

ExtractMessages parses the raw messages from a conversation record

func GetConfigFromProfile

func GetConfigFromProfile(settings llmtypes.ProfileConfig) (llmtypes.Config, error)

GetConfigFromProfile decodes a model profile with field defaults, without consulting daemon or workspace settings.

func GetConfigFromSettingsWithEnvironmentProfile

func GetConfigFromSettingsWithEnvironmentProfile(settings map[string]any, profileName string) (llmtypes.Config, error)

GetConfigFromSettingsWithEnvironmentProfile resolves a runner-owned settings snapshot without consulting or mutating the process-global Viper instance.

func GetConfigFromViper

func GetConfigFromViper() (llmtypes.Config, error)

GetConfigFromViper loads the selected named model profile and shared settings, then resolves model aliases. A profile selection is required.

func GetConfigFromViperWithCmd

func GetConfigFromViperWithCmd(cmd *cobra.Command) (llmtypes.Config, error)

GetConfigFromViperWithCmd loads the LLM configuration from Viper with command context. When a cobra.Command is provided, CLI flags that were explicitly changed take priority over profile settings.

func GetConfigFromViperWithEnvironmentProfile

func GetConfigFromViperWithEnvironmentProfile(profileName string) (llmtypes.Config, error)

GetConfigFromViperWithEnvironmentProfile loads runner-owned configuration from the separate environment_profiles namespace without applying a model profile.

func GetConfigFromViperWithProfile

func GetConfigFromViperWithProfile(profileName string) (llmtypes.Config, error)

GetConfigFromViperWithProfile loads configuration from Viper while applying the provided profile name instead of the globally active viper profile. This is useful for request-scoped profile selection (for example, in the web UI) without mutating shared process-wide viper state. An empty name uses the configured profile selection; "default" is an ordinary profile name.

func GetConfigFromViperWithoutProfile

func GetConfigFromViperWithoutProfile() (llmtypes.Config, error)

GetConfigFromViperWithoutProfile loads only shared configuration. It neither requires nor applies model profiles, and returns no model settings.

func GlobalProfileSetting

func GlobalProfileSetting() string

GlobalProfileSetting returns the active profile selected by the global configuration layer.

func GlobalProfiles

func GlobalProfiles() map[string]llmtypes.ProfileConfig

GlobalProfiles returns the profiles declared by the global configuration layer. Nil is returned when no profile is declared or an isolated override disables the layer. All names, including "default", are ordinary profiles.

func HasConfiguredProfile

func HasConfiguredProfile(profileName string) bool

HasConfiguredProfile reports whether a named profile exists in the merged Viper configuration.

func IsProfileHidden

func IsProfileHidden(profileName string) bool

IsProfileHidden reports presentation metadata, not a restriction on explicit selection.

func ModelOptions

func ModelOptions(ctx context.Context, config llmtypes.Config) []string

ModelOptions returns model IDs for a resolved profile's provider connection. The configured main model is first; the remaining IDs are sorted and unique. Explicit model lists take precedence over pricing catalogs and platform defaults. Aliases are intentionally not a catalog: they may refer to other connections.

func NewThread

func NewThread(config llmtypes.Config) (llmtypes.Thread, error)

NewThread creates a new thread based on the model specified in the config

func OverrideProfileSetting

func OverrideProfileSetting() (string, bool)

OverrideProfileSetting returns the profile selected by KODELET_CONFIG_FILE and whether that file explicitly contains a profile setting.

func OverrideProfiles

func OverrideProfiles() map[string]llmtypes.ProfileConfig

OverrideProfiles returns the profiles declared by KODELET_CONFIG_FILE.

func ProfileSources

func ProfileSources() map[string]ProfileSource

ProfileSources returns every available profile and the highest-precedence configuration layer that defines it.

func ProviderPlatform

func ProviderPlatform(config llmtypes.Config, provider string) string

ProviderPlatform returns the normalized platform for a provider's configuration block.

func RenderConversationMarkdown

func RenderConversationMarkdown(
	provider string,
	rawMessages []byte,
	metadata map[string]any,
	toolResults map[string]tooltypes.StructuredToolResult,
) (string, error)

RenderConversationMarkdown converts a stored conversation into markdown using the same formatting logic as `kodelet conversation show --format markdown`.

func RenderConversationMarkdownWithOptions

func RenderConversationMarkdownWithOptions(
	provider string,
	rawMessages []byte,
	metadata map[string]any,
	toolResults map[string]tooltypes.StructuredToolResult,
	opts ConversationMarkdownOptions,
) (string, error)

RenderConversationMarkdownWithOptions converts a stored conversation into markdown with optional output-shaping controls.

func RenderConversationRecordMarkdown

func RenderConversationRecordMarkdown(record convtypes.ConversationRecord, opts ConversationMarkdownOptions) (string, error)

RenderConversationRecordMarkdown renders archived and active display history.

func RepoProfileSetting

func RepoProfileSetting() string

RepoProfileSetting returns the active profile selected by the repository-local config.

func RepoProfiles

func RepoProfiles() map[string]llmtypes.ProfileConfig

RepoProfiles returns the profiles declared by the repository-local config.

func SendMessageAndGetText

func SendMessageAndGetText(ctx context.Context, state tooltypes.State, query string, config llmtypes.Config, silent bool, opt llmtypes.MessageOpt) string

SendMessageAndGetText is a convenience method for one-shot queries that returns the response as a string

func SendMessageAndGetTextWithUsage

func SendMessageAndGetTextWithUsage(ctx context.Context, state tooltypes.State, query string, config llmtypes.Config, silent bool, opt llmtypes.MessageOpt) (string, llmtypes.Usage)

SendMessageAndGetTextWithUsage is a convenience method for one-shot queries that returns the response as a string and usage information

func SetEnvironment

func SetEnvironment(thread llmtypes.Thread, environment agentenv.Environment) error

SetEnvironment attaches an agent environment to a provider thread.

func UsesIsolatedConfigFile

func UsesIsolatedConfigFile() bool

UsesIsolatedConfigFile reports whether an explicit override replaces both the home and repository configuration layers.

func ValidateModelProfiles

func ValidateModelProfiles() error

ValidateModelProfiles validates daemon model configuration at startup. Clients, runners and saved-conversation shared loaders must not call this: they do not need a default model profile. Removed top-level file and environment settings are rejected; explicit model flags remain per-request overrides.

Types

type ConversationMarkdownOptions

type ConversationMarkdownOptions = conversations.MarkdownOptions

ConversationMarkdownOptions controls markdown rendering for stored conversations.

type ProfileSource

type ProfileSource string

ProfileSource identifies the highest-precedence configuration layer for a profile.

func ActiveProfileSetting

func ActiveProfileSetting() (string, ProfileSource)

ActiveProfileSetting returns the profile selected by the highest-precedence configuration file together with that file's source.

Directories

Path Synopsis
Package anthropic provides a client implementation for interacting with Anthropic's Claude AI models.
Package anthropic provides a client implementation for interacting with Anthropic's Claude AI models.
Package base provides shared functionality for LLM thread implementations.
Package base provides shared functionality for LLM thread implementations.
Package openai provides OpenAI API client implementations.
Package openai provides OpenAI API client implementations.
copilotdefaults
Package copilotdefaults builds OpenAI-compatible model defaults from the Copilot model catalog.
Package copilotdefaults builds OpenAI-compatible model defaults from the Copilot model catalog.
preset/codex
Package codex provides preset configurations for Codex CLI models.
Package codex provides preset configurations for Codex CLI models.
preset/openai
Package openai provides preset configurations for OpenAI models
Package openai provides preset configurations for OpenAI models
responses
Package responses implements storage types for the OpenAI Responses API.
Package responses implements storage types for the OpenAI Responses API.
Package prompts provides common prompt templates for LLM interactions including context compacting prompts and other reusable prompt text used throughout kodelet's LLM communication.
Package prompts provides common prompt templates for LLM interactions including context compacting prompts and other reusable prompt text used throughout kodelet's LLM communication.

Jump to

Keyboard shortcuts

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