Skip to main content

Channel

Trait Channel 

Source
pub trait Channel: Send {
Show 17 methods // Required methods fn recv( &mut self, ) -> impl Future<Output = Result<Option<ChannelMessage>, ChannelError>> + Send; fn send( &mut self, text: &str, ) -> impl Future<Output = Result<(), ChannelError>> + Send; fn send_chunk( &mut self, chunk: &str, ) -> impl Future<Output = Result<(), ChannelError>> + Send; fn flush_chunks( &mut self, ) -> impl Future<Output = Result<(), ChannelError>> + Send; // Provided methods fn try_recv(&mut self) -> Option<ChannelMessage> { ... } fn supports_exit(&self) -> bool { ... } fn send_typing( &mut self, ) -> impl Future<Output = Result<(), ChannelError>> + Send { ... } fn send_status( &mut self, _text: &str, ) -> impl Future<Output = Result<(), ChannelError>> + Send { ... } fn send_thinking_chunk( &mut self, _chunk: &str, ) -> impl Future<Output = Result<(), ChannelError>> + Send { ... } fn send_queue_count( &mut self, _count: usize, ) -> impl Future<Output = Result<(), ChannelError>> + Send { ... } fn send_usage( &mut self, _input_tokens: u64, _output_tokens: u64, _context_window: u64, ) -> impl Future<Output = Result<(), ChannelError>> + Send { ... } fn send_diff( &mut self, _diff: DiffData, ) -> impl Future<Output = Result<(), ChannelError>> + Send { ... } fn send_tool_start( &mut self, _event: ToolStartEvent, ) -> impl Future<Output = Result<(), ChannelError>> + Send { ... } fn send_tool_output( &mut self, event: ToolOutputEvent, ) -> impl Future<Output = Result<(), ChannelError>> + Send { ... } fn confirm( &mut self, _prompt: &str, ) -> impl Future<Output = Result<bool, ChannelError>> + Send { ... } fn elicit( &mut self, _request: ElicitationRequest, ) -> impl Future<Output = Result<ElicitationResponse, ChannelError>> + Send { ... } fn send_stop_hint( &mut self, _hint: StopHint, ) -> impl Future<Output = Result<(), ChannelError>> + Send { ... }
}
Expand description

Bidirectional communication channel for the agent.

Required Methods§

Source

fn recv( &mut self, ) -> impl Future<Output = Result<Option<ChannelMessage>, ChannelError>> + Send

Receive the next message. Returns None on EOF or shutdown.

§Errors

Returns an error if the underlying I/O fails.

Source

fn send( &mut self, text: &str, ) -> impl Future<Output = Result<(), ChannelError>> + Send

Send a text response.

§Errors

Returns an error if the underlying I/O fails.

Source

fn send_chunk( &mut self, chunk: &str, ) -> impl Future<Output = Result<(), ChannelError>> + Send

Send a partial chunk of streaming response.

§Errors

Returns an error if the underlying I/O fails.

Source

fn flush_chunks( &mut self, ) -> impl Future<Output = Result<(), ChannelError>> + Send

Flush any buffered chunks.

§Errors

Returns an error if the underlying I/O fails.

Provided Methods§

Source

fn try_recv(&mut self) -> Option<ChannelMessage>

Non-blocking receive. Returns None if no message is immediately available.

Source

fn supports_exit(&self) -> bool

Whether /exit and /quit commands should terminate the agent loop.

Returns false for persistent server-side channels (e.g. Telegram) where breaking the loop would not meaningfully exit from the user’s perspective.

Source

fn send_typing( &mut self, ) -> impl Future<Output = Result<(), ChannelError>> + Send

Send a typing indicator. No-op by default.

§Errors

Returns an error if the underlying I/O fails.

Source

fn send_status( &mut self, _text: &str, ) -> impl Future<Output = Result<(), ChannelError>> + Send

Send a status label (shown as spinner text in TUI). No-op by default.

§Errors

Returns an error if the underlying I/O fails.

Source

fn send_thinking_chunk( &mut self, _chunk: &str, ) -> impl Future<Output = Result<(), ChannelError>> + Send

Send a thinking/reasoning token chunk. No-op by default.

§Errors

Returns an error if the underlying I/O fails.

Source

fn send_queue_count( &mut self, _count: usize, ) -> impl Future<Output = Result<(), ChannelError>> + Send

Notify channel of queued message count. No-op by default.

§Errors

Returns an error if the underlying I/O fails.

Source

fn send_usage( &mut self, _input_tokens: u64, _output_tokens: u64, _context_window: u64, ) -> impl Future<Output = Result<(), ChannelError>> + Send

Send token usage after an LLM call. No-op by default.

§Errors

Returns an error if the underlying I/O fails.

Source

fn send_diff( &mut self, _diff: DiffData, ) -> impl Future<Output = Result<(), ChannelError>> + Send

Send diff data for a tool result. No-op by default (TUI overrides).

§Errors

Returns an error if the underlying I/O fails.

Source

fn send_tool_start( &mut self, _event: ToolStartEvent, ) -> impl Future<Output = Result<(), ChannelError>> + Send

Announce that a tool call is starting.

Emitted before execution begins so the transport layer can send an InProgress status to the peer before the result arrives. No-op by default.

§Errors

Returns an error if the underlying I/O fails.

Source

fn send_tool_output( &mut self, event: ToolOutputEvent, ) -> impl Future<Output = Result<(), ChannelError>> + Send

Send a complete tool output with optional diff and filter stats atomically.

display is the formatted tool output. The default implementation forwards to Channel::send. Structured channels (e.g. LoopbackChannel) override this to emit a typed event so consumers can access tool_name and display as separate fields.

§Errors

Returns an error if the underlying I/O fails.

Source

fn confirm( &mut self, _prompt: &str, ) -> impl Future<Output = Result<bool, ChannelError>> + Send

Request user confirmation for a destructive action. Returns true if confirmed. Default: auto-confirm (for headless/test scenarios).

§Errors

Returns an error if the underlying I/O fails.

Source

fn elicit( &mut self, _request: ElicitationRequest, ) -> impl Future<Output = Result<ElicitationResponse, ChannelError>> + Send

Request structured input from the user for an MCP elicitation.

Always displays request.server_name to prevent phishing by malicious servers. Default: auto-decline (for headless/daemon/non-interactive scenarios).

§Errors

Returns an error if the underlying I/O fails.

Source

fn send_stop_hint( &mut self, _hint: StopHint, ) -> impl Future<Output = Result<(), ChannelError>> + Send

Signal the non-default stop reason to the consumer before flushing.

Called by the agent loop immediately before flush_chunks() when a truncation or turn-limit condition is detected. No-op by default.

§Errors

Returns an error if the underlying I/O fails.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§