Quick Start
Give Your Agent the Tool
send_message at any point mid-task to push a notification to the user.List Available Targets
action="list" first when you want the agent to pick the right channel rather than defaulting to "origin".How It Works
| Component | Purpose |
|---|---|
| send_message tool | Agent-callable function; resolves messenger from context |
| OutboundMessengerProtocol | Interface the gateway registers per-turn |
| SessionContext | Task-local registry — no globals, safe for concurrent handlers |
| Gateway | Delivers to Telegram, Slack, Discord, WhatsApp, etc. |
Targets
Choose the right target form for your situation:| Target form | Example | Description |
|---|---|---|
"origin" | "origin" | The chat this conversation came from (default) |
"<platform>" | "telegram" | That platform’s configured home channel |
"<platform>:<chat_id>" | "slack:#ops" | A specific chat or channel |
"<platform>:<chat_id>:<thread_id>" | "slack:#ops:T123" | A specific thread within a chat |
"<alias>" | "my-ops-alert" | A named alias configured in the gateway |
Attachments (MEDIA:)
AppendMEDIA:<path> to the message string to attach a local file to the delivery.
File paths must not contain whitespace. The
MEDIA: directive is stripped from the displayed message text before delivery.Listing Targets
action="list" returns a JSON array of all reachable targets so the agent can pick the right one before sending.
| Field | Type | Description |
|---|---|---|
target | str | Token to pass as the target argument to send_message |
platform | str | Platform name (e.g. "telegram", "slack") |
kind | str | One of "origin", "home", or "alias" |
label | str | Friendly name for display |
When It’s Available
| Runtime | Behaviour |
|---|---|
| Bot / Gateway (Telegram, Slack, Discord, WhatsApp, …) | Delivers the message; returns a short summary string |
CLI / one-shot (agent.start(...) directly) | Returns the string below — does not raise |
User Interaction Flow
A user starts a long research task on Telegram, then closes their phone. The agent finishes compiling the report, callssend_message("origin", "Your report is ready MEDIA:/tmp/report.pdf"), and the user receives a Telegram push notification with the PDF attached — without ever having to ask “are you done yet?”.
Configuration Reference
send_message takes three arguments. All are optional:
| Argument | Type | Default | Description |
|---|---|---|---|
target | str | "origin" | Symbolic destination (see Targets table) |
message | str | "" | Text to send; append " MEDIA:<path>" to attach files |
action | str | "send" | "send" to deliver, "list" to enumerate reachable targets |
action="send" vs action="list" at a glance:
action | Returns |
|---|---|
"send" | Short summary string, e.g. "Delivered to slack:#ops" |
"list" | JSON array of {target, platform, kind, label} objects |
Common Patterns
Notify on long-task completion
Cross-channel handoff
Pick the target from the list, then send
Best Practices
Confirm channel before sending to an explicit target
Confirm channel before sending to an explicit target
Call
send_message(action="list") first when the user hasn’t specified where they want to be notified. Sending to a channel the user doesn’t monitor is noise.Default to 'origin'
Default to 'origin'
"origin" sends to the chat the conversation started in — usually the right choice. Only override it when you have a specific reason (e.g., sending an ops alert to a dedicated Slack channel).Handle the no-gateway fallback in agent instructions
Handle the no-gateway fallback in agent instructions
Include a note like “If send_message returns a ‘No active gateway’ message, skip the notification and continue.” so the agent doesn’t retry endlessly on CLI runs.
Keep messages short — they hit a phone
Keep messages short — they hit a phone
Mobile push notifications truncate long text. Send a one-line summary; attach details as a file with
MEDIA:.Related
Clarify Tool
Ask the user mid-task for clarifying input
Channels Gateway
Connect agents to Telegram, Slack, Discord, and WhatsApp
Bot Gateway
Run the gateway server
Bot Routing
Route messages by channel and platform

