config

package
v0.10.2 Latest Latest
Warning

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

Go to latest
Published: May 2, 2026 License: MIT Imports: 27 Imported by: 0

Documentation

Overview

Package config provides multi-provider configuration loading for agent. Supports named providers, environment variable expansion, and compatibility with the old flat config format.

Package config — legacy model_routes parser and accessors.

The `model_routes:` config block was the pre-ADR-005 hand-authored per-tier candidate list. ADR-005 replaces it with deterministic smart routing driven by the model catalog, provider config, and the engine scoring path. This file exists so config.go itself contains no `ModelRouteConfig` type, no `model_routes` YAML tag, and no `ModelRouteConfig` method on `*Config` — see the structural boundary test `TestConfigSchemaHasNoModelRoutes`.

One-release deprecation: configs that still set `model_routes:` parse, honor configured ordering, and emit a deprecation warning naming the offending file path. The next release deletes this file outright.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultModelCatalogManifestPath

func DefaultModelCatalogManifestPath() string

func DefaultSessionLogDir

func DefaultSessionLogDir() string

func FallbackModelCatalogManifestPath

func FallbackModelCatalogManifestPath() string

func GlobalConfigDirName

func GlobalConfigDirName() string

func GlobalConfigPath

func GlobalConfigPath(home string) string

func LookupModelLimits

func LookupModelLimits(ctx context.Context, pc ProviderConfig, model string) limits.ModelLimits

LookupModelLimits queries the concrete provider package for provider-owned model limits. Unknown or unsupported providers return zero values.

func NewServiceConfig

func NewServiceConfig(cfg *Config, baseDir string) fizeau.ServiceConfig

func ProjectConfigDirName

func ProjectConfigDirName() string

func ProjectConfigPath

func ProjectConfigPath(workDir string) string

func ProjectRouteHealthPath

func ProjectRouteHealthPath(workDir, routeKey string) string

func ProjectRouteStateCounterPath

func ProjectRouteStateCounterPath(workDir, routeKey string) string

func ProviderImplicitGenerationConfig

func ProviderImplicitGenerationConfig(providerType string) bool

ProviderImplicitGenerationConfig reports whether the inference server behind the given provider type auto-applies the model's HuggingFace generation_config.json when the request omits sampler fields. The CLI uses this to tone the ADR-007 §7 catalog-stale nudge — vLLM users with no catalog profile aren't decoding greedy, they're getting model-card defaults; everyone else is in the loop-bug regime.

The single source of truth is each provider package's ProtocolCapabilities; this function exists because cmd/fiz cannot import provider packages directly.

func Save

func Save(cfg *Config) ([]byte, error)

Save is a package-level alias for Config.Save.

func SaveToFile

func SaveToFile(path string, cfg *Config) error

SaveToFile writes the config to a YAML file.

Types

type BackendPoolConfig

type BackendPoolConfig struct {
	// ModelRef is the model catalog reference (alias, profile, or canonical
	// target) attached to this backend pool. Optional.
	ModelRef string `yaml:"model_ref,omitempty"`

	// Providers is the ordered list of named provider references.
	Providers []string `yaml:"providers"`

	// Strategy is the provider selection algorithm: "round-robin" or
	// "first-available". Defaults to "first-available" if empty.
	Strategy string `yaml:"strategy,omitempty"`
}

BackendPoolConfig describes a named routing target that selects one provider before a run using a specified strategy.

type BashOutputFilterConfig

type BashOutputFilterConfig struct {
	Mode         string `yaml:"mode,omitempty"`
	RTKBinary    string `yaml:"rtk_binary,omitempty"`
	MaxBytes     int    `yaml:"max_bytes,omitempty"`
	RawOutputDir string `yaml:"raw_output_dir,omitempty"`
}

type BashToolConfig

type BashToolConfig struct {
	OutputFilter BashOutputFilterConfig `yaml:"output_filter,omitempty"`
}

type Config

