Overview
Channels receive messages from external sources (CLI, HTTP, WebSockets, etc.) and convert them to a unified message format for the agent to process. The channel system supports:- Multiple concurrent input channels
- Unified message abstraction
- Streaming message delivery
- Channel-specific metadata
- WASM-based dynamic channel loading
Architecture
Core Types
Channel Trait
The main trait that all channels must implement.Methods
fn(&self) -> &str
Return the channel name (must be unique)
fn(&self) -> MessageStream
Get a stream of incoming messages from this channel
async fn(&self, response: OutgoingResponse) -> Result<()>
Send a response back through this channel
async fn(&self, status: StatusUpdate) -> Result<()>
Send a status update (typing indicator, progress, etc.)
IncomingMessage
A message received from an external channel.Uuid
Unique message identifier
String
Channel this message came from
String
User identifier within the channel
Option<String>
Optional display name for the user
String
Message content/text
Option<String>
Thread/conversation ID for threaded conversations
DateTime<Utc>
When the message was received
serde_json::Value
Channel-specific metadata
Constructors
fn(channel: impl Into<String>, user_id: impl Into<String>, content: impl Into<String>) -> Self
Create a new incoming message
fn(self, thread_id: impl Into<String>) -> Self
Set the thread ID
fn(self, metadata: serde_json::Value) -> Self
Set channel-specific metadata
fn(self, name: impl Into<String>) -> Self
Set the user’s display name
Example
OutgoingResponse
A response to send back through a channel.String
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
Constructors
fn(content: impl Into<String>) -> Self
Create a simple text response
fn(self, thread_id: impl Into<String>) -> Self
Set the thread ID for the response
fn(self, attachments: Vec<String>) -> Self
Add file attachments
fn(self, metadata: serde_json::Value) -> Self
Set channel-specific metadata
Example
StatusUpdate
Status updates sent during processing (typing indicators, progress, etc.).StatusKind
Type of status update
Option<String>
Optional status message
Option<f32>
Optional progress (0.0 to 1.0)
StatusKind
()
Agent is typing/thinking
()
Agent is processing the request
String
Agent is executing a tool (includes tool name)
()
Processing is complete
Example
MessageStream
A stream of incoming messages from a channel.Built-in Channels
ReplChannel
Interactive command-line REPL channel.fn() -> Self
Create a new REPL channel with stdin/stdout
fn(prompt: impl Into<String>) -> Self
Set a custom prompt string
HttpChannel
HTTP webhook receiver channel.fn(addr: impl Into<SocketAddr>) -> Self
Create a new HTTP channel listening on the given address
fn(self, token: impl Into<String>) -> Self
Add bearer token authentication
HTTP Endpoint
The HTTP channel exposes a POST endpoint:SignalChannel
Unix signal handler channel (SIGUSR1, SIGUSR2, etc.).fn(signals: Vec<Signal>) -> Self
Create a signal channel that listens for the specified Unix signals
GatewayChannel
WebSocket gateway for real-time bidirectional communication.fn(addr: impl Into<SocketAddr>) -> Self
Create a WebSocket gateway listening on the given address
fn(self, auth_fn: AuthFn) -> Self
Add custom authentication function
Channel Manager
ChannelManager
Manages multiple channels and multiplexes their message streams.fn() -> Self
Create a new channel manager
fn(&mut self, channel: Arc<dyn Channel>)
Register a channel with the manager
fn(&self) -> MessageStream
Get a unified stream of messages from all registered channels
async fn(&self, channel_name: &str, response: OutgoingResponse) -> Result<()>
Send a response to a specific channel
Example
WASM Channels
Dynamically load channel implementations at runtime using WebAssembly.WasmChannel
A channel implementation loaded from a WASM module.async fn(wasm_bytes: &[u8]) -> Result<Self>
Load a WASM module as a channel
async fn(path: &Path) -> Result<Self>
Load a WASM channel from a file
WASM Channel Interface
WASM channels must implement the following interface:wasm module documentation for full details on the WASM channel ABI.
Error Handling
ChannelError
Errors that can occur during channel operations.String
Failed to establish connection
String
Failed to send message/response
String
Received malformed message
String
Authentication/authorization failed
String
Channel or resource not found
WebSocket Gateway
TheGatewayChannel provides a production-ready WebSocket server for real-time communication.
Client Connection
Status Updates
The gateway sends real-time status updates:Best Practices
- Channel isolation: Each channel should handle its own protocol/transport details
- Unified messages: Convert channel-specific formats to
IncomingMessageearly - Metadata: Use the metadata field for channel-specific context (message IDs, etc.)
- Error handling: Channels should gracefully handle disconnections and reconnect
- Authentication: Validate users before accepting messages
- Rate limiting: Consider rate limiting per user/channel to prevent abuse
Related Modules
Agent Module
Agent orchestration and message processing
Tools Module
Tools that agents can use to respond to messages