Skip to content
Get Started

Introduction

Rig is a Rust library for building LLM-powered applications and agents. It gives you unified abstractions over model providers (OpenAI, Anthropic, Gemini, Cohere, and more), vector stores, tools, and RAG pipelines, so you can wire up an agent in a few lines and scale it to a production system without changing frameworks.

If you already know Rust, Rig lets you build AI systems in Rust — the high-level building blocks you’d expect (agents, tools, RAG, structured output), with Rust’s performance and type safety, and no context-switching.

  • Type-safe by construction — tool arguments and structured outputs are ordinary Rust types, so the compiler checks your schemas and extraction targets before you ever hit the network.
  • Rust around the model calls — the orchestration, retrieval, and concurrency that surround each request run at native speed, with no interpreter overhead.
  • One unified API — the same agent, completion, and embedding abstractions work across 20+ providers (OpenAI, Anthropic, Gemini, Cohere, and more); swap backends by changing a client, not a framework.
  • Deploy as a single binary — compile to one self-contained executable, or to WebAssembly for edge and browser targets. No runtime or dependency tree to ship.
  • Stay in your stack — if your codebase is already Rust, build AI features in the same language, toolchain, and type system you use everywhere else.

An agent is a model plus a system prompt (a “preamble”) and, optionally, tools and context. Here’s a complete program that creates one and prompts it:

use rig::client::{CompletionClient, ProviderClient};
use rig::completion::Prompt;
use rig::providers::openai;
#[tokio::main]
async fn main() -> Result<(), anyhow::Error> {
// Reads the OPENAI_API_KEY environment variable.
let client = openai::Client::from_env()?;
// Build an agent from a model and a system prompt.
let agent = client
.agent("gpt-5.5")
.preamble("You are a helpful assistant.")
.build();
// Send a prompt and await the response.
let answer = agent.prompt("Who are you?").await?;
println!("{answer}");
Ok(())
}

Most agent work is API-call orchestration, but the surrounding systems — data pipelines, retrieval, concurrency, deployment — benefit from a fast, reliable language. Rust gives Rig:

  • Performance: Rust’s efficiency keeps the work around your model calls — data pipelines, retrieval, and concurrent request handling — fast and cheap to run at scale.
  • Safety: Rust’s type system and ownership model help you handle unexpected LLM outputs, coerce types, and surface errors at compile time.
  • Concurrency: Zero-cost async and the Tokio runtime make it straightforward to fan out many concurrent model requests safely.
  • Portability: Rust compiles to small, self-contained binaries and, in many cases, to WebAssembly for edge and browser deployments.
  • Full support for LLM completion and embedding workflows.
  • Simple, powerful abstractions over providers and vector stores that let you swap backends with minimal code changes.
  • Agents with system prompts, tools, and dynamic context.
  • Native RAG support via embeddings and vector store indexes.
  • Structured extraction of typed data from unstructured text.
  • Multi-agent systems that coordinate specialized agents.
  • Production tooling: typed errors, token-usage accounting, tracing, and mock models for offline, deterministic testing.
  • A growing ecosystem of companion crates for vector stores and integrations.