type Config struct {
	// Providers is a map of named provider configurations.
	Providers map[string]ProviderConfig `yaml:"providers"`

	// Endpoints is the endpoint-first provider schema. Each entry is expanded
	// into an internal generated provider during finalization.
	Endpoints []EndpointConfig `yaml:"endpoints,omitempty"`

	// Routing configures default model-first resolution behavior.
	Routing RoutingConfig `yaml:"routing,omitempty"`

	// ModelRoutes is the deprecated (ADR-005) model-first routing table.
	// Populated by a second-pass YAML decoder in legacy_model_routes.go
	// (no parsing tag is declared here), so config.go itself owns no
	// part of the deprecated surface.
	ModelRoutes map[string]ModelRouteConfig `yaml:"-"`

	// Backends is a map of named backend pool configurations.
	Backends map[string]BackendPoolConfig `yaml:"backends,omitempty"`

	// DefaultBackend is the name of the default backend pool. When set, it
	// takes precedence over Default for runs that do not name a provider
	// or backend explicitly.
	DefaultBackend string `yaml:"default_backend,omitempty"`

	// ModelCatalog configures the optional external manifest path.
	ModelCatalog ModelCatalogConfig `yaml:"model_catalog,omitempty"`

	Tools ToolsConfig `yaml:"tools,omitempty"`

	// Telemetry configures OTel export enablement and runtime-specific
	// pricing keyed by provider system and resolved model.
	Telemetry telemetry.Config `yaml:"telemetry,omitempty"`

	// Default is the name of the default provider. If empty, uses the first.
	Default string `yaml:"default"`

	// MaxIterations limits agent loop iterations.
	MaxIterations int `yaml:"max_iterations"`

	// ReasoningByteLimit is the maximum bytes of pure reasoning_content
	// allowed before the stream is aborted. Default is 256KB.
	// Set to 0 for unlimited (same pattern as max_iterations).
	ReasoningByteLimit int `yaml:"reasoning_byte_limit"`

	// ReasoningStallTimeout is the maximum duration (e.g. "5m", "300s")
	// that only reasoning tokens may arrive before the stream is aborted.
	// Default is 300s. Set to "0s" for unlimited.
	ReasoningStallTimeout string `yaml:"reasoning_stall_timeout"`

	// CompactionPercent scales the effective context window used to trigger
	// automatic compaction. Range 1-100. 0 or absent = use default (95%).
	// The actual trigger threshold = context_window × percent/100 - reserve_tokens.
	CompactionPercent int `yaml:"compaction_percent,omitempty"`

	// SessionLogDir is where session logs are written.
	SessionLogDir string `yaml:"session_log_dir"`

	// Preset is the system prompt preset name.
	Preset string `yaml:"preset"`

	// ImportedFrom records the last import source for drift detection.
	ImportedFrom *ImportMetadata `yaml:"imported_from,omitempty"`

	// Legacy flat fields for backwards compatibility.
	LegacyProvider string `yaml:"provider,omitempty"`
	LegacyBaseURL  string `yaml:"base_url,omitempty"`
	LegacyAPIKey   string `yaml:"api_key,omitempty"`
	LegacyModel    string `yaml:"model,omitempty"`
	// contains filtered or unexported fields
}

Config is the top-level agent configuration.

func Defaults

func Defaults() Config

Defaults returns a Config with sensible defaults.

func Load

func Load(workDir string) (*Config, error)

Load reads configuration from .fizeau/config.yaml (project) and ~/.config/fizeau/config.yaml (global), with env var expansion. Project config overrides global config. If no config files exist, returns defaults.

func (*Config) BackendNames

func (c *Config) BackendNames() []string

BackendNames returns configured backend pool names in stable alphabetical order.

func (*Config) BuildProvider

func (c *Config) BuildProvider(name string) (agent.Provider, error)

BuildProvider creates a agent.Provider from a named provider config.

func (*Config) BuildProviderWithOverrides

func (c *Config) BuildProviderWithOverrides(name string, overrides ProviderOverrides) (agent.Provider, ProviderConfig, *modelcatalog.ResolvedTarget, error)

BuildProviderWithOverrides builds a provider after applying per-run overrides.

func (*Config) BuildTelemetry

func (c *Config) BuildTelemetry() telemetry.Telemetry

BuildTelemetry constructs the telemetry runtime from config. Pricing entries from the model catalog are seeded into RuntimePricing as fallback defaults; user-configured entries in fizeau.yaml take precedence.

func (*Config) DefaultName

func (c *Config) DefaultName() string

DefaultName returns the name of the default provider.

func (*Config) DefaultProvider

func (c *Config) DefaultProvider() (agent.Provider, error)

DefaultProvider creates the default provider.

func (*Config) GetBackend

func (c *Config) GetBackend(name string) (BackendPoolConfig, bool)

GetBackend returns the BackendPoolConfig for a named backend pool.

func (*Config) GetDeprecatedBackendRoute

func (c *Config) GetDeprecatedBackendRoute(name string) (ModelRouteConfig, bool)

GetDeprecatedBackendRoute returns the translated model-route config for a deprecated backend compatibility input.

func (*Config) GetModelRoute

func (c *Config) GetModelRoute(name string) (ModelRouteConfig, bool)

