YAML configuration

Define every agent in one file and load them with AgentKavach.from_yaml(). Use YAML when you run a fleet of agents that share alert channels or a budget pool.

Optional

YAML is one of three ways to configure agents. You can configure each agent in code (see Quickstart) or manage budgets and alerts from the dashboard.

Example #

yaml
# agentkavach.yaml

channels:
  team-slack:
    type: slack
    webhook_url: ${AGENTKAVACH_SLACK_WEBHOOK_URL}
  oncall-pd:
    type: pagerduty
    routing_key: ${AGENTKAVACH_PAGERDUTY_ROUTING_KEY}

org_budget:
  limit: 1000
  period: daily

defaults:
  provider: openai
  budget:
    type: daily
    limit: 50
  alerts:
    - threshold: 0.80
      channels: [team-slack]
    - threshold: 1.0
      channels: [team-slack, kill]

agents:
  research-bot:
    budget:
      type: daily
      limit: 100
    alerts:
      - threshold: 0.80
        channels: [team-slack]
      - threshold: 0.95
        channels: [oncall-pd]
      - threshold: 1.0
        channels: [oncall-pd, kill]

  support-agent:
    provider: anthropic
    budget: default          # inherit defaults.budget

Loading

python
from agentkavach import AgentKavach

# Load every agent
clients = AgentKavach.from_yaml("agentkavach.yaml", on_kill=lambda: None)
research = clients["research-bot"]

# Load a single agent
support = AgentKavach.from_yaml("agentkavach.yaml", agent="support-agent")

Schema #

Top-level keys

ParameterTypeRequiredDefaultDescription
channelsmapNoNamed alert channel definitions. Referenced by name in alerts. The built-in 'kill' is always available.
org_budgetmapNoSingle org-wide budget applied to every agent loaded from this file (limit, period).
defaultsmapNoDefault settings merged into every agent.
agentsmapYesAgent definitions, keyed by agent name.

channels.<name>

ParameterTypeRequiredDefaultDescription
typestringYesOne of "slack", "email", "pagerduty", "webhook".
webhook_urlstringNoSlack only.
tostringNoEmail recipient.
api_keystringNoEmail: legacy Resend key. Omit it — the cloud delivers email for you.
routing_keystringNoPagerDuty Events API v2 routing key.
urlstringNoWebhook target URL.
secretstringNoWebhook HMAC-SHA256 signing secret.

agents.<name>.budget

ParameterTypeRequiredDefaultDescription
typestringNo"daily""daily", "monthly", or "total".
limitfloatNo100.0Limit in USD. Must be > 0.

The literal budget: default tells the loader to inherit defaults.budget verbatim.

agents.<name>.guardrails

Per-run guardrails, identical to the inline constructor arguments. Each is optional; an unknown key raises ValueError so a typo can never silently disable a limit.

ParameterTypeRequiredDefaultDescription
max_tokens_per_runintNoRaise TokenLimitError once the run's total tokens reach this cap.
max_calls_per_runintNoRaise CallLimitError once the run reaches this many LLM calls.
max_runtime_secondsfloatNoRaise RuntimeLimitError once the run's wall-clock reaches this duration.
detect_loopsboolNofalseRaise LoopDetectedError when a repeating call pattern is detected.
loop_thresholdintNo3Number of repetitions that counts as a loop (with detect_loops).
yaml
agents:
  research-bot:
    budget:
      type: daily
      limit: 50
    guardrails:
      max_tokens_per_run: 200000
      max_runtime_seconds: 600
      max_calls_per_run: 100
      detect_loops: true
      loop_threshold: 3

agents.<name>.alerts

A list of rules.

ParameterTypeRequiredDefaultDescription
thresholdfloatYesTrigger ratio in (0.0, 1.0]. Alias: "at".
channelslist[string]No["email"]Channel names from the channels: section, plus the built-in 'kill'. Unknown names raise ValueError.
actionstringNoLegacy convenience: "kill" appends "kill" to channels.

Other agent fields

ParameterTypeRequiredDefaultDescription
providerstringNo"openai""openai", "anthropic", "google", or "mistral".
save_promptsboolNofalseSend prompt text to telemetry. Off by default.
fail_on_errorboolNofalseWhen true, any internal SDK error invokes on_kill and re-raises instead of failing open.

org_budget

ParameterTypeRequiredDefaultDescription
limitfloatYesOrg-wide limit in USD.
periodstringNo"daily""daily", "monthly", or "total".

Environment variables #

AgentKavach does not expand ${VAR} inside YAML values, and it never reads credentials from the environment on your behalf. Use shell expansion with envsubst or a templating tool to fill the values in, or pass the credential explicitly to the constructor.

Validation #

The loader raises plain Python exceptions when something is wrong.

  • ValueError for unknown channel types, undefined channel references in alerts, unknown budget types, or thresholds outside (0, 1.0].
  • KeyError when from_yaml(..., agent="name") is called with an agent that is not in the file.
  • FileNotFoundError or yaml.YAMLError for missing files or malformed YAML.