MingaAgent.Config (Minga v0.1.0)

Copy Markdown View Source

Single source of truth for all agent tunables.

Reads user-facing settings from Minga.Config.Options and defines sensible defaults for internal tunables. No other agent module should define @default_* constants or call Config.get(:agent_*) directly.

Call resolve/0 once at session or provider init, then thread the resulting %Config{} through state and function arguments.

Adding a new setting

  1. Add the field to the struct and @type t
  2. Add the default value in defstruct
  3. If user-configurable, register it in Minga.Config.Options and read it in resolve/0
  4. If internal-only, the struct default is sufficient

Summary

Functions

Returns the explicitly configured model, or nil when the user has not chosen one.

Returns the explicitly configured model from a specific options server, or nil when unset.

Returns the model used for new sessions when the user has not explicitly configured one.

Returns the model used for new sessions from a specific options server.

Extracts the provider prefix from a model spec string.

Normalizes raw :agent_hooks config declarations into hook structs.

Builds a %Config{} from Options with struct defaults as fallbacks.

Returns the configured model, then the first available credential-backed model.

Returns the configured model from a specific options server, then the first available credential-backed model.

Returns the configured provider, falling back to :auto.

Splits a model spec into {model, provider} regardless of whether the user wrote provider:model or model@provider.

Strips the provider encoding from a model spec string.

Returns the internal sentinel used when no configured provider has an available model.

Returns a config with agent hooks disabled.

Types

t()

@type t() :: %MingaAgent.Config{
  agent_hooks: [MingaAgent.Hooks.Hook.t()],
  api_base_url: String.t(),
  api_base_url_override: String.t() | nil,
  api_endpoints: map() | nil,
  append_system_prompt: String.t(),
  approval_timeout_ms: pos_integer(),
  auto_context: boolean(),
  compaction_keep_recent: pos_integer(),
  compaction_threshold: float() | nil,
  destructive_tools: [String.t()],
  diff_size_threshold: pos_integer(),
  max_cost: float() | nil,
  max_file_size: pos_integer(),
  max_image_size: pos_integer(),
  max_mention_candidates: pos_integer(),
  max_retries: non_neg_integer(),
  max_tokens: pos_integer(),
  max_turns: pos_integer(),
  mcp_servers: [MingaAgent.MCP.ServerConfig.t() | map()],
  memory_max_tokens: pos_integer(),
  model: String.t(),
  models: [String.t()],
  notifications: boolean(),
  notify_debounce_ms: pos_integer(),
  notify_on: [atom()],
  panel_split: pos_integer(),
  prompt_cache: boolean(),
  provider: :auto | :native | String.t(),
  save_debounce_ms: pos_integer(),
  session_retention_days: pos_integer(),
  shell_debounce_ms: pos_integer(),
  subagent_timeout_ms: pos_integer(),
  system_prompt: String.t(),
  tool_approval: :destructive | :all | :none,
  tool_permissions: map() | nil
}

Functions

configured_model()

@spec configured_model() :: String.t() | nil

Returns the explicitly configured model, or nil when the user has not chosen one.

configured_model(options_server)

@spec configured_model(Minga.Config.Options.server()) :: String.t() | nil

Returns the explicitly configured model from a specific options server, or nil when unset.

default_model()

@spec default_model() :: String.t()

Returns the model used for new sessions when the user has not explicitly configured one.

default_model(options_server)

@spec default_model(Minga.Config.Options.server()) :: String.t()

Returns the model used for new sessions from a specific options server.

extract_provider_prefix(model)

@spec extract_provider_prefix(String.t()) :: String.t()

Extracts the provider prefix from a model spec string.

Returns the provider name, or "" if no prefix is present.

normalize_hooks(raw_hooks)

@spec normalize_hooks(term()) :: [MingaAgent.Hooks.Hook.t()]

Normalizes raw :agent_hooks config declarations into hook structs.

resolve()

@spec resolve() :: t()

Builds a %Config{} from Options with struct defaults as fallbacks.

Safe to call before the Options ETS table exists (e.g., in tests or standalone usage). When Options is unavailable, all fields use their struct defaults.

resolve_model()

@spec resolve_model() :: String.t()

Returns the configured model, then the first available credential-backed model.

Safe to call before Config is running (catches exits). If no provider has credentials, returns the internal "unknown" sentinel rather than pretending a specific vendor model is ready.

resolve_model(options_server)

@spec resolve_model(Minga.Config.Options.server()) :: String.t()

Returns the configured model from a specific options server, then the first available credential-backed model.

This keeps per-editor tests and embedded editors from depending on the global options server.

resolve_provider()

@spec resolve_provider() :: :auto | :native | String.t()

Returns the configured provider, falling back to :auto.

Safe to call before Config is running (catches exits).

split_model_spec(model)

@spec split_model_spec(String.t()) :: {String.t(), String.t() | nil}

Splits a model spec into {model, provider} regardless of whether the user wrote provider:model or model@provider.

Returns {bare_model, nil} when no provider is encoded in the string.

Examples

iex> MingaAgent.Config.split_model_spec("anthropic:claude-sonnet-4")
{"claude-sonnet-4", "anthropic"}

iex> MingaAgent.Config.split_model_spec("claude-sonnet-4@anthropic")
{"claude-sonnet-4", "anthropic"}

iex> MingaAgent.Config.split_model_spec("claude-sonnet-4")
{"claude-sonnet-4", nil}

strip_provider_prefix(model)

@spec strip_provider_prefix(String.t()) :: String.t()

Strips the provider encoding from a model spec string.

Returns the bare model name. If there's no provider encoding, returns the string unchanged.

unconfigured_model()

@spec unconfigured_model() :: String.t()

Returns the internal sentinel used when no configured provider has an available model.

without_hooks(config)

@spec without_hooks(t()) :: t()

Returns a config with agent hooks disabled.