Agent Notification Systems

Production-grade guide to agent notification systems covering architecture patterns, implementation strategies, testing approaches, and operational best practices for enterprise engineering teams.

Agent Notification Systems are the mechanisms by which autonomous agents detect events, evaluate conditions, and deliver timely, targeted alerts to users, services, or other agents. They matter when agents must act beyond their own execution loop—when they need to coordinate, report, or trigger workflows based on internal state, external signals, or thresholds. A notification system is essential whenever an agent must inform someone or something that something has happened, is happening, or will happen, and must do so reliably, with minimal latency, across distributed environments.

Triggering Notifications

An agent triggers a notification when it detects a condition that warrants attention. The trigger is typically a state change, a metric crossing a threshold, or a scheduled event. The most common triggers are:

The agent uses a standardized interface to emit a notification. The interface consists of a notification object with the following required fields:

{
  "event_id": "uuidv4",
  "timestamp": "2025-04-05T12:34:56.789Z",
  "source": "agent://inventory/stock-checker",
  "severity": "info|warning|error|critical",
  "title": "Low stock for product X",
  "body": "Product ID 4523 has only 3 units in stock. Expected delivery in 2 days.",
  "context": {
    "product_id": 4523,
    "current_stock": 3,
    "threshold": 10,
    "expected_delivery": "2025-04-07T10:00:00Z"
  },
  "metadata": {
    "agent_version": "1.3.2",
    "execution_id": "exec-7a2b4c",
    "trigger_source": "threshold"
  }
}

The severity field is used by notification consumers to route, prioritize, and escalate messages. The context object captures all relevant data for debugging or further processing. The metadata field is optional but recommended for audit and tracing.

Agents emit notifications via HTTP POST to a standard endpoint, typically /notifications:

curl -X POST https://notifier.example.com/notifications \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer ntfy-abc123" \
  -d '{
    "event_id": "a1b2c3d4-e5f6-7890-g1h2-i3j4k5l6m7n8",
    "timestamp": "2025-04-05T12:34:56.789Z",
    "source": "agent://inventory/stock-checker",
    "severity": "warning",
    "title": "Low stock for product X",
    "body": "Product ID 4523 has only 3 units in stock. Expected delivery in 2 days.",
    "context": {
      "product_id": 4523,
      "current_stock": 3,
      "threshold": 10,
      "expected_delivery": "2025-04-07T10:00:00Z"
    },
    "metadata": {
      "agent_version": "1.3.2",
      "execution_id": "exec-7a2b4c",
      "trigger_source": "threshold"
    }
  }'

The server responds with 202 Accepted on success, and 400 Bad Request if the payload is malformed. The most common failure is missing event_id or source, which leads to undeliverable or duplicated notifications.

Routing and Delivery

Once a notification is emitted, the system routes it based on a set of rules defined in a routing configuration. The configuration is a list of rules, each with a condition and a target.

A rule has the following structure:

{
  "id": "rule-123",
  "condition": {
    "field": "severity",
    "operator": "in|eq|gt|gte|lt|lte",
    "value": ["warning", "error"]
  },
  "target": {
    "type": "email|slack|webhook|sms|push",
    "config": {
      "channel": "#alerts",
      "recipient": "[email protected]",
      "template": "alert-{{severity}}.mustache"
    }
  },
  "priority": 5,
  "enabled": true
}

The condition field uses a simple query language: field is a key in the notification object, operator compares the field value to value, which can be a scalar or array. The priority field determines the order in which rules are evaluated; higher priority rules are evaluated first and can override lower-priority ones.

The delivery mechanism is defined by the target.type. For example:

Routing is performed in order of priority. A notification is processed by applying each rule in sequence. The first rule whose condition matches is selected, and its target is used for delivery. If multiple rules match, the highest-priority one wins.

Delivery Failures and Retries

Delivery may fail due to network issues, provider throttling, or invalid configuration. The system must retry failed deliveries with exponential backoff and a maximum retry limit.

A delivery attempt is recorded in a delivery_attempts table:

attempt_idnotification_idtarget_typetarget_configstatuserrorretry_countscheduled_atcompleted_at
1001ntfy-a1b2c3demail{ "to": "[email protected]" }failed"500 Internal Server Error"22025-04-05T12:35:00Znull

The system maintains a retry queue, typically implemented as a message broker (e.g., Kafka, RabbitMQ, AWS SQS). Failed deliveries are requeued with increasing delay: 1 minute after first failure, 5 minutes after second, 15 minutes after third, then 1 hour, 3 hours, and so on.

