Skip to main content

Overview

Channels receive messages from external sources (CLI, HTTP, Signal, etc.) and convert them to a unified message format for the agent to process.

Architecture

Channel Trait

All channels implement the Channel trait.
src/channels/channel.rs

name

Returns the channel identifier (e.g., “cli”, “slack”, “telegram”, “http”).

start

Starts listening for messages. Returns a stream of incoming messages. The channel should handle reconnection and error recovery internally.

respond

Sends a response back to the user in the context of the original message (same channel, same thread if applicable).

send_status

Sends a status update (thinking, tool execution, etc.). The metadata contains channel-specific routing info.

broadcast

Sends a proactive message without a prior incoming message. Used for alerts, heartbeat notifications, and other agent-initiated communication.

health_check

Checks if the channel is healthy and able to send/receive messages.

conversation_context

Extracts conversation context from message metadata for the system prompt. Returns key-value pairs like “sender”, “sender_uuid”, “group” that help the LLM understand who it’s talking to.

shutdown

Gracefully shuts down the channel.

IncomingMessage

A message received from an external channel.
src/channels/channel.rs
Uuid
required
Unique message ID
String
required
Channel this message came from
String
required
User identifier within the channel
Option<String>
Optional display name
String
required
Message content
Option<String>
Thread/conversation ID for threaded conversations
DateTime<Utc>
required
When the message was received
serde_json::Value
required
Channel-specific metadata

OutgoingResponse

Response to send back to a channel.
src/channels/channel.rs
String
required
The content to send
Option<String>
Optional thread ID to reply in
Vec<String>
Optional file paths to attach
serde_json::Value
Channel-specific metadata for the response

StatusUpdate

Status update types for showing agent activity.
src/channels/channel.rs

ChannelManager

Manages multiple input channels and merges their message streams.

Constructor

src/channels/manager.rs
Creates a new channel manager.

add

src/channels/manager.rs
Adds a channel to the manager.

hot_add

src/channels/manager.rs
Hot-adds a channel to a running agent. Starts the channel, registers it for respond/broadcast, and spawns a task to forward its messages.

start_all

src/channels/manager.rs
Starts all channels and returns a merged stream of messages.

respond

src/channels/manager.rs
Sends a response to a specific channel.

send_status

src/channels/manager.rs
Sends a status update to a specific channel.

broadcast

src/channels/manager.rs
Broadcasts a message to a specific user on a specific channel.

broadcast_all

src/channels/manager.rs
Broadcasts a message to all channels.

inject_sender

src/channels/manager.rs
Get a clone of the injection sender. Background tasks use this to push messages into the agent loop.

Example: Custom Channel