iFlow CLI SDK for Rust
A powerful Rust SDK for interacting with iFlow using the Agent Communication Protocol (ACP). This SDK provides both simple query functions and full bidirectional client for complex interactions.
Features
- 🚀 Automatic Process Management - SDK automatically starts and manages iFlow process
- 🔌 Stdio Communication - Communicate with iFlow via stdio
- 🔌 WebSocket Communication - Communicate with iFlow via WebSocket for better performance and reliability
- 🔄 Bidirectional Communication - Real-time streaming messages and responses
- 🛠️ Tool Call Management - Fine-grained permission control for tool execution
- 📋 Task Planning - Receive and process structured task plans
- 🔍 Raw Data Access - Debug and inspect protocol-level messages
- ⚡ Async/Await Support - Modern async Rust with full type safety
TODO
- 🤖 Sub-agent Support - Track and manage multiple AI agents via
agent_id
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
Or install directly from the repository:
Quick Start
Simple Query
use query;
async
MCP Server Configuration
The SDK supports configuring MCP (Modular Command Protocol) servers for extended capabilities such as filesystem access, command execution, and more. You can configure MCP servers using the McpServer type:
use ;
async
Simple Query with Custom Configuration
use ;
async
Interactive Session
use ;
use StreamExt;
async
Streaming Responses
use query_stream;
use StreamExt;
async
Streaming Responses with Custom Configuration
use ;
use StreamExt;
async
Configuration
Client Options
use IFlowOptions;
let options = new
.with_timeout
.with_file_access
.with_auto_start_process;
WebSocket Communication
The SDK supports WebSocket communication with iFlow for better performance and reliability. To use WebSocket, specify the WebSocket configuration in the options:
use ;
// Simple configuration with default reconnect settings
let options = new
.with_websocket_config;
// Or use the default configuration
let options = new
.with_websocket_config;
// Or configure with custom reconnect settings
let options = new
.with_websocket_config;
// In auto-start mode, you can omit the URL entirely
let options = new
.with_websocket_config;
// Or configure auto-start mode with custom reconnect settings
let options = new
.with_websocket_config;
If you enable auto-start process with a WebSocket URL pointing to localhost, the SDK will automatically start the iFlow process if it's not already running. In auto-start mode, you can omit the URL entirely and let the SDK generate it automatically.
Message Types
The SDK handles various message types from iFlow:
Message::Assistant { content }- AI assistant responsesMessage::ToolCall { id, name, status }- Tool execution requestsMessage::Plan { entries }- Structured task plansMessage::TaskFinish { reason }- Task completion signalsMessage::Error { code, message }- Error notificationsMessage::User { content }- User message echoes
Examples
Run the examples:
# Simple query example
# Interactive client example
# Test response handling
# Explore API capabilities
# Logging example
Architecture
The SDK is organized into several modules:
client- Main IFlowClient implementation with stdio communicationtypes- Type definitions and message structuresprocess_manager- iFlow process lifecycle managementquery- Convenience functions for simple querieserror- Error types and handlinglogger- Message logging functionality
Requirements
- Rust 1.70+
- iFlow CLI installed with
--experimental-acpsupport (or use auto-start feature)
Development
Building
Testing
# Run specific test suites
# e2e tests
Running with logging
RUST_LOG=debug
License
MIT License - see LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.