The most common failure is delivery timeout—a delivery attempt takes longer than the configured timeout (default 30 seconds), leading to incomplete or stale deliveries. Another silent failure is duplicate delivery: a notification is sent multiple times due to a retry loop, but the delivery system does not deduplicate. This causes users to receive the same alert multiple times.

To prevent duplicates, the system uses event_id as a deduplication key. Each delivery is marked with the event_id, and the target system checks for existing deliveries before processing a new one. If the event_id already exists, the delivery is skipped.

Notification Templates and Contextualization

Templates are used to format the body of a notification. They are rendered using the full notification object as context. The system supports a simple template language with variable interpolation, conditionals, and loops.

A template is a string with placeholders:

{{#context}}
  <p><strong>Product:</strong> {{product_name}}</p>
  <p><strong>Current Stock:</strong> {{current_stock}}</p>
  <p><strong>Threshold:</strong> {{threshold}}</p>
  <p><strong>Expected Delivery:</strong> {{expected_delivery}}</p>
{{/context}}

<p><em>Alert generated by {{source}}</em></p>

The context object is merged with the template variables. The title and body fields are rendered separately. The template field in the target configuration specifies the template name or path.

A common mistake is confusing body and context in the template: the body field is used as the initial text, but context is used to populate the template. If the context object includes product_name, but the template expects name, the field is ignored.

Another sharp edge is template resolution: the system looks for templates in a hierarchy. First, it checks for a template named alert-{{severity}}.mustache. If not found, it falls back to alert-default.mustache. If neither exists, it uses a built-in default template. The fallback order is:

  1. {template_name}
  2. alert-{{severity}}.mustache
  3. alert-{{source}}.mustache
  4. alert-default.mustache

This allows fine-grained customization without requiring a new template for every notification type.

Configuration and Monitoring

The notification system is configured via a set of configuration keys, typically in a file or environment variables. The configuration is structured as a JSON object with the following top-level keys:

{
  "notifications": {
    "routing": [
      {
        "id": "high-priority-alerts",
        "condition": {
          "field": "severity",
          "operator": "in",
          "value": ["critical", "error"]
        },
        "target": {
          "type": "webhook",
          "config": {
            "url": "https://alerting-api.example.com/v1/ingest",
            "headers": {
              "X-Source": "agent-notifier"
            },
            "method": "POST"
          }
        },
        "priority": 10,
        "enabled": true
      }
    ],
    "delivery": {
      "retry_backoff": [1, 5, 15, 60, 180],
      "max_retries": 5,
      "deduplication_window": "1h",
      "timeout": "30s"
    },
    "templates": {
      "path": "/etc/notifications/templates",
      "default": "alert-default.mustache"
    },
    "logging": {
      "level": "info",
      "output": "stdout|file|syslog",
      "file": "/var/log/notifications.log"
    }
  }
}

The routing array defines the rule set. The delivery object controls retry and deduplication behavior. The templates object specifies where templates are stored and which one is the default.

The system exposes a health endpoint at /health that returns a JSON object with status, uptime, and queue metrics:

{
  "status": "ok",
  "uptime": "12d3h45m22s",
  "queues": {
    "pending": 142,
    "failed": 17,
    "retrying": 8
  },
  "last_updated": "2025-04-05T12:34:56.789Z"
}

The status field is ok, warning, or critical. The queues object shows the number of notifications in each state. The endpoint is used by orchestration systems (e.g., Kubernetes, systemd) to monitor the system.

Common Failure Modes

The system assumes that all rules are evaluated in order, and the first match wins. This is a common source of confusion when a rule with lower priority is expected to apply, but a higher-priority rule is missed due to a typo in a field name or condition.

Summary

A notification system is the bridge between agent execution and human or service awareness. It is not just about sending messages—it is about ensuring that the right message reaches the right recipient, at the right time, with the right context. The key components are: a standardized notification object, a routing engine based on priority rules, a delivery pipeline with retries and deduplication, and a template system for contextualization. The system must be configured to handle failures silently, with clear monitoring and error reporting. The most critical insight is that the notification object is the single source of truth, and every field, every rule, and every template must be understood to design, debug, and scale the system effectively.

This page was rewritten on 13 October 2026. It replaced a templated version that was not specific to its own title. How these pages are written and checked. If anything here is wrong, tell us at [email protected] and we will correct it.