AGENTSDK
A lean Rust SDK for building AI agents with OpenAI-compatible APIs. Type-safe tool definitions, streaming, and agentic loops out of the box.
Features
- Callback-driven agent loop — automatically handles multi-turn tool-calling conversations with lifecycle hooks
- Type-safe tools — derive tools from plain Rust functions with the
#[tool]macro - OpenAI-compatible — works with OpenAI, OpenRouter, and any compatible endpoint
- JSON Schema generation — automatic input/output schemas via
schemars
Installation
Quick Start
use ;
use async_trait;
// Define a tool from a plain function
/// Get the current weather for a location
;
async
Defining Tools
Use the #[tool] macro to turn any function into a callable tool:
use ;
/// Calculate the sum of two numbers
The macro automatically:
- Uses the function name as the tool name
- Extracts the description from doc comments
- Generates a JSON Schema from the parameters
- Supports both sync and async functions
Struct parameters
use ;
use JsonSchema;
use Deserialize;
/// Search for documents
Tool context
Access runtime context (model name, extensions) via ToolContext:
use ;
Configuration
Agent options
builder
.model
.temperature
.max_tokens
.max_iterations // limit agent loop iterations (default: 25)
.with_tool
.build?
OpenAI client
let config = ModelConfig ;
let client = new;
// OR from environment variables
let config = from_env?;
Contributing
See CONTRIBUTING.md.
License
MIT — see LICENSE.