Autohand Code Agent SDK for Rust
May 8, 2026 ยท View on GitHub
Rust SDK for building applications that control Autohand code agents through the Autohand CLI JSON-RPC mode.
Documentation: https://autohand.ai/docs/agent-sdk/
Beta: this SDK is actively evolving while the Agent SDK APIs stabilize. Pin versions in production and review release notes before upgrading.
What It Does
The Rust SDK wraps the existing Autohand CLI process and gives Rust applications an async, typed API for agent runs:
Rust app -> autohand-sdk -> Autohand CLI subprocess -> provider -> model
Use it when you want to embed Autohand inside a Rust service, developer tool, CLI, desktop app, or test harness while keeping the same CLI behavior users already trust.
Features
- Tokio-based subprocess transport over JSON-RPC 2.0
AgentandRunfor high-level application workflowsAutohandSdkfor direct low-level RPC access- Typed streaming events for messages, tools, permissions, and errors
- Permission response helpers for host-controlled approval flows
- Structured JSON helpers for typed agent output
- Example parity with the TypeScript SDK examples
Requirements
- Rust 1.80 or later
- Tokio runtime
- Autohand CLI installed and authenticated
- A configured provider in
~/.autohand/config.json, or environment variables accepted by the CLI
Set AUTOHAND_CLI_PATH when you want to force a local CLI binary:
export AUTOHAND_CLI_PATH=/path/to/autohand
Installation
Until the crate is published, use the GitHub repo directly:
[dependencies]
autohand-sdk = { git = "https://github.com/autohandai/code-agent-sdk-rust" }
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
The crate name is planned as autohand-sdk.
Quick Start
use autohand_sdk::{Agent, Config, Result, SdkEvent};
#[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 mut run = agent.send("Review this repository for release readiness.").await?;
while let Some(event) = run.next().await {
match event? {
SdkEvent { event_type, raw } if event_type == "message_update" => {
if let Some(delta) = raw.get("delta").and_then(|value| value.as_str()) {
print!("{delta}");
}
}
SdkEvent { event_type, raw } if event_type == "permission_request" => {
eprintln!("permission requested: {raw}");
}
_ => {}
}
}
let result = run.wait().await?;
println!("\nRun {} finished with {}", result.id, result.status);
agent.close().await?;
Ok(())
}
Low-Level Control
Use AutohandSdk when your host needs direct access to the JSON-RPC control surface:
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(())
}
Examples
The examples/ directory mirrors the TypeScript SDK example inventory:
01-hello-agent.rs02-streaming-query.rs03-code-reviewer.rs04-bash-command.rs05-file-editor.rs06-prompt-skills.rs07-direct-skills.rs08-memory-management.rs10-multi-tool-reasoning.rs13-permissions.rs20-sdlc-discovery-plan.rs21-sdlc-gated-implementation.rs22-sdlc-release-readiness.rs23-system-prompts.rs24-high-level-agent.rs25-structured-json.rsbasic-agent.rsbasic-usage.rsloop-strategies.rspermission-handling.rssdk-control-features.rsstreaming.rs
Run an example with:
cargo run --example 01-hello-agent
Live examples require an authenticated Autohand CLI and may ask for tool permissions depending on your CLI configuration.
Documentation
- Getting Started
- API Reference
- Configuration
- Event Streaming
- Permissions
- Plan Mode
- SDLC Workflows
- Error Handling
- Examples
- Contributing
- Security
Development
cargo fmt --check
cargo test
cargo check --examples
The transport tests use a deterministic fake CLI, so the unit suite does not require model credentials.
Other SDKs
Support
- SDK docs: https://autohand.ai/docs/agent-sdk/
- Issues: https://github.com/autohandai/code-agent-sdk-rust/issues
- Security reports: security@autohand.ai