Quick Start
Basic Bot (Platform Awareness On by Default)
- Which platform the message came from
- What chat type (DM, group, channel)
- Which channels it can reach
How It Works
Each incoming message triggers a per-turn context injection into the agent’s system prompt.| Step | What Happens |
|---|---|
| Origin detection | detect_chat_type(platform, chat_id) classifies the chat as "group", "direct", "channel", or "unknown" |
| Target listing | ChannelDirectory.describe_targets() lists home channels and named aliases |
| Prompt injection | A ## Session Context block is appended to the system prompt for this turn only |
| Agent responds | The agent uses the context to make decisions (e.g. reply here vs. post there) |
Prompt injection happens after the system prompt is cached. The per-turn
## Session Context block is never stored in the cache — this keeps the cache valid across turns while still giving the agent fresh context every time.Configuration Options
Origin
Describes where the incoming message came from. Populated automatically by the bot runtime.
| Option | Type | Default | Description |
|---|---|---|---|
platform | str | "" | Platform name ("telegram", "discord", "slack", "whatsapp", …) |
chat_type | str | "" | "group", "direct", "channel", or "unknown" |
display_name | str | "" | Channel name, group name, or user name |
thread_id | str | "" | Thread / topic id |
ReachableTarget
Represents a channel the agent can deliver to. Built from the ChannelDirectory.
| Option | Type | Default | Description |
|---|---|---|---|
name | str | — | Friendly name or alias |
platform | str | — | Target platform |
channel_id | str | — | Platform channel id |
kind | str | "alias" | "home" or "alias" |
BotSessionManager Parameters
| Option | Type | Default | Description |
|---|---|---|---|
channel_directory | Optional[ChannelDirectory] | None | Directory of reachable channels; if set, describe_targets() populates reachable_targets |
inject_session_context | bool | True | When False, suppress per-turn prompt injection (origin + targets are still passed to tools) |
Chat-Type Detection
detect_chat_type(platform, chat_id) returns a string classifying the chat context. Used to fill Origin.chat_type.
| Platform | Pattern | Returned Type |
|---|---|---|
telegram | chat_id starts with -100 | "unknown" (supergroup/channel ambiguous) |
telegram | chat_id starts with - | "group" |
telegram | otherwise | "direct" |
discord | any | "channel" |
slack | starts with C | "channel" |
slack | starts with G | "group" |
slack | starts with D or U | "direct" |
whatsapp | contains @g.us | "group" |
whatsapp | contains @c.us | "direct" |
| anything else | — | "unknown" |
Choosing Your Setup
Common Patterns
Cross-Platform Delivery via Natural Language
The agent can deliver to another platform when the user says “post this to Slack”:Referring to “Here”
The agent knows what “here” means becauseOrigin includes the current platform and chat type:
Disabling Injection for Privacy
Keep context away from the agent’s visible system prompt (it still flows to tools viaget_session_context()):
Best Practices
Per-turn data is never cached
Per-turn data is never cached
The
## Session Context block is injected after the system prompt cache boundary. Changing the origin or reachable targets never invalidates the cache for previous turns — each turn gets a fresh block without paying a re-cache penalty.Use friendly alias names the model can guess
Use friendly alias names the model can guess
Prefer short, descriptive names like
"team", "ops", or "alerts" over raw channel IDs like "C0123456". The model matches user intent to alias names — the closer the alias is to how users talk, the more reliably it routes.Disable injection for privacy-sensitive deployments
Disable injection for privacy-sensitive deployments
Set
inject_session_context=False when you don’t want the agent to see platform metadata in its system prompt. The context is still available to tools via get_session_context() — only the visible prompt block is suppressed.Set home channels before adding aliases
Set home channels before adding aliases
set_home_channel(platform, channel_id) designates the default delivery target for a platform. Agents can refer to it as "<platform>:home". Add aliases for any additional channels that need friendly names.Related
Cross-Platform Sessions
Unified conversation history across platforms — same human, one history.
Channels Gateway
Connect agents to Telegram, Discord, Slack, and WhatsApp.
Bot Message Routing
Route messages from DMs, groups, and channels to different agents.
Messaging Bots
Deploy AI agents to messaging platforms.

