# `Alloy.Agent.Config`
[🔗](https://github.com/alloy-ex/alloy/blob/v0.10.1/lib/alloy/agent/config.ex#L1)

Configuration for an agent run.

Built from the options passed to `Alloy.run/2`. Immutable for the
duration of the run.

# `compaction`

```elixir
@type compaction() :: %{
  reserve_tokens: pos_integer(),
  keep_recent_tokens: pos_integer(),
  fallback: :truncate
}
```

# `t`

```elixir
@type t() :: %Alloy.Agent.Config{
  code_execution: boolean(),
  compaction: compaction(),
  compaction_explicit: %{
    reserve_tokens: boolean(),
    keep_recent_tokens: boolean()
  },
  context: map(),
  fallback_providers: [{module(), map()}],
  max_budget_cents: number() | nil,
  max_pending: non_neg_integer(),
  max_retries: non_neg_integer(),
  max_tokens: pos_integer(),
  max_tokens_explicit?: boolean(),
  max_turns: pos_integer(),
  middleware: [module()],
  model_metadata_overrides: map(),
  on_compaction: (list(), Alloy.Agent.State.t() -&gt; any()) | nil,
  on_shutdown: (Alloy.Session.t() -&gt; any()) | nil,
  provider: module(),
  provider_config: map(),
  pubsub: module() | nil,
  retry_backoff_ms: pos_integer(),
  subscribe: [String.t()],
  system_prompt: String.t() | nil,
  timeout_ms: pos_integer(),
  tool_timeout: pos_integer(),
  tools: [module()],
  until_tool: String.t() | nil,
  working_directory: String.t()
}
```

# `from_opts`

```elixir
@spec from_opts(keyword()) :: t()
```

Builds a config from `Alloy.run/2` options.

# `with_provider`

```elixir
@spec with_provider(t(), module() | {module(), keyword() | map()}) :: t()
```

Returns an updated config with a new provider while preserving unrelated options.

If `max_tokens` was not set explicitly, the budget is re-derived from the new
provider model and current `model_metadata_overrides`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
