AAnvio
Channels

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

  1. 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.
  2. Thread → session mapping — an external thread (Telegram topic, Discord thread, Slack thread_ts, web conversation) maps 1:1 to an agent session.
  3. Detached execution — agents keep running when a user disconnects; completion is delivered later via the same or a different channel adapter.
  4. Adapter-only extension — a new channel implements the ChannelAdapter interface; no changes to packages/agents/ are required.

Channel Hub routing

Rendering diagram…

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" --detach

The 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

TypeTrigger
task_completedAgent run finished
task_failedAgent run error
approval_requiredTool needs human approval
agent_waitingAgent blocked on input
workflow_finishedOrchestration complete

Channel health check

Verify credentials and connectivity for every configured channel without starting the worker:

anvio channels status
anvio channels status --json

probeAllChannels() (packages/channels/src/channel-health.ts) returns one of five states per channel:

StatusMeaning
healthyProbe succeeded — API reachable, token valid (or channel is a built-in that's always available: cli, web-chat, rest)
degradedPartially 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
disabledNot enabled in workspace/anvio.yaml
misconfiguredEnabled but missing required env vars/config
unreachableEnabled with credentials but the live API probe failed

Adding a new channel

  1. Create packages/channels/src/<channel>.ts implementing ChannelAdapter (or extending BaseChannelAdapter, which provides default sendProgress/sendNotification implementations built on sendMessage).
  2. Register it in createChannelHub() (packages/channels/src/create-channels.ts), gated on its config/env vars being present.
  3. Map inbound webhooks/polling to InboundMessage with a channelThreadId.
  4. No changes to packages/agents/ are required — this is the entire point of the transport-only design.
Edit on GitHub

Last updated on

On this page