model

package
v0.1.13 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrModelNotRegistered = errors.New("model not registered")

ErrModelNotRegistered is returned by Finder.Find when no model configuration matches the requested id and no registered config can be loaded. Wrapped with the offending id via fmt.Errorf("%w: <id>", ...) so errors.Is(err, ErrModelNotRegistered) detects the condition while the wrapped message still names the missing model.

Per H1 (modelpref-pkg.md §3): the legacy provider-prefix heuristic `inferConfigFromID` is opt-in via AGENTLY_ALLOW_LEGACY_INFER=1. Default behavior surfaces this typed error so missing model configs are caught at the boundary rather than papered over by inference. Callers (skill activation, intake, agent.Query) that today rely on inference must register an explicit YAML under `<workspace>/models/<id>.yaml` or set the env flag during migration.

Functions

This section is empty.

Types

type Finder

type Finder struct {
	// contains filtered or unexported fields
}

func New

func New(options ...Option) *Finder

func (*Finder) AddConfig

func (d *Finder) AddConfig(name string, cfg *provider.Config)

AddConfig injects or overwrites a model configuration and bumps version.

func (*Finder) Best

func (d *Finder) Best(p *llm.ModelPreferences) string

func (*Finder) BestWithFilter

func (d *Finder) BestWithFilter(p *llm.ModelPreferences, allow func(id string) bool) string

BestWithFilter selects the best model after reducing candidates using allow. When the filter excludes all candidates, it falls back to the full set.

func (*Finder) Candidates

func (d *Finder) Candidates() []matcher.Candidate

Candidates returns the matcher view of registered models. Cached by registry version — rebuilds only when configs change (provider added, removed, replaced). On cache hit returns the same slice every time; callers MUST treat the result as read-only (no mutation, no in-place sort). The matcher does so already.

Concurrency: a single read lock + one fast atomic load on the hot path. Rebuild path takes a write lock, computes once, stores, then downgrades to read-only access for subsequent calls.

func (*Finder) ConfigByIDOrModel

func (d *Finder) ConfigByIDOrModel(id string) *provider.Config

ConfigByIDOrModel returns the provider config matching the given identifier. It first attempts a direct lookup by config ID. If not found, it scans all configs to find a match either by config ID or by the provider model name stored in Options.Model. Returns nil when no matching config exists.

func (*Finder) DropModel

func (d *Finder) DropModel(name string)

DropModel removes an already instantiated llm.Model instance but keeps its configuration. Next Find() will create a fresh model using the existing config. Useful after model implementation reload without deleting YAML.

func (*Finder) Find

func (d *Finder) Find(ctx context.Context, id string) (llm.Model, error)

func (*Finder) Matcher

func (d *Finder) Matcher() *matcher.Matcher

Matcher builds a matcher instance from current configs.

func (*Finder) Remove

func (d *Finder) Remove(name string)

Remove deletes a model configuration and any instantiated model from the finder caches. It bumps the internal version so hot-swap watchers can detect the change.

func (*Finder) TokenPrices

func (d *Finder) TokenPrices(id string) (in float64, out float64, cached float64, ok bool)

TokenPrices returns per-1k token prices for the specified model ID when available in the model configuration. Returns ok=false when no config exists or prices are not set.

func (*Finder) Version

func (d *Finder) Version() int64

Version returns monotonically increasing value changed on Add/Remove.

type Option

type Option func(dao *Finder)

Option defines a functional option for Finder

func WithConfigLoader

func WithConfigLoader(loader modelprovider.ConfigLoader) Option

WithConfigLoader sets a custom configuration loader for the Finder instance.

func WithInitial

func WithInitial(configs ...*modelprovider.Config) Option

WithInitial adds model configurations to the Finder instance.

Jump to

Keyboard shortcuts

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