Skip to main content

agent-alerts

Structured alert routing to humans and AI agents.

Install

pip install agent-alerts
pip install "agent-alerts[mcp]"

Python imports stay under alerts.

Quick Start

Send a simple alert directly to Telegram:

from alerts import send

send("Screen complete: 4 names passed", channel="telegram")

That reads TELEGRAM_BOT_TOKEN and TELEGRAM_CHAT_ID from your environment unless you pass token= and chat_id= explicitly.

Use AlertRouter for structured routing, thresholds, quiet hours, and agent follow-up:

from alerts import Alert, AlertCategory, AlertLevel, AlertRouter

router = AlertRouter(config_path="alerting.yaml")

result = router.send(
    Alert(
        title="Estimate revisions turning negative",
        body="NVDA revisions rolled over after guidance.",
        level=AlertLevel.HIGH,
        category=AlertCategory.SIGNAL,
        source="portfolio-system",
        source_type="estimate_revisions",
        metadata={"passed_count": 1},
    )
)

print(result.delivered_channels)
print(result.agent_dispatched)

Send Authority

Every outbound send (Telegram, iMessage, email, the agent channel, send, AlertRouter, and the MCP notify_* tools) passes one shared transport gate governed by a typed alerts.SendMode:

  • SendMode.DENY (default): refuses every send with alerts.SendNotAuthorized before any network, SMTP, subprocess, or agent-dispatch work starts.
  • SendMode.LIVE: requires a host-injected predicate (alerts.set_send_mode(alerts.SendMode.LIVE, predicate=is_production_runtime) or alerts.set_send_authority(is_production_runtime)). The predicate is called on every send attempt; environment variables alone can never authorize live sends.
  • SendMode.SINK: routes every send path (send, AlertRouter, and direct channel functions) to a local JSONL sink (alerts.set_send_mode(alerts.SendMode.SINK, sink_path=...)), clears any live predicate, and reports delivered: False.
import alerts

alerts.set_send_mode(alerts.SendMode.LIVE, predicate=is_production_runtime)

For process-level configuration, alerts.configure_send_mode_from_env(env, live_predicate=...) reads one variable, ALERTS_SEND_MODE (deny, live, or sink:<path>). Requesting live without a host live_predicate raises SendNotAuthorized. The MCP notify_send and notify_test_channel tools return a non-recoverable SendNotAuthorized error envelope when denied, and notify_send returns status: "sink" with delivered: False in sink mode. alerts.clear_send_authority() returns to SendMode.DENY.

Channels

Channel Purpose Required config
telegram Fast human notification TELEGRAM_BOT_TOKEN, TELEGRAM_CHAT_ID
imessage Local macOS delivery IMESSAGE_TARGET or channels.imessage.recipient; optional backend, service
email SMTP delivery smtp_host, smtp_port, from, to plus EMAIL_USERNAME, EMAIL_PASSWORD
agent Background agent analysis agent_name, dispatch_fn on router; optional notify

Named Channel Variants

Define multiple instances of the same channel type for different contexts:

channels:
  telegram-analyst:
    enabled: true
    bot_token_env: ANALYST_BOT_TOKEN
    chat_id_env: TELEGRAM_CHAT_ID
  telegram-finance:
    enabled: true
    bot_token_env: FINANCE_BOT_TOKEN
    chat_id_env: TELEGRAM_CHAT_ID
  agent-analyst:
    enabled: true
    agent_name: alerts-agent
    notify: telegram
  agent-finance:
    enabled: true
    agent_name: finance-agent
    notify: telegram

routing:
  critical: [telegram-analyst, agent-analyst]
  high: [telegram-analyst, agent-analyst]
  normal: [telegram-analyst]
  by_category:
    budget:
      high: [telegram-finance, agent-finance]
      normal: [telegram-finance]

