config

package
v0.10.16 Latest Latest
Warning

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

Go to latest
Published: May 8, 2026 License: MIT Imports: 29 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.

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"`

	// 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"`

	// Anchors enables anchored read output and the anchor_edit tool for CLI runs.
	Anchors bool `yaml:"anchors,omitempty"`

	// Skills configures progressive-disclosure SKILL.md discovery.
	Skills SkillsConfig `yaml:"skills,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"`

	// 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) GetProvider

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

GetProvider returns the ProviderConfig for a named provider.

func (*Config) LoadModelCatalog

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

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

func (*Config) ProviderError added in v0.10.11

func (c *Config) ProviderError(name string) string

ProviderError returns the provider-scoped config error recorded during load, if any. Provider-scoped errors do not make the whole config unloadable.

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"`
	ServerInstance string              `yaml:"server_instance,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 ProviderConfig

type ProviderConfig struct {
	Type           string             `yaml:"type"`               // "openai", "openrouter", "lmstudio", "llama-server", "omlx", "lucebox", "vllm", "rapid-mlx", "ollama", or "anthropic"
	BaseURL        string             `yaml:"base_url,omitempty"` // shorthand for one endpoint
	ServerInstance string             `yaml:"server_instance,omitempty"`
	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"`
	// DailyTokenBudget caps total tokens (request + response) the provider
	// may consume per UTC daily window. Zero/absent disables predictive
	// exhaustion for this provider; the actual quota signal from the
	// upstream API is still respected. See fizeau-f2661619.
	DailyTokenBudget int `yaml:"daily_token_budget,omitempty"`
}

ProviderConfig describes a single named provider.

type ProviderEndpoint

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

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 SkillsConfig added in v0.10.4

type SkillsConfig struct {
	// Dir is the skills directory. Empty defaults to ".fizeau/skills"
	// relative to the work directory; "-" disables skill discovery
	// even when a directory exists. The FIZEAU_SKILLS_DIR environment
	// variable overrides this value when set.
	Dir string `yaml:"dir,omitempty"`
}

SkillsConfig configures discovery of SKILL.md progressive-disclosure skills.

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