GetModelRoute returns the (deprecated) model-route config for a route key. Retained for one-release backward compat per ADR-005.

func (*Config) GetProvider

func (c *Config) GetProvider(name string) (ProviderConfig, bool)

GetProvider returns the ProviderConfig for a named provider.

func (*Config) LegacyModelRouteNames

func (c *Config) LegacyModelRouteNames() []string

LegacyModelRouteNames returns configured model-route names in stable alphabetical order. Renamed from `ModelRouteNames` per ADR-005 to keep the boundary test from flagging re-introduction; the `*Config`-receiver method named `ModelRouteConfig` was the literal hit, so naming around model_routes remains in this file (legacy surface area), not config.go.

func (*Config) LoadModelCatalog

func (c *Config) LoadModelCatalog() (*modelcatalog.Catalog, error)

LoadModelCatalog loads the shared model catalog using the configured manifest override path.

func (*Config) ModelRouteNames

func (c *Config) ModelRouteNames() []string

ModelRouteNames is kept as a thin alias to LegacyModelRouteNames for out-of-package callers (cmd/fiz, cmd/bench) that read configured route names. Defined here (not in config.go) so config.go stays free of the deprecated surface.

func (*Config) ParseReasoningStallTimeout

func (c *Config) ParseReasoningStallTimeout() (time.Duration, error)

ParseReasoningStallTimeout parses the ReasoningStallTimeout string into a time.Duration. Returns 0 if the string is empty (caller should apply default).

func (*Config) ProviderNames

func (c *Config) ProviderNames() []string

ProviderNames returns configured provider names in stable order.

func (*Config) ResolveBackend

func (c *Config) ResolveBackend(name string, counter int, overrides ProviderOverrides) (agent.Provider, ProviderConfig, *modelcatalog.ResolvedTarget, error)

ResolveBackend resolves a named backend pool to a concrete provider and model.

counter is the rotation index used for round-robin selection; it should be the number of prior requests against this backend pool. Callers that want stateless first-available behavior can always pass 0.

overrides.Model, when set, bypasses the catalog and uses the given concrete model string. overrides.ModelRef, when set, overrides the backend's own model_ref. If neither the backend nor the overrides specify a model, the provider's configured default model is used.

func (*Config) ResolveProviderConfig

func (c *Config) ResolveProviderConfig(name string, overrides ProviderOverrides) (ProviderConfig, *modelcatalog.ResolvedTarget, error)

ResolveProviderConfig applies per-run overrides to a named provider config.

func (*Config) Save

func (c *Config) Save() ([]byte, error)

Save serializes the config to YAML bytes.

func (*Config) Warnings

func (c *Config) Warnings() []string

Warnings returns config-load warnings that the CLI may surface.

type EndpointConfig

type EndpointConfig struct {
	Name      string              `yaml:"name,omitempty"`
	Type      string              `yaml:"type"`
	Host      string              `yaml:"host,omitempty"`
	Port      int                 `yaml:"port,omitempty"`
	BaseURL   string              `yaml:"base_url,omitempty"`
	APIKey    string              `yaml:"api_key,omitempty"`
	Headers   map[string]string   `yaml:"headers,omitempty"`
	Reasoning reasoning.Reasoning `yaml:"reasoning,omitempty"`
}

EndpointConfig describes one endpoint-first serving target. Unlike ProviderConfig, endpoint blocks do not require a user-facing provider name or a configured model; routing discovers live model IDs from /v1/models.

type ImportMetadata

type ImportMetadata struct {
	// Source is the import source ("pi" or "opencode").
	Source string `yaml:"source"`
	// Timestamp is when the import occurred (RFC3339).
	Timestamp string `yaml:"timestamp"`
	// SourceHash is the truncated SHA-256 of the source files.
	SourceHash string `yaml:"source_hash"`
}

ImportMetadata records the last import source for drift detection.

type ModelCatalogConfig

type ModelCatalogConfig struct {
	Manifest string `yaml:"manifest,omitempty"`
}

ModelCatalogConfig configures how the shared model catalog is loaded.

type ModelRouteCandidateConfig deprecated

type ModelRouteCandidateConfig struct {
	Provider string `yaml:"provider"`
	Model    string `yaml:"model,omitempty"`
	Priority int    `yaml:"priority,omitempty"`
}

ModelRouteCandidateConfig describes one provider candidate inside a (deprecated) model_routes entry.

Deprecated: see ADR-005. Retained only for one-release backward compat.

type ModelRouteConfig deprecated

