Notifications

Send notifications via email, Slack, or in-app channels. Supports system-wide and per-project channel configuration with trigger-based routing.

from sagewai import NotificationService, SlackWebhookChannel

svc = NotificationService()
svc.register_channel("slack", SlackWebhookChannel(webhook_url="https://hooks.slack.com/..."))
await svc.notify("budget_warning", "Budget Alert", "Agent exceeded 80% of daily budget")

NotificationService

Central notification dispatcher. Routes notifications to appropriate channels based on trigger type and project context.

from sagewai import NotificationService

svc = NotificationService(store=my_store)
svc.register_channel("email", email_channel)
svc.register_channel("slack", slack_channel)
svc.register_channel("in_app", inapp_channel)

# System-wide notification
await svc.notify("budget_warning", "Budget Alert", "Approaching limit")

# Per-project channel override
svc.register_channel("slack", project_slack, project_id="acme")

Constructor

ParameterTypeDefaultDescription
storeAnyNoneOptional store for notification history

Methods

MethodSignatureDescription
register_channelregister_channel(channel_type, channel, project_id=None)Register a notification channel
set_trigger_routingset_trigger_routing(trigger, channel_types)Configure which channels a trigger routes to
get_trigger_routingget_trigger_routing()Return current trigger routing config
notifyasync notify(trigger, title, body, severity="info", metadata={})Send a notification

Default Trigger Routing

TriggerChannels
budget_warningemail, slack, in_app
budget_exceededemail, slack, in_app
budget_throttledemail, slack, in_app
workflow_failedemail, slack, in_app
approval_requestedin_app

NotificationChannel (ABC)

Abstract base class for notification channels. Implement send() to create custom channels.

from sagewai import NotificationChannel

class WebhookChannel(NotificationChannel):
    async def send(
        self,
        title: str,
        body: str,
        severity: str,
        metadata: dict,
    ) -> bool:
        # Send via webhook, return True on success
        ...

Required Method

MethodSignatureReturnsDescription
sendasync send(title, body, severity, metadata)boolSend a notification. Must not raise.

SMTPChannel

Send notifications as HTML emails via SMTP. Requires aiosmtplib (pip install aiosmtplib).

from sagewai import SMTPChannel

channel = SMTPChannel(
    smtp_host="smtp.gmail.com",
    smtp_port=587,
    smtp_user="alerts@company.com",
    smtp_password="app-password",
    use_tls=True,
    from_address="alerts@company.com",
    to_addresses=["team@company.com"],
)

Constructor

ParameterTypeDefaultDescription
smtp_hoststrrequiredSMTP server hostname
smtp_portint587SMTP server port
smtp_userstr | NoneNoneSMTP username
smtp_passwordstr | NoneNoneSMTP password
use_tlsboolTrueUse TLS encryption
from_addressstrrequiredSender email address
to_addresseslist[str]requiredRecipient email addresses

SlackWebhookChannel

Send notifications to Slack via an incoming webhook. Posts Block Kit messages.

from sagewai import SlackWebhookChannel

channel = SlackWebhookChannel(
    webhook_url="https://hooks.slack.com/services/T.../B.../...",
    channel="#alerts",
)

Constructor

ParameterTypeDefaultDescription
webhook_urlstrrequiredSlack incoming webhook URL
channelstr | NoneNoneOverride channel name

InAppChannel

Publish notifications to an in-app event bus or callback. Used for real-time SSE-based alerts in the admin UI. Always returns True (best-effort delivery).

from sagewai import InAppChannel

channel = InAppChannel(
    callback=lambda event: event_bus.publish(event),
)

Constructor

ParameterTypeDefaultDescription
callbackCallable[[dict], None] | NoneNoneEvent handler function