Help us shape the future of Go! Take the 2026 Go Developer Survey

modelcatalog

package
v1.153.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Catalog

type Catalog struct {
	Config  *Config
	Store   Store
	Now     func() time.Time
	ListDMR func(context.Context) ([]dmrmodels.Model, error)
	// contains filtered or unexported fields
}

Catalog owns model discovery and picker metadata, independently of execution. Configuration is immutable after construction.

func (*Catalog) AvailableModels

func (r *Catalog) AvailableModels(ctx context.Context, agentName string) []ModelChoice

AvailableModels returns configured and discovered choices for agentName.

type Config

type Config struct {
	// Models is the map of model names to configurations from the loaded config
	Models map[string]latest.ModelConfig
	// Providers is the map of custom provider configurations
	Providers map[string]latest.ProviderConfig
	// ModelsGateway is the gateway URL if configured
	ModelsGateway string
	// EncryptedConfig is the opaque encrypted agent YAML forwarded to a trusted
	// Docker models gateway on every request (X-Cagent-Encrypted-Config header).
	// Empty disables forwarding.
	EncryptedConfig string
	// EnvProvider provides access to environment variables
	EnvProvider environment.Provider
	// ProviderRegistry instantiates providers for runtime model switching.
	ProviderRegistry *provider.Registry
	// AgentDefaultModels maps agent names to their configured default model references
	AgentDefaultModels map[string]string
	// ModelsStore is the models.dev catalog store used for the picker's
	// pricing/context/modality metadata and the catalog listing. When set, the
	// runtime adopts it instead of building its own (cold) lazy store, so a
	// store the team loader already warmed is reused. Optional: a nil store
	// falls back to the lazy default. An explicit WithModelStore takes
	// precedence over this field.
	ModelsStore Store
}

Config holds the configuration needed for model switching. This is populated by the app layer when creating the runtime.

type ModelChoice

type ModelChoice struct {
	// Name is the display name (config key)
	Name string `json:"name"`
	// Ref is the model reference used internally (e.g., "my_model" or "openai/gpt-4o")
	Ref string `json:"ref"`
	// Provider is the provider name (e.g., "openai", "anthropic")
	Provider string `json:"provider,omitempty"`
	// Model is the specific model name (e.g., "gpt-4o", "claude-sonnet-4-0")
	Model string `json:"model,omitempty"`
	// IsDefault indicates this is the agent's configured default model
	IsDefault bool `json:"is_default,omitempty"`
	// IsCurrent indicates this is the currently active model for the agent
	IsCurrent bool `json:"is_current,omitempty"`
	// IsCustom indicates this is a custom model from the session history (not from config)
	IsCustom bool `json:"is_custom,omitempty"`
	// IsCatalog indicates this is a model from the models.dev catalog
	IsCatalog bool `json:"is_catalog,omitempty"`

	// Local model metadata reported by Docker Model Runner.
	Architecture string `json:"architecture,omitempty"`
	Parameters   string `json:"parameters,omitempty"`
	Quantization string `json:"quantization,omitempty"`
	Size         string `json:"size,omitempty"`

	// Family is the model family (e.g., "claude", "gpt").
	Family string `json:"family,omitempty"`
	// InputCost is the price (in USD) per 1M input tokens.
	InputCost float64 `json:"input_cost,omitempty"`
	// OutputCost is the price (in USD) per 1M output tokens.
	OutputCost float64 `json:"output_cost,omitempty"`
	// CacheReadCost is the price (in USD) per 1M cached input tokens.
	CacheReadCost float64 `json:"cache_read_cost,omitempty"`
	// CacheWriteCost is the price (in USD) per 1M cache-write tokens.
	CacheWriteCost float64 `json:"cache_write_cost,omitempty"`
	// ContextLimit is the maximum context window size in tokens.
	ContextLimit int `json:"context_limit,omitempty"`
	// OutputLimit is the maximum number of tokens the model can produce
	// in a single response.
	OutputLimit int64 `json:"output_limit,omitempty"`
	// InputModalities lists the input modalities supported by the model
	// (e.g., "text", "image", "audio").
	InputModalities []string `json:"input_modalities,omitempty"`
	// OutputModalities lists the output modalities the model can produce.
	OutputModalities []string `json:"output_modalities,omitempty"`
}

ModelChoice represents a model available for selection in the model picker.

JSON tags are part of the public wire format used by GET /api/sessions/:id/models; renaming a tag is a breaking change.

func DecorateModelChoices

func DecorateModelChoices(models []ModelChoice, currentRef string, customRefs []string) []ModelChoice

DecorateModelChoices marks the active selection with IsCurrent and appends any custom (provider/model) refs from the session history that the runtime does not already expose. It is used by every consumer that wants to render a model picker (the TUI App, the HTTP /sessions/:id/models endpoint, …) so they all agree on which entry is current and what the final list looks like.

currentRef is the model override active for the agent ("" when none), and customRefs is the session's CustomModelsUsed history.

The input slice is never mutated: callers can safely pass a slice that is shared with or backed by an internal cache.

type SessionModelsResponse

type SessionModelsResponse struct {
	Agent           string        `json:"agent"`
	CurrentModelRef string        `json:"current_model_ref,omitempty"`
	Models          []ModelChoice `json:"models"`
}

SessionModelsResponse is the response returned by GET /api/sessions/:id/models. CurrentModelRef is the active override for the named agent (empty when the agent is using its configured default).

type Store

type Store interface {
	GetModel(ctx context.Context, id modelsdev.ID) (*modelsdev.Model, error)
	GetDatabase(ctx context.Context) (*modelsdev.Database, error)
}

Store provides model metadata and the complete catalog.

Jump to

Keyboard shortcuts

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