type ModelRouteConfig struct {
	Strategy   string                      `yaml:"strategy,omitempty"`
	Candidates []ModelRouteCandidateConfig `yaml:"candidates"`
}

ModelRouteConfig describes a (deprecated) model-first routing target.

Deprecated: see ADR-005. Retained only for one-release backward compat.

type ProviderConfig

type ProviderConfig struct {
	Type      string             `yaml:"type"`               // "openai", "openrouter", "lmstudio", "omlx", "lucebox", "vllm", "ollama", or "anthropic"
	BaseURL   string             `yaml:"base_url,omitempty"` // shorthand for one endpoint
	Endpoints []ProviderEndpoint `yaml:"endpoints,omitempty"`
	APIKey    string             `yaml:"api_key,omitempty"`
	Model     string             `yaml:"model,omitempty"`
	// ModelPattern is a case-insensitive regex applied to auto-discovered model
	// IDs when Model is empty. The first matching model returned by /v1/models
	// is used. If the pattern matches nothing, the first available model is
	// used as a fallback.
	ModelPattern string            `yaml:"model_pattern,omitempty"`
	Headers      map[string]string `yaml:"headers"` // extra HTTP headers (OpenRouter, Azure)
	// Reasoning controls model-side reasoning with one scalar value.
	Reasoning reasoning.Reasoning `yaml:"reasoning,omitempty"`
	// MaxTokens is the maximum number of tokens the model may generate per turn.
	// Zero means use the provider's default.
	MaxTokens int `yaml:"max_tokens,omitempty"`
	// ContextWindow is the model's context window in tokens. Used to configure
	// automatic compaction: the compactor triggers when message history approaches
	// this limit. Zero means use the compaction package default (8192).
	ContextWindow int `yaml:"context_window,omitempty"`
	// Sampling overrides the harness defaults for sampling parameters.
	// Any nil/unset field falls through to harness/server defaults.
	Sampling *SamplingProfile `yaml:"sampling,omitempty"`
}

ProviderConfig describes a single named provider.

type ProviderEndpoint

type ProviderEndpoint struct {
	Name    string `yaml:"name,omitempty"`
	BaseURL string `yaml:"base_url"`
}

ProviderEndpoint describes one serving endpoint for providers that can run across multiple host:port locations.

type ProviderOverrides

type ProviderOverrides struct {
	Model           string
	ModelRef        string
	AllowDeprecated bool
}

ProviderOverrides are per-run overrides applied before building a provider.

type RoutingConfig

type RoutingConfig struct {
	// DefaultModel is the default requested model-route key to use when the
	// caller does not set --model, --model-ref, or --provider.
	DefaultModel string `yaml:"default_model,omitempty"`

	// DefaultModelRef resolves through the model catalog to a canonical route
	// key when no explicit provider or model input is supplied.
	DefaultModelRef string `yaml:"default_model_ref,omitempty"`

	// HealthCooldown controls how long a failed candidate remains deprioritized
	// before it is retried.
	HealthCooldown string `yaml:"health_cooldown,omitempty"`

	// HistoryWindow controls how far back observed routing history is sampled
	// when scoring healthy candidates.
	HistoryWindow string `yaml:"history_window,omitempty"`

	// ProbeTimeout controls provider availability/model probes.
	ProbeTimeout string `yaml:"probe_timeout,omitempty"`

	// ReliabilityWeight weights recent success history when scoring healthy
	// candidates.
	ReliabilityWeight float64 `yaml:"reliability_weight,omitempty"`

	// PerformanceWeight weights observed latency/throughput when scoring healthy
	// candidates.
	PerformanceWeight float64 `yaml:"performance_weight,omitempty"`

	// LoadWeight weights recent selection volume when balancing healthy
	// candidates.
	LoadWeight float64 `yaml:"load_weight,omitempty"`

	// CostWeight weights observed known cost when balancing healthy candidates.
	CostWeight float64 `yaml:"cost_weight,omitempty"`

	// CapabilityWeight weights model benchmark capability (swe_bench_verified)
	// when scoring healthy candidates.
	CapabilityWeight float64 `yaml:"capability_weight"`
}

RoutingConfig configures model-first route selection defaults.

type SamplingProfile

type SamplingProfile = sampling.Profile

SamplingProfile is the canonical sampling-overrides bundle. The type itself lives in internal/sampling so model-catalog entries and provider config can share it without a circular import; this alias preserves the existing config.SamplingProfile spelling for callers.

type ToolsConfig

type ToolsConfig struct {
	Bash BashToolConfig `yaml:"bash,omitempty"`
}

Jump to

Keyboard shortcuts

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