Platform-Aware Agents

Gateway agents automatically know which platform they're on and which channels they can reach.

Gateway agents automatically know where a message came from and which channels they can deliver to — no extra code required.

python
from praisonai.bots import Bot
from praisonaiagents import Agent

agent = Agent(
    name="gateway",
    instructions="Help users across platforms.",
)

bot = Bot("telegram", agent=agent)
bot.run()

The user messages on Telegram; the gateway agent replies with platform-aware routing.

Diagram

📨 Incoming Message

🌐 Detect Origin

📡 List Targets

🧠 Session Context

🤖 Agent Response

Quick Start

  1. Simple Usage
    python
    from praisonai.bots import Bot
    from praisonaiagents import Agent
    
    agent = Agent(
        name="gateway",
        instructions="Help users across platforms.",
    )
    
    # Token from TELEGRAM_BOT_TOKEN env var
    bot = Bot("telegram", agent=agent)
    bot.run()

    The agent’s system prompt automatically includes the source platform, chat type, and reachable delivery targets.

  2. With Configuration

    Add a channel directory for cross-platform delivery:

    python
    from praisonai.bots import Bot
    from praisonai.bots.delivery import ChannelDirectory
    from praisonaiagents import Agent
    
    agent = Agent(
        name="gateway",
        instructions="Help users and post summaries to Slack when asked.",
    )
    
    directory = ChannelDirectory()
    directory.set_home_channel("slack", "C0123456")
    directory.add_alias("team", "slack", "C0123456")
    directory.add_alias("ops", "discord", "987654321")
    
    bot = Bot("telegram", agent=agent, channel_directory=directory)
    bot.run()

How It Works

Diagram
SlackAgentGateway BotUserSlackAgentGateway BotUser“Replying on telegram (group)”“Targets: team (slack), ops (discord)”“post this summary to Slack”detect_chat_type() + describe_targets()chat() + Session Contextdeliver(target=”team”)posted
StepWhat Happens
Origin detectiondetect_chat_type(platform, chat_id) classifies as group, direct, channel, or unknown
Target listingChannelDirectory.describe_targets() lists home channels and aliases
Prompt injectionA ## Session Context block is appended per turn
Agent respondsThe agent uses context to reply here or deliver elsewhere

Configuration Options

BotSessionManager

OptionTypeDefaultDescription
channel_directoryChannelDirectoryNoneNamed aliases and home channels for delivery
inject_session_contextboolTrueWhen False, suppress per-turn prompt injection

BotConfig media

OptionTypeDefaultDescription
max_inbound_media_bytesint20971520Max inbound media size; set 0 to disable

Chat-type detection

PlatformPatternType
telegramstarts with -100"unknown"
telegramstarts with -"group"
telegramotherwise"direct"
slackstarts with C / G / Dchannel / group / direct
whatsappcontains @g.us / @c.usgroup / direct

Common Patterns

Cross-platform delivery

python
directory = ChannelDirectory()
directory.set_home_channel("slack", "C0123456")
directory.add_alias("team", "slack", "C0123456")

agent = Agent(
    name="cross-platform",
    instructions="When asked to post somewhere, use delivery targets from Session Context.",
)
bot = Bot("telegram", agent=agent, channel_directory=directory)

Disable injection for privacy

python
bot = Bot("telegram", agent=agent, inject_session_context=False)

Context still flows to tools via get_session_context() — only the visible prompt block is suppressed.


Best Practices

Per-turn data is never cached

The ## Session Context block is injected after the cache boundary — each turn gets fresh context without invalidating prior cache entries.

Use friendly alias names

Prefer "team" or "ops" over raw channel IDs — the model matches user intent to alias names.

Set home channels before aliases

set_home_channel(platform, channel_id) designates the default delivery target; agents refer to it as "<platform>:home".

Disable injection for privacy-sensitive deployments

Set inject_session_context=False when platform metadata should not appear in the system prompt.


Related