hanzo-agent
Core agent framework for Hanzo AI, ported from the Python agent SDK.
Overview
hanzo-agent provides a flexible, type-safe agent framework for building AI applications with:
- Agents: Configured with instructions, tools, and model settings
- Tools: Functions that agents can call to perform actions
- Handoffs: Delegate to specialized sub-agents
- Runner: Execute the agent loop with tool execution and handoff support
- OpenAI-compatible API: Works with any OpenAI-compatible LLM endpoint
Features
- ✅ Async/await with tokio
- ✅ Type-safe tool system with JSON schema
- ✅ Handoff mechanism (TODO: full implementation)
- ✅ Usage tracking
- ✅ Error handling with Result types
- ✅ Builder pattern for easy configuration
- 🔜 Streaming support
- 🔜 Guardrails
- 🔜 Lifecycle hooks
Installation
Add to your Cargo.toml:
[]
= { = "path/to/hanzo-agent" }
= { = "1", = ["full"] }
Quick Start
use *;
async
Adding Tools
use *;
use json;
// Create a simple tool
let calculator = builder
.description
.schema
.handler
.build?;
// Add to agent
let agent = builder
.instructions
.tool
.build;
Architecture
The agent framework follows a simple execution loop:
- Build messages: Combine original input with any generated items
- Call LLM: Send messages to the model with available tools
- Process response:
- If tool calls: Execute tools and continue loop
- If text message: Return as final output
- If handoff: Switch to new agent (TODO)
- Repeat until max_turns or final output
Core Types
- Agent: The main configuration object (name, instructions, model, tools, handoffs)
- Tool: Trait for tools with name, description, JSON schema, and invoke method
- RunContext: Runtime context with user data and usage tracking
- RunResult: Contains input, generated items, responses, output, and usage
- RunConfig: Configuration for the run (max_turns, API settings)
Comparison with Python SDK
This Rust implementation mirrors the Python agent SDK core functionality:
| Feature | Python SDK | Rust SDK | Status |
|---|---|---|---|
| Agent struct | ✅ | ✅ | Complete |
| Tool trait | ✅ | ✅ | Complete |
| Runner loop | ✅ | ✅ | Complete |
| Result types | ✅ | ✅ | Complete |
| Context | ✅ | ✅ | Complete |
| Handoffs | ✅ | 🔜 | Partial |
| Streaming | ✅ | 🔜 | TODO |
| Guardrails | ✅ | 🔜 | TODO |
| Hooks | ✅ | 🔜 | TODO |
| Output types | ✅ | 🔜 | TODO |
Examples
See the Python SDK examples for inspiration:
/Users/z/work/hanzo/agent/examples/
Rust examples coming soon!
Environment Variables
OPENAI_API_BASE: API base URL (default: https://api.openai.com/v1)OPENAI_API_KEY: API key for authentication
Testing
Run tests:
Run with output:
Development
Building
Linting
Formatting
License
MIT OR Apache-2.0