| Crates.io | tinyagent_macros |
| lib.rs | tinyagent_macros |
| version | 0.1.0 |
| created_at | 2025-10-20 18:29:24.715773+00 |
| updated_at | 2025-10-20 18:29:24.715773+00 |
| description | Procedural macros for tiny-agent-rs tool development |
| homepage | https://github.com/tunahorse/tinyagent-rust |
| repository | https://github.com/tunahorse/tinyagent-rust |
| max_upload_size | |
| id | 1892504 |
| size | 20,355 |
A lightweight, type-safe Rust agent library for LLM tool calling with strong typing and deterministic error handling.
cargo install tiny-agent-rs --features cli
use tiny_agent_rs::{Agent, FunctionFactory, tools::{CalculatorTool, WeatherTool}};
use async_openai::Client;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create OpenAI client
let client = Client::new();
// Set up function factory with tools
let mut function_factory = FunctionFactory::new();
function_factory.register_tool(CalculatorTool::new());
function_factory.register_tool(WeatherTool::new());
// Create agent
let agent = Agent::new(client, function_factory);
// Run agent
let response = agent.run("What is 15 + 27?").await?;
println!("{}", response);
Ok(())
}
# Set your OpenAI API key
export OPENAI_API_KEY="your-api-key-here"
# Run the agent
tiny-agent "What is the weather in Tokyo and 25 * 4?"
# Use different model
tiny-agent --model gpt-4 "Calculate 2^10"
# Custom timeout and iterations
tiny-agent --timeout 120 --max-iterations 20 "Complex query"
use tiny_agent_rs::Tool;
use async_trait::async_trait;
use serde::{Deserialize, Serialize};
use schemars::JsonSchema;
#[derive(Serialize, Deserialize, JsonSchema)]
pub struct MyToolParams {
pub input: String,
}
pub struct MyTool;
#[async_trait]
impl Tool for MyTool {
fn name(&self) -> &'static str {
"my_tool"
}
fn description(&self) -> &'static str {
"A custom tool example"
}
fn parameters_schema(&self) -> serde_json::Value {
schemars::schema_for!(MyToolParams).into()
}
async fn execute(&self, parameters: serde_json::Value) -> Result<serde_json::Value, AgentError> {
let params: MyToolParams = serde_json::from_value(parameters)?;
// Your tool logic here
let result = format!("Processed: {}", params.input);
Ok(serde_json::json!({ "result": result }))
}
}
See the examples/ directory for more complete examples:
# Clone the repository
git clone https://github.com/tunahorse/tinyagent-rust.git
cd tinyagent-rust
# Run tests
cargo test
# Run example
cargo run --example simple_agent --features cli
# Build with CLI
cargo build --features cli
githooks/: git config core.hooksPath githooks.PATH; the pre-commit hook fails fast if it cannot run gitleaks protect --staged --redact.gitleaks → cargo fmt --all -- --check → cargo clippy --all-targets --all-features -D warnings → cargo test.gitleaks detect --redact --source . before opening pull requests to scan the full tree.MIT License - see LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.