Overview
Channel Hub architecture — every communication surface is a transport-only adapter, and the Agent Runtime never imports channel code.
4 min read
Anvio treats every communication surface — CLI, REST, web chat, Telegram, Discord, Slack, WhatsApp, and ten more — as a transport layer only. The Agent Runtime never imports channel-specific code; it emits events, and the ChannelHub routes them to whichever adapters are registered.
Design principles
- Channel independence — every channel shares identical runtime behavior. An agent's tool loop, memory, and approval flow are the same whether the message came from Telegram or the REST API.
- Thread → session mapping — an external thread (Telegram topic, Discord thread, Slack
thread_ts, web conversation) maps 1:1 to an agent session. - Detached execution — agents keep running when a user disconnects; completion is delivered later via the same or a different channel adapter.
- Adapter-only extension — a new channel implements the
ChannelAdapterinterface; no changes topackages/agents/are required.
Channel Hub routing
Inbound flow: ChannelAdapter → EventBus (AGENT_RUN_REQUESTED) → Worker → AgentRuntime.
Outbound flow: AgentRuntime / Worker → events → ChannelHub → adapter.sendMessage / sendProgress / sendApprovalRequest.
ChannelHub
ChannelHub (packages/channels/src/channel-hub.ts) is a thin registry, not a message broker:
export class ChannelHub implements ChannelHubPort {
private readonly adapters = new Map<ChannelType, ChannelAdapter>();
register(adapter: ChannelAdapter): void {
this.adapters.set(adapter.channelType, adapter);
}
async sendMessage(channel: ChannelType, sessionId: string, message: OutboundMessage): Promise<void> {
const adapter = this.adapters.get(channel);
if (!adapter) return;
await adapter.sendMessage(sessionId, message);
}
// sendProgress, sendNotification, sendApprovalRequest follow the same pattern
// startAll() / stopAll() start or stop every registered adapter
}createChannelHub() (packages/channels/src/create-channels.ts) is the actual composition function — it reads ChannelConfig, registers the always-on adapters (WebChatChannel, CliChannel, RestApiChannel), and conditionally registers each optional adapter only if its required credentials are present (bot token, webhook URL, etc.).
Thread-based sessions
Sessions store a channelThread field so an external conversation reliably maps back to the same Anvio session:
{
"channelThread": {
"channel": "discord",
"threadId": "1234567890"
}
}Resume via SessionStore.getByChannelThread(channel, threadId). A session payload also includes context (messages), progress (status), state, attachments (artifacts), and approvals (pendingApproval).
Detached execution and progress
Set detached: true on session creation or on the AGENT_RUN_REQUESTED event to let the worker run independently of the client connection:
anvio run architect "Review this repository" --detachThe runtime emits AGENT_RUN_PROGRESS events during context assembly, model calls, and memory storage; every adapter renders these as formatted updates (🔄 Analyzing repository, ✅ Completed).
Notifications
| Type | Trigger |
|---|---|
task_completed | Agent run finished |
task_failed | Agent run error |
approval_required | Tool needs human approval |
agent_waiting | Agent blocked on input |
workflow_finished | Orchestration complete |
Channel health check
Verify credentials and connectivity for every configured channel without starting the worker:
anvio channels status
anvio channels status --jsonprobeAllChannels() (packages/channels/src/channel-health.ts) returns one of five states per channel:
| Status | Meaning |
|---|---|
healthy | Probe succeeded — API reachable, token valid (or channel is a built-in that's always available: cli, web-chat, rest) |
degraded | Partially ready — for example WhatsApp API reachable but the webhook needs the API process running, or Teams/Matrix credentials set but missing a serviceUrl/roomId for live delivery |
disabled | Not enabled in workspace/anvio.yaml |
misconfigured | Enabled but missing required env vars/config |
unreachable | Enabled with credentials but the live API probe failed |
Adding a new channel
- Create
packages/channels/src/<channel>.tsimplementingChannelAdapter(or extendingBaseChannelAdapter, which provides defaultsendProgress/sendNotificationimplementations built onsendMessage). - Register it in
createChannelHub()(packages/channels/src/create-channels.ts), gated on its config/env vars being present. - Map inbound webhooks/polling to
InboundMessagewith achannelThreadId. - No changes to
packages/agents/are required — this is the entire point of the transport-only design.
Last updated on