> ## Documentation Index
> Fetch the complete documentation index at: https://agdiai-597e782f.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Configuration

# Configuration

Agdi reads an optional **JSON5** (JSON5 supports comments and trailing commas) config from `~/.agdi/agdi.json`.

If the file is missing, Agdi uses safe defaults. Common reasons to add a config:

* Connect channels and control who can message the bot
* Set models, tools, sandboxing, or automation (cron, hooks)
* Tune sessions, media, networking, or UI

See the [full reference](https://agdiai-597e782f.mintlify.site/gateway/configuration-reference.md) for every available field.

> [!TIP]
>
> **New to configuration?** Start with `agdi onboard` for interactive setup, or check out the [Configuration Examples](https://agdiai-597e782f.mintlify.site/gateway/configuration-examples.md) guide for complete copy-paste configs.

## Minimal config

```json5 theme={"theme":{"light":"min-light","dark":"min-dark"}}
// ~/.agdi/agdi.json
{
  agents: { defaults: { workspace: "~/.agdi/workspace" } },
  channels: { whatsapp: { allowFrom: ["+15555550123"] } },
}
```

## Editing config

> [tab] Interactive wizard
>
> ```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
> agdi onboard       # full onboarding flow
> agdi configure     # config wizard
> ```

> [tab] CLI (one-liners)
>
> ```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
> agdi config get agents.defaults.workspace
> agdi config set agents.defaults.heartbeat.every "2h"
> agdi config unset plugins.entries.brave.config.webSearch.apiKey
> ```

> [tab] Control UI
>
> Open [http://127.0.0.1:18789](http://127.0.0.1:18789) and use the **Config** tab.
> The Control UI renders a form from the config schema, with a **Raw JSON** editor as an escape hatch.

> [tab] Direct edit
>
> Edit `~/.agdi/agdi.json` directly. The Gateway watches the file and applies changes automatically (see [hot reload](#config-hot-reload)).

## Strict validation

> [!WARNING]
>
> Agdi only accepts configurations that fully match the schema. Unknown keys, malformed types, or invalid values cause the Gateway to **refuse to start**. The only root-level exception is `$schema` (string), so editors can attach JSON Schema metadata.

When validation fails:

* The Gateway does not boot
* Only diagnostic commands work (`agdi doctor`, `agdi logs`, `agdi health`, `agdi status`)
* Run `agdi doctor` to see exact issues
* Run `agdi doctor --fix` (or `--yes`) to apply repairs

## Common tasks

> [accordion] Set up a channel (WhatsApp, Telegram, Discord, etc.)
>
> Each channel has its own config section under `channels.<provider>`. See the dedicated channel page for setup steps:
>
> * [WhatsApp](https://agdiai-597e782f.mintlify.site/channels/whatsapp.md) — `channels.whatsapp`
> * [Telegram](https://agdiai-597e782f.mintlify.site/channels/telegram.md) — `channels.telegram`
> * [Discord](https://agdiai-597e782f.mintlify.site/channels/discord.md) — `channels.discord`
> * [Slack](https://agdiai-597e782f.mintlify.site/channels/slack.md) — `channels.slack`
> * [Signal](https://agdiai-597e782f.mintlify.site/channels/signal.md) — `channels.signal`
> * [iMessage](https://agdiai-597e782f.mintlify.site/channels/imessage.md) — `channels.imessage`
> * [Google Chat](https://agdiai-597e782f.mintlify.site/channels/googlechat.md) — `channels.googlechat`
> * [Mattermost](https://agdiai-597e782f.mintlify.site/channels/mattermost.md) — `channels.mattermost`
> * [Microsoft Teams](https://agdiai-597e782f.mintlify.site/channels/msteams.md) — `channels.msteams`
>
> All channels share the same DM policy pattern:
>
> ```json5 theme={"theme":{"light":"min-light","dark":"min-dark"}}
> {
>   channels: {
>     telegram: {
>       enabled: true,
>       botToken: "123:abc",
>       dmPolicy: "pairing",   // pairing | allowlist | open | disabled
>       allowFrom: ["tg:123"], // only for allowlist/open
>     },
>   },
> }
> ```

> [accordion] Choose and configure models
>
> Set the primary model and optional fallbacks:
>
> ```json5 theme={"theme":{"light":"min-light","dark":"min-dark"}}
> {
>   agents: {
>     defaults: {
>       model: {
>         primary: "anthropic/claude-sonnet-4-6",
>         fallbacks: ["openai/gpt-5.2"],
>       },
>       models: {
>         "anthropic/claude-sonnet-4-6": { alias: "Sonnet" },
>         "openai/gpt-5.2": { alias: "GPT" },
>       },
>     },
>   },
> }
> ```
>
> * `agents.defaults.models` defines the model catalog and acts as the allowlist for `/model`.
> * Model refs use `provider/model` format (e.g. `anthropic/claude-opus-4-6`).
> * `agents.defaults.imageMaxDimensionPx` controls transcript/tool image downscaling (default `1200`); lower values usually reduce vision-token usage on screenshot-heavy runs.
> * See [Models CLI](https://agdiai-597e782f.mintlify.site/concepts/models.md) for switching models in chat and [Model Failover](https://agdiai-597e782f.mintlify.site/concepts/model-failover.md) for auth rotation and fallback behavior.
> * For custom/self-hosted providers, see [Custom providers](https://agdiai-597e782f.mintlify.site/gateway/configuration-reference.md#custom-providers-and-base-urls) in the reference.

> [accordion] Control who can message the bot
>
> DM access is controlled per channel via `dmPolicy`:
>
> * `"pairing"` (default): unknown senders get a one-time pairing code to approve
> * `"allowlist"`: only senders in `allowFrom` (or the paired allow store)
> * `"open"`: allow all inbound DMs (requires `allowFrom: ["*"]`)
> * `"disabled"`: ignore all DMs
>
> For groups, use `groupPolicy` + `groupAllowFrom` or channel-specific allowlists.
>
> See the [full reference](https://agdiai-597e782f.mintlify.site/gateway/configuration-reference.md#dm-and-group-access) for per-channel details.

> [accordion] Set up group chat mention gating
>
> Group messages default to **require mention**. Configure patterns per agent:
>
> ```json5 theme={"theme":{"light":"min-light","dark":"min-dark"}}
> {
>   agents: {
>     list: [
>       {
>         id: "main",
>         groupChat: {
>           mentionPatterns: ["@agdi", "agdi"],
>         },
>       },
>     ],
>   },
>   channels: {
>     whatsapp: {
>       groups: { "*": { requireMention: true } },
>     },
>   },
> }
> ```
>
> * **Metadata mentions**: native @-mentions (WhatsApp tap-to-mention, Telegram @bot, etc.)
> * **Text patterns**: safe regex patterns in `mentionPatterns`
> * See [full reference](https://agdiai-597e782f.mintlify.site/gateway/configuration-reference.md#group-chat-mention-gating) for per-channel overrides and self-chat mode.

> [accordion] Tune gateway channel health monitoring
>
> Control how aggressively the gateway restarts channels that look stale:
>
> ```json5 theme={"theme":{"light":"min-light","dark":"min-dark"}}
> {
>   gateway: {
>     channelHealthCheckMinutes: 5,
>     channelStaleEventThresholdMinutes: 30,
>     channelMaxRestartsPerHour: 10,
>   },
>   channels: {
>     telegram: {
>       healthMonitor: { enabled: false },
>       accounts: {
>         alerts: {
>           healthMonitor: { enabled: true },
>         },
>       },
>     },
>   },
> }
> ```
>
> * Set `gateway.channelHealthCheckMinutes: 0` to disable health-monitor restarts globally.
> * `channelStaleEventThresholdMinutes` should be greater than or equal to the check interval.
> * Use `channels.<provider>.healthMonitor.enabled` or `channels.<provider>.accounts.<id>.healthMonitor.enabled` to disable auto-restarts for one channel or account without disabling the global monitor.
> * See [Health Checks](https://agdiai-597e782f.mintlify.site/gateway/health.md) for operational debugging and the [full reference](https://agdiai-597e782f.mintlify.site/gateway/configuration-reference.md#gateway) for all fields.

> [accordion] Configure sessions and resets
>
> Sessions control conversation continuity and isolation:
>
> ```json5 theme={"theme":{"light":"min-light","dark":"min-dark"}}
> {
>   session: {
>     dmScope: "per-channel-peer",  // recommended for multi-user
>     threadBindings: {
>       enabled: true,
>       idleHours: 24,
>       maxAgeHours: 0,
>     },
>     reset: {
>       mode: "daily",
>       atHour: 4,
>       idleMinutes: 120,
>     },
>   },
> }
> ```
>
> * `dmScope`: `main` (shared) | `per-peer` | `per-channel-peer` | `per-account-channel-peer`
> * `threadBindings`: global defaults for thread-bound session routing (Discord supports `/focus`, `/unfocus`, `/agents`, `/session idle`, and `/session max-age`).
> * See [Session Management](https://agdiai-597e782f.mintlify.site/concepts/session.md) for scoping, identity links, and send policy.
> * See [full reference](https://agdiai-597e782f.mintlify.site/gateway/configuration-reference.md#session) for all fields.

> [accordion] Enable sandboxing
>
> Run agent sessions in isolated Docker containers:
>
> ```json5 theme={"theme":{"light":"min-light","dark":"min-dark"}}
> {
>   agents: {
>     defaults: {
>       sandbox: {
>         mode: "non-main",  // off | non-main | all
>         scope: "agent",    // session | agent | shared
>       },
>     },
>   },
> }
> ```
>
> Build the image first: `scripts/sandbox-setup.sh`
>
> See [Sandboxing](https://agdiai-597e782f.mintlify.site/gateway/sandboxing.md) for the full guide and [full reference](https://agdiai-597e782f.mintlify.site/gateway/configuration-reference.md#agentsdefaultssandbox) for all options.

> [accordion] Enable relay-backed push for official iOS builds
>
> Relay-backed push is configured in `agdi.json`.
>
> Set this in gateway config:
>
> ```json5 theme={"theme":{"light":"min-light","dark":"min-dark"}}
> {
>   gateway: {
>     push: {
>       apns: {
>         relay: {
>           baseUrl: "https://relay.example.com",
>           // Optional. Default: 10000
>           timeoutMs: 10000,
>         },
>       },
>     },
>   },
> }
> ```
>
> CLI equivalent:
>
> ```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
> agdi config set gateway.push.apns.relay.baseUrl https://relay.example.com
> ```
>
> What this does:
>
> * Lets the gateway send `push.test`, wake nudges, and reconnect wakes through the external relay.
> * Uses a registration-scoped send grant forwarded by the paired iOS app. The gateway does not need a deployment-wide relay token.
> * Binds each relay-backed registration to the gateway identity that the iOS app paired with, so another gateway cannot reuse the stored registration.
> * Keeps local/manual iOS builds on direct APNs. Relay-backed sends apply only to official distributed builds that registered through the relay.
> * Must match the relay base URL baked into the official/TestFlight iOS build, so registration and send traffic reach the same relay deployment.
>
> End-to-end flow:
>
> 1. Install an official/TestFlight iOS build that was compiled with the same relay base URL.
> 2. Configure `gateway.push.apns.relay.baseUrl` on the gateway.
> 3. Pair the iOS app to the gateway and let both node and operator sessions connect.
> 4. The iOS app fetches the gateway identity, registers with the relay using App Attest plus the app receipt, and then publishes the relay-backed `push.apns.register` payload to the paired gateway.
> 5. The gateway stores the relay handle and send grant, then uses them for `push.test`, wake nudges, and reconnect wakes.
>
> Operational notes:
>
> * If you switch the iOS app to a different gateway, reconnect the app so it can publish a new relay registration bound to that gateway.
> * If you ship a new iOS build that points at a different relay deployment, the app refreshes its cached relay registration instead of reusing the old relay origin.
>
> Compatibility note:
>
> * `AGDI_APNS_RELAY_BASE_URL` and `AGDI_APNS_RELAY_TIMEOUT_MS` still work as temporary env overrides.
> * `AGDI_APNS_RELAY_ALLOW_HTTP=true` remains a loopback-only development escape hatch; do not persist HTTP relay URLs in config.
>
> See [iOS App](https://agdiai-597e782f.mintlify.site/platforms/ios.md#relay-backed-push-for-official-builds) for the end-to-end flow and [Authentication and trust flow](https://agdiai-597e782f.mintlify.site/platforms/ios.md#authentication-and-trust-flow) for the relay security model.

> [accordion] Set up heartbeat (periodic check-ins)
>
> ```json5 theme={"theme":{"light":"min-light","dark":"min-dark"}}
> {
>   agents: {
>     defaults: {
>       heartbeat: {
>         every: "30m",
>         target: "last",
>       },
>     },
>   },
> }
> ```
>
> * `every`: duration string (`30m`, `2h`). Set `0m` to disable.
> * `target`: `last` | `whatsapp` | `telegram` | `discord` | `none`
> * `directPolicy`: `allow` (default) or `block` for DM-style heartbeat targets
> * See [Heartbeat](https://agdiai-597e782f.mintlify.site/gateway/heartbeat.md) for the full guide.

> [accordion] Configure cron jobs
>
> ```json5 theme={"theme":{"light":"min-light","dark":"min-dark"}}
> {
>   cron: {
>     enabled: true,
>     maxConcurrentRuns: 2,
>     sessionRetention: "24h",
>     runLog: {
>       maxBytes: "2mb",
>       keepLines: 2000,
>     },
>   },
> }
> ```
>
> * `sessionRetention`: prune completed isolated run sessions from `sessions.json` (default `24h`; set `false` to disable).
> * `runLog`: prune `cron/runs/<jobId>.jsonl` by size and retained lines.
> * See [Cron jobs](https://agdiai-597e782f.mintlify.site/automation/cron-jobs.md) for feature overview and CLI examples.

> [accordion] Set up webhooks (hooks)
>
> Enable HTTP webhook endpoints on the Gateway:
>
> ```json5 theme={"theme":{"light":"min-light","dark":"min-dark"}}
> {
>   hooks: {
>     enabled: true,
>     token: "shared-secret",
>     path: "/hooks",
>     defaultSessionKey: "hook:ingress",
>     allowRequestSessionKey: false,
>     allowedSessionKeyPrefixes: ["hook:"],
>     mappings: [
>       {
>         match: { path: "gmail" },
>         action: "agent",
>         agentId: "main",
>         deliver: true,
>       },
>     ],
>   },
> }
> ```
>
> Security note:
>
> * Treat all hook/webhook payload content as untrusted input.
> * Keep unsafe-content bypass flags disabled (`hooks.gmail.allowUnsafeExternalContent`, `hooks.mappings[].allowUnsafeExternalContent`) unless doing tightly scoped debugging.
> * For hook-driven agents, prefer strong modern model tiers and strict tool policy (for example messaging-only plus sandboxing where possible).
>
> See [full reference](https://agdiai-597e782f.mintlify.site/gateway/configuration-reference.md#hooks) for all mapping options and Gmail integration.

> [accordion] Configure multi-agent routing
>
> Run multiple isolated agents with separate workspaces and sessions:
>
> ```json5 theme={"theme":{"light":"min-light","dark":"min-dark"}}
> {
>   agents: {
>     list: [
>       { id: "home", default: true, workspace: "~/.agdi/workspace-home" },
>       { id: "work", workspace: "~/.agdi/workspace-work" },
>     ],
>   },
>   bindings: [
>     { agentId: "home", match: { channel: "whatsapp", accountId: "personal" } },
>     { agentId: "work", match: { channel: "whatsapp", accountId: "biz" } },
>   ],
> }
> ```
>
> See [Multi-Agent](https://agdiai-597e782f.mintlify.site/concepts/multi-agent.md) and [full reference](https://agdiai-597e782f.mintlify.site/gateway/configuration-reference.md#multi-agent-routing) for binding rules and per-agent access profiles.

> [accordion] Split config into multiple files (\$include)
>
> Use `$include` to organize large configs:
>
> ```json5 theme={"theme":{"light":"min-light","dark":"min-dark"}}
> // ~/.agdi/agdi.json
> {
>   gateway: { port: 18789 },
>   agents: { $include: "./agents.json5" },
>   broadcast: {
>     $include: ["./clients/a.json5", "./clients/b.json5"],
>   },
> }
> ```
>
> * **Single file**: replaces the containing object
> * **Array of files**: deep-merged in order (later wins)
> * **Sibling keys**: merged after includes (override included values)
> * **Nested includes**: supported up to 10 levels deep
> * **Relative paths**: resolved relative to the including file
> * **Error handling**: clear errors for missing files, parse errors, and circular includes

## Config hot reload

The Gateway watches `~/.agdi/agdi.json` and applies changes automatically — no manual restart needed for most settings.

### Reload modes

| Mode | Behavior |
| - | - |
| **`hybrid`** (default) | Hot-applies safe changes instantly. Automatically restarts for critical ones. |
| **`hot`** | Hot-applies safe changes only. Logs a warning when a restart is needed — you handle it. |
| **`restart`** | Restarts the Gateway on any config change, safe or not. |
| **`off`** | Disables file watching. Changes take effect on the next manual restart. |

```json5 theme={"theme":{"light":"min-light","dark":"min-dark"}}
{
  gateway: {
    reload: { mode: "hybrid", debounceMs: 300 },
  },
}
```

### What hot-applies vs what needs a restart

Most fields hot-apply without downtime. In `hybrid` mode, restart-required changes are handled automatically.

| Category | Fields | Restart needed? |
| - | - | - |
| Channels | `channels.*`, `web` (WhatsApp) — all built-in and extension channels | No |
| Agent & models | `agent`, `agents`, `models`, `routing` | No |
| Automation | `hooks`, `cron`, `agent.heartbeat` | No |
| Sessions & messages | `session`, `messages` | No |
| Tools & media | `tools`, `browser`, `skills`, `audio`, `talk` | No |
| UI & misc | `ui`, `logging`, `identity`, `bindings` | No |
| Gateway server | `gateway.*` (port, bind, auth, tailscale, TLS, HTTP) | **Yes** |
| Infrastructure | `discovery`, `canvasHost`, `plugins` | **Yes** |

> [!NOTE]
>
> `gateway.reload` and `gateway.remote` are exceptions — changing them does **not** trigger a restart.

## Config RPC (programmatic updates)

> [!NOTE]
>
> Control-plane write RPCs (`config.apply`, `config.patch`, `update.run`) are rate-limited to **3 requests per 60 seconds** per `deviceId+clientIp`. When limited, the RPC returns `UNAVAILABLE` with `retryAfterMs`.

> [accordion] config.apply (full replace)
>
> Validates + writes the full config and restarts the Gateway in one step.
>
> > [!WARNING]
> >
> > `config.apply` replaces the **entire config**. Use `config.patch` for partial updates, or `agdi config set` for single keys.
>
> Params:
>
> * `raw` (string) — JSON5 payload for the entire config
> * `baseHash` (optional) — config hash from `config.get` (required when config exists)
> * `sessionKey` (optional) — session key for the post-restart wake-up ping
> * `note` (optional) — note for the restart sentinel
> * `restartDelayMs` (optional) — delay before restart (default 2000)
>
> Restart requests are coalesced while one is already pending/in-flight, and a 30-second cooldown applies between restart cycles.
>
> ```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
> agdi gateway call config.get --params '{}'  # capture payload.hash
> agdi gateway call config.apply --params '{
>   "raw": "{ agents: { defaults: { workspace: \"~/.agdi/workspace\" } } }",
>   "baseHash": "<hash>",
>   "sessionKey": "agent:main:whatsapp:direct:+15555550123"
> }'
> ```

> [accordion] config.patch (partial update)
>
> Merges a partial update into the existing config (JSON merge patch semantics):
>
> * Objects merge recursively
> * `null` deletes a key
> * Arrays replace
>
> Params:
>
> * `raw` (string) — JSON5 with just the keys to change
> * `baseHash` (required) — config hash from `config.get`
> * `sessionKey`, `note`, `restartDelayMs` — same as `config.apply`
>
> Restart behavior matches `config.apply`: coalesced pending restarts plus a 30-second cooldown between restart cycles.
>
> ```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
> agdi gateway call config.patch --params '{
>   "raw": "{ channels: { telegram: { groups: { \"*\": { requireMention: false } } } } }",
>   "baseHash": "<hash>"
> }'
> ```

## Environment variables

Agdi reads env vars from the parent process plus:

* `.env` from the current working directory (if present)
* `~/.agdi/.env` (global fallback)

Neither file overrides existing env vars. You can also set inline env vars in config:

```json5 theme={"theme":{"light":"min-light","dark":"min-dark"}}
{
  env: {
    OPENROUTER_API_KEY: "sk-or-...",
    vars: { GROQ_API_KEY: "gsk-..." },
  },
}
```

> [accordion] Shell env import (optional)
>
> If enabled and expected keys aren't set, Agdi runs your login shell and imports only the missing keys:
>
> ```json5 theme={"theme":{"light":"min-light","dark":"min-dark"}}
> {
>   env: {
>     shellEnv: { enabled: true, timeoutMs: 15000 },
>   },
> }
> ```
>
> Env var equivalent: `AGDI_LOAD_SHELL_ENV=1`

> [accordion] Env var substitution in config values
>
> Reference env vars in any config string value with `${VAR_NAME}`:
>
> ```json5 theme={"theme":{"light":"min-light","dark":"min-dark"}}
> {
>   gateway: { auth: { token: "${AGDI_GATEWAY_TOKEN}" } },
>   models: { providers: { custom: { apiKey: "${CUSTOM_API_KEY}" } } },
> }
> ```
>
> Rules:
>
> * Only uppercase names matched: `[A-Z_][A-Z0-9_]*`
> * Missing/empty vars throw an error at load time
> * Escape with `$${VAR}` for literal output
> * Works inside `$include` files
> * Inline substitution: `"${BASE}/v1"` → `"https://api.example.com/v1"`

> [accordion] Secret refs (env, file, exec)
>
> For fields that support SecretRef objects, you can use:
>
> ```json5 theme={"theme":{"light":"min-light","dark":"min-dark"}}
> {
>   models: {
>     providers: {
>       openai: { apiKey: { source: "env", provider: "default", id: "OPENAI_API_KEY" } },
>     },
>   },
>   skills: {
>     entries: {
>       "image-lab": {
>         apiKey: {
>           source: "file",
>           provider: "filemain",
>           id: "/skills/entries/image-lab/apiKey",
>         },
>       },
>     },
>   },
>   channels: {
>     googlechat: {
>       serviceAccountRef: {
>         source: "exec",
>         provider: "vault",
>         id: "channels/googlechat/serviceAccount",
>       },
>     },
>   },
> }
> ```
>
> SecretRef details (including `secrets.providers` for `env`/`file`/`exec`) are in [Secrets Management](https://agdiai-597e782f.mintlify.site/gateway/secrets.md).
> Supported credential paths are listed in [SecretRef Credential Surface](https://agdiai-597e782f.mintlify.site/reference/secretref-credential-surface.md).

See [Environment](https://agdiai-597e782f.mintlify.site/help/environment.md) for full precedence and sources.

## Full reference

For the complete field-by-field reference, see **[Configuration Reference](https://agdiai-597e782f.mintlify.site/gateway/configuration-reference.md)**.

***

*Related: [Configuration Examples](https://agdiai-597e782f.mintlify.site/gateway/configuration-examples.md) · [Configuration Reference](https://agdiai-597e782f.mintlify.site/gateway/configuration-reference.md) · [Doctor](https://agdiai-597e782f.mintlify.site/gateway/doctor.md)*


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.