Rust SDK
The Rust SDK wraps the Autohand Code CLI in JSON-RPC mode and exposes async, typed APIs for prompts, event streams, permissions, and structured output.
Requirements
- Rust 1.80 or newer.
- Tokio runtime.
- Autohand Code CLI installed, authenticated, and configured.
Install
[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.
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
AgentandRunAPIs for application workflows. - Low-level
AutohandSdkfor direct JSON-RPC control. - Typed
SdkEventhelpers for message deltas, tool events, permissions, and errors. - Structured JSON helpers through
run_jsonandJsonRunOptions.
Low-level control
Use AutohandSdk when your host needs direct access to plan mode, model switching, permission responses, or raw JSON-RPC calls.
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.