Rust SDK
The Rust SDK wraps the Autohand CLI in JSON-RPC mode and exposes async, typed APIs for prompts, event streams, permissions, and structured output.
Repository: autohandai/code-agent-sdk-rust. This SDK is in beta while the Agent SDK APIs stabilize. Pin commits or package versions in production.
Requirements
- Rust 1.80 or newer.
- Tokio runtime.
- Autohand CLI installed, authenticated, and configured.
Install
Cargo.toml
[dependencies]
autohand-sdk = { git = "https://github.com/autohandai/code-agent-sdk-rust" }
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }Run your first agent
Start with the high-level agent API when you want the SDK to own the run lifecycle and final result collection.
main.rs
use autohand_sdk::{Agent, Config, Result};
#[tokio::main]
async fn main() -> Result<()> {
let mut agent = Agent::create(
Config::from_env()
.with_cwd(".")
.with_instructions("Review code with senior Rust judgement."),
)
.await?;
let result = agent
.run("List the main source files and tell me what looks risky.")
.await?;
println!("{}", result.text);
agent.close().await?;
Ok(())
}API shape
- High-level `Agent` and `Run` APIs for application workflows.
- Low-level `AutohandSdk` for direct JSON-RPC control.
- Typed `SdkEvent` helpers for message deltas, tool events, permissions, and errors.
- Structured JSON helpers through `run_json` and `JsonRunOptions`.
Low-level control
Use `AutohandSdk` when your host needs direct access to plan mode, model switching, permission responses, or raw JSON-RPC calls.
Rust
use autohand_sdk::{AutohandSdk, Config, PromptOptions, Result};
#[tokio::main]
async fn main() -> Result<()> {
let mut sdk = AutohandSdk::new(Config::from_env().with_cwd("."));
sdk.start().await?;
sdk.set_plan_mode(true).await?;
let mut events = sdk
.stream_prompt("Create a discovery plan for this SDK change.", PromptOptions::default())
.await?;
while let Some(event) = events.recv().await {
println!("{:?}", event?);
}
sdk.stop().await?;
Ok(())
}Next steps
- Use Quickstart for the cross-language setup flow.
- Open Rust API for the reference surface.
- Read Stream responses in real-time and Handle approvals and user input for shared runtime behavior.