Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content

Notifications

A tool calls ctx.notify to tell one person who uses the agent that something happened. The person reads the notification in the agent's app. They can also turn on email for the agent. Each notification belongs to one person, and no caller can read another person's notifications, operators included.

Send a notification

async handle(ctx) {
  const { id, result } = await ctx.notify({
    key: `report:${ctx.input.report_id}`,
    kind: 'report',
    title: 'Your weekly report is ready',
    body: 'Revenue is up 4% on last week.',
    link: `/reports/${ctx.input.report_id}`,
  });
  return { notification_id: id, result };
}

ctx.notify resolves to { id, result }. id is the notification's id. result is created, updated, or unchanged.

FieldRequiredLimitsDescription
keyyes1 to 200 charactersIdentifies the notification for its recipient. See Keys.
kindno1 to 40 charactersA category your app can filter or style by.
titleyes1 to 200 characters after trimming whitespaceThe line the inbox and the email show.
bodynoUp to 2,000 charactersLonger text for the app. Email carries it only when email is full.
linknoUp to 2,000 charactersAn app-relative path such as /reports/42. It must start with / and not with // or /\.
emailnolink_only (default) or fullWhat an email carries. See Email.
tono{ email }Another person who may use this agent. Without it, the recipient is ctx.userId.

Input that breaks a limit makes the call reject.

Errors

A refused notification rejects with an AmodalError whose code names the reason:

CodeCause
NO_RECIPIENTThe call has no to, and the run acts for no person, so ctx.userId is undefined.
RECIPIENT_NOT_ADMITTEDNo Amodal user has the to.email address, or that user has no access to the agent.
NOTIFY_LIMITThe recipient reached the daily limit for this agent.

Recipients

Without to, the notification goes to ctx.userId. That is the person signed in to the chat or to the app page that called the tool. For a scheduled run, it is the person who saved the automation. See The run's user.

A run that acts for no person has no ctx.userId. This covers API keys, SDK client tokens, and service tokens. Its ctx.notify calls without to fail with NO_RECIPIENT.

to: { email } names another person. That person must be an Amodal user with access to the agent. Otherwise the call fails with RECIPIENT_NOT_ADMITTED.

One person has one inbox per agent and environment, whether they sign in with an Amodal user id or a WorkOS user id. An idp:<sub> identity, or any other id that names no Amodal user, keeps its own inbox under that id and cannot receive email.

Keys

The key identifies one notification for one recipient. A second call with the same key and the same recipient does not add a notification:

  • When kind, title, body, link, and email all match the stored notification, nothing changes and result is unchanged.
  • When any of them differs, the notification takes the call's content, becomes unread again, and becomes eligible for email again. result is updated.

Use a key that names the thing the notification is about, such as report:42. A tool that runs again then updates the same notification instead of adding a duplicate.

The inbox lists notifications by creation time, newest first. An updated notification keeps its place in the list.

Scheduled task results

A run started by an automation that has an owner sends that owner one notification when it finishes without an error. The runtime sends it, so no tool has to call ctx.notify. Runs of automations that target the agent or a subagent send it. Runs of automations that target a tool do not. An automation with no owner notifies no one.

FieldValue
keyautomation:<automation id>
titleThe automation's name, cut at 200 characters
bodyThe run's final answer, cut at 2,000 characters
link/?resume=<session id>, which opens the run's chat
session_idThe run's session
emaillink_only

Every run of one automation uses the same key, so each run updates the same notification and marks it unread again. An automation takes one of its owner's 200 daily notifications.

The run's chat takes the automation's name as its title, so the chat list shows the same name as the notification. A run with no name keeps its first message as the title.

When the run ends on an ask_choice question, the title ends with needs your answer and the body starts with the question. The title is the part a link_only email shows, so the email tells the owner the run is waiting on them.

With capabilities.automations on, the run also gets the skip_report tool. A run that calls it sends no notification. A refused or failed notification is logged and does not fail the run.

A run that fails its last attempt sends the automation's owner a failure notification. Automations of every target kind send it, tools included. It is sent only while the owner can still use the agent.

FieldValue
keyautomation:<automation id>
titleThe automation's name followed by failed, 200 characters at most
bodyNone
link/tasks?task=<automation id>, which opens the automation's task page
emaillink_only

The failure notification uses the success notification's key, so it replaces the last result in the inbox and marks it unread again.

Read notifications in the app

