Jido.Plugin.Config (Jido v2.3.1)

Copy Markdown View Source

Resolves and validates plugin configuration.

Config resolution merges three sources (in order of precedence):

  1. Per-agent overrides (highest priority)
  2. Application environment config (Application.get_env(otp_app, plugin_module))
  3. Default values from the plugin's config_schema (lowest priority)

Example

# In config/config.exs:
config :my_app, MyApp.SlackPlugin,
  token: "default-token",
  channel: "#general"

# In agent definition:
use Jido.Agent,
  plugins: [
    {MyApp.SlackPlugin, %{channel: "#support"}}  # Override channel
  ]

# Resolved config:
%{token: "default-token", channel: "#support"}

Summary

Functions

Resolves configuration for a plugin module by merging app env with overrides.

Functions

resolve_config(plugin_module, overrides \\ %{})

@spec resolve_config(module(), map()) :: {:ok, map()} | {:error, list()}

Resolves configuration for a plugin module by merging app env with overrides.

Parameters

  • plugin_module - The plugin module (must implement otp_app/0 and optionally config_schema/0)
  • overrides - Per-agent config overrides (map)

Returns

  • {:ok, resolved_config} - Successfully resolved and validated config
  • {:error, errors} - Validation errors from Zoi schema

Examples

Config.resolve_config(MyApp.SlackPlugin, %{channel: "#support"})
# => {:ok, %{token: "env-token", channel: "#support"}}

Config.resolve_config(MyApp.SlackPlugin, %{invalid: "field"})
# => {:error, validation_errors}

resolve_config!(plugin_module, overrides \\ %{})

@spec resolve_config!(module(), map()) :: map()

Like resolve_config/2 but raises on validation errors.

Examples

Config.resolve_config!(MyApp.SlackPlugin, %{channel: "#support"})
# => %{token: "env-token", channel: "#support"}

Config.resolve_config!(MyApp.SlackPlugin, %{invalid: "field"})
# Raises ArgumentError when the resolved config fails schema validation.