CLI Channel
The CLI channel provides a simple, always-available interface for local development and testing through stdin/stdout communication.Overview
- Channel Name:
cli - Transport: Local stdin/stdout
- Authentication: None (local only)
- Dependencies: Zero external dependencies
- Public Port Required: No
Configuration
Basic Setup
true in your config.
Complete Example
Features
Automatic Message Handling
- Reads input from stdin line by line
- Writes responses to stdout
- Filters empty lines automatically
- Generates unique message IDs using UUID v4
Exit Commands
The CLI channel supports graceful exit through commands:Message Format
Each incoming message is converted to aChannelMessage with:
- ID: Unique UUID v4 identifier
- Sender:
"user" - Reply Target:
"user" - Content: The input line (trimmed)
- Channel:
"cli" - Timestamp: Current Unix timestamp in seconds
- Thread: None
Usage
Starting the CLI Channel
Interactive Mode
The CLI channel is ideal for:- Local development and testing
- Debugging agent behavior
- Scripting and automation via pipes
- Quick one-off queries
Piped Input
Redirect Output
Implementation Details
Source Location
src/channels/cli.rs
Key Components
CliChannel Struct
Channel Trait Implementation
name(): Returns"cli"send(): Writes message content to stdout viaprintln!listen(): Reads from stdin usingtokio::io::AsyncBufReadExt
Message Processing Flow
- Input: Async buffered stdin reader
- Filtering: Skip empty lines and exit commands
- Conversion: Create
ChannelMessagewith metadata - Delivery: Send to agent via channel sender
Exit Behavior
When a user sends/quit or /exit:
- The listen loop breaks cleanly
- No error is returned (normal termination)
- The channel shuts down gracefully
Error Handling
Send Errors
Sending to stdout never fails - thesend() method always returns Ok(()).
Listen Errors
- EOF: Returns
Ok(())when stdin closes - Channel Closed: Breaks loop when message receiver is dropped
- Line Read Error: Propagates as
anyhow::Resulterror
Testing
The CLI channel includes comprehensive tests:Best Practices
- Use for Development: Perfect for testing agent behavior locally
- Combine with Other Channels: Run CLI alongside remote channels
- Redirect as Needed: Use shell redirects for logging
- Exit Cleanly: Use
/quitor/exitfor graceful shutdown
Troubleshooting
No Response
- Check Configuration: Ensure
cli = trueis set - Check Agent Status: Verify the agent is running
- Check Provider: Ensure a provider is configured
Input Not Processing
- Empty Lines: Empty lines are automatically filtered
- Whitespace: Input is trimmed automatically
- EOF: Closing stdin (Ctrl+D) terminates the channel
Comparison with Other Channels
| Feature | CLI | Telegram | Discord | |
|---|---|---|---|---|
| Local Only | Yes | No | No | No |
| Authentication | None | Token | Token | Credentials |
| Public Port | No | No | No | No |
| Setup Complexity | Minimal | Medium | Medium | High |
| Best For | Testing | Production | Production | Async |