useNotifications and useNotificationPrefs from @amodalai/react read the signed-in person's notifications and email setting:

import { useNotificationPrefs, useNotifications } from '@amodalai/react';
 
function Inbox() {
  const { data, unread, markRead } = useNotifications({ limit: 20 });
  const prefs = useNotificationPrefs();
 
  return (
    <section>
      <button onClick={() => void markRead('all')}>Mark {unread} read</button>
      {data?.notifications.map((n) => (
        <a key={n.id} href={n.link ?? '#'} onClick={() => void markRead([n.id])}>
          {n.read_at ? n.title : <strong>{n.title}</strong>}
        </a>
      ))}
      {prefs.data?.email_available && (
        <label>
          <input
            type="checkbox"
            checked={prefs.data.email === 'each'}
            onChange={(e) => void prefs.setEmail(e.target.checked ? 'each' : 'off')}
          />
          Email me
        </label>
      )}
    </section>
  );
}

The app's inbox renders body as Markdown flattened to one run of text. It keeps bold, italic, strikethrough, and code formatting, shows headings, lists, and links as plain text, and drops images. MarkdownPreview from @amodalai/react renders a body the same way.

A created or updated notification emits a notification_created event on /api/events. The event carries only the notification id and the recipient's user id, and only that recipient receives it. useNotifications refetches when it sees one, and after the event stream reconnects.

Email

Each person chooses whether an agent emails them. The setting is off or each, and it is off until the person changes it. It applies to one person, one agent, and one environment. email_available is false on a preview deploy, which sends no email, and when no email can reach the person, such as an idp:<sub> identity. The setting then has no effect.

The platform checks for notifications to email every 60 seconds. It sends one email per person per agent, listing every notification of theirs from that agent that is due. The email goes out once the person's notifications have been quiet for 60 seconds, or once the oldest of them has waited 15 minutes while the run keeps writing more. An email lists up to 20 notifications, newest first, and points to the app for the rest.

A notification is emailed only when all of these hold:

  • The agent runs a production deploy. Preview deploys send no email.
  • The notification is unread and has not been emailed since it was last created or updated.
  • It was created or updated in the last 24 hours, and after the person last changed their setting.
  • The person still has access to the agent.

Each notification is emailed at most once per version of its content. A failed send is not retried.

Every email shows each notification's title, linked to the agent's app at the notification's link, or at the app's home page without one. The body appears only for a notification sent with email: 'full'. The default, link_only, keeps the body out of email, so content that should stay inside the app does not reach a mailbox unless the tool opts in.

Each email carries an unsubscribe link and List-Unsubscribe headers for one-click unsubscribe. The link opens a page that asks for confirmation. Confirming sets that person's setting for the agent to off without signing in. The link does not expire. Notifications still appear in the app.

Limits and retention

Each recipient can get at most 200 created or updated notifications per agent and environment in a rolling 24 hours. Past that, a call that would create or change a notification fails with NOTIFY_LIMIT. A call that repeats a notification's current content still returns unchanged.

The platform deletes a notification 90 days after it was last created or updated.

Durable tools

In a durable tool, ctx.notify rejects with an error, like the other side-effecting context methods.

HTTP routes

The agent's runtime serves the signed-in caller's own notifications. A caller whose token names no person gets 403 with NO_USER. Responses are not cached.

MethodPathPurpose
GET/api/notificationsList notifications, newest first. Accepts ?unread=true, ?cursor=, and ?limit= (1 to 100).
POST/api/notifications/readMark notifications read: {ids} with 1 to 100 ids, or {all: true}.
GET/api/notifications/prefsRead the email setting.
PUT/api/notifications/prefsSet the email setting: {email: "off" | "each"}.

GET /api/notifications returns {notifications, next_cursor, unread_count} with 50 notifications unless limit says otherwise. Pass next_cursor back as cursor for the next page. unread_count counts every unread notification of the caller, not only the page. Each notification has id, key, kind, title, body, link, email, session_id, created_at, updated_at, and read_at.

POST /api/notifications/read returns {updated}, the number of notifications it marked read. Both prefs routes return {email, email_available}.

Local development

amodal dev keeps notifications in memory, so they are lost when it stops. It sends no email, and email_available is always false. It refuses to.email with RECIPIENT_NOT_ADMITTED, because it has no user directory. It does not apply the daily limit. The routes, keys, and notification_created events work as they do on a hosted runtime.