Channel names are resolved by prefix: telegram-* → TelegramChannel, agent-* → AgentChannel, etc. Each variant reads its own credentials from channel_config. Plain names (telegram, agent) still work for backward compatibility.

Variants must be defined in channels: — undefined names are rejected to prevent typos silently falling back to default credentials.

Agent Channel

The agent channel dispatches alerts to an AI agent for analysis. The caller provides a dispatch_fn when constructing the router:

def my_dispatch(agent_name, task, notify, env, alert_context):
    """Called on a background thread by AgentChannel."""
    # invoke the agent, send notification, etc.
    ...

router = AlertRouter(
    config_path="alerting.yaml",
    agent_dispatch_fn=my_dispatch,
)

Config:

channels:
  agent:
    enabled: true
    agent_name: alerts-agent
    notify: telegram          # where to send agent findings

Independent Agent Rate Limiting

The agent channel can have its own rate budget, independent of human channels:

rate_limits:
  enabled: true
  global_max_per_hour: 20
  agent_max_per_hour: 5       # opt-in, 0 or absent = agent follows human limits

When human channels are rate-limited, the agent can still fire if under its own agent_max_per_hour budget. This prevents losing agent analysis during alert bursts.

Router Config

Example alerting.yaml:

schema_version: 1
on_config_error: use_last_good

channels:
  telegram:
    enabled: true
  agent:
    enabled: true
    agent_name: alerts-agent
    notify: telegram

routing:
  critical: [telegram, agent]
  high: [telegram, agent]
  normal: [telegram]
  low: []
  by_category:
    signal:
      critical: [telegram, agent]
    screen_result:
      high: [telegram, agent]

quiet_hours:
  enabled: true
  start: "22:00"
  end: "07:00"
  timezone: "America/New_York"
  per_channel:
    agent:
      enabled: false

rate_limits:
  enabled: true
  global_max_per_hour: 20
  agent_max_per_hour: 5

thresholds:
  _default:
    min_passed_count: 1
    default_level: normal
    max_per_hour: 3
  estimate_revisions:
    min_passed_count: 1
    level_rules:
      - when:
          passed_count_gte: 3
        level: critical

MCP Server

The package exposes an MCP server entry point:

alerts-mcp
python -m alerts.mcp_server

It provides four tools:

  • notify_send
  • notify_preview
  • notify_list_channels
  • notify_test_channel

notify_send always requires the confirmation token returned for the exact payload by notify_preview; environment variables and caller-supplied mode flags do not bypass that gate.

License

MIT

Metadata

Release files for agent-alerts 0.3.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for agent-alerts 0.3.2
File Size Uploaded Provenance Actions
agent_alerts-0.3.2.tar.gz 21.3 kB Without provenance Details for agent_alerts-0.3.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for agent-alerts 0.3.2
File Interpreter ABI Platform Actions
agent_alerts-0.3.2-py3-none-any.whl Python 3 none any Details for agent_alerts-0.3.2-py3-none-any.whl

Total release size: 48.8 kB

Release files / agent_alerts-0.3.2.tar.gz

Download URL agent_alerts-0.3.2.tar.gz
Size 21.3 kB
Tags Source
SHA-256 checksum
How to use checksums
c718c113cf47ae4b6f08c46a0fb6afb1ca3a1a0cee67daeea17dd668abf3df79
BLAKE2b-256 checksum
How to use checksums
2feedbe8ee3fda6ae84194dfdcdc5f5454493d9c4497f9de2289fd6f14e18ef6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Release files / agent_alerts-0.3.2-py3-none-any.whl

Download URL agent_alerts-0.3.2-py3-none-any.whl
Size 27.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
217491a60a40f211a674c3f9cdad9b5fac6e5088ca54aa72766e45be496c8681
BLAKE2b-256 checksum
How to use checksums
885aad5a2d13f906f1cef643a9b0e24735bb9592f14ebddf75acf074bb322e64
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Security for agent-alerts 0.3.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page