Skip to main content

Crate machi

Crate machi 

Source
Expand description

Machi - A Rust implementation of smolagents

This crate provides a lightweight, ergonomic framework for building AI agents that can use tools and interact with language models.

§Quick Start

use machi::prelude::*;

#[tool(description = "Add two numbers")]
async fn add(a: i32, b: i32) -> Result<i32, ToolError> {
    Ok(a + b)
}

#[tokio::main]
async fn main() {
    // Use OpenAI (requires OPENAI_API_KEY env var)
    let model = OpenAIClient::from_env().completion_model("gpt-4o");

    // Or use Ollama (local, no API key needed)
    // let model = OllamaClient::new().completion_model("qwen3");

    let mut agent = Agent::builder()
        .model(model)
        .tool(Box::new(Add))
        .build();

    let result = agent.run("What is 2 + 3?").await;
}

Re-exports§

pub use error::AgentError;
pub use error::Result;

Modules§

agent
AI Agent for executing tasks with tools.
callback
Advanced callback system for agent events.
error
Error types for the machi framework.
managed
Managed agent system for multi-agent collaboration.
mcp
MCP (Model Context Protocol) client integration.
memory
Memory system for tracking agent steps and state.
message
Message types for agent-model communication.
multimodal
Agent types for multimodal data (images, audio).
prelude
Prelude module for convenient imports.
prompts
Prompt template system for AI agents.
providers
LLM Provider implementations for various model APIs.
tool
Tool trait and utilities for defining agent tools.
tools
Built-in tools for agents.

Attribute Macros§

tool
A procedural macro that transforms a function into a machi::tool::Tool implementation.