Core Concepts
Rig is built from a small set of composable abstractions. Once you understand how they layer, everything else in the framework is a variation on the same pattern. This section explains each piece and links to a dedicated page.
The mental model
Section titled “The mental model”The building blocks stack from the bottom up:
- Provider clients wrap an LLM vendor (OpenAI, Anthropic, Gemini, Ollama, and more). A client knows how to authenticate and which capabilities the provider supports.
- Models are created from a client: a
CompletionModelfor text generation, anEmbeddingModelfor vector representations, plus transcription, image, and audio models where a provider supports them. - Agents wrap a completion model with a preamble, tools, and context. An agent is the highest-level, most convenient way to prompt a model, and it runs the tool-calling loop for you.
- Tools, RAG, and memory extend an agent: tools let it call your code, RAG injects relevant documents from a vector store, and memory loads and saves conversation history per conversation — automatically via a memory backend, or by hand when you want full control.
- Workflows compose all of the above into multi-step programs — sequential, parallel, or conditional — using plain Rust.
How the pieces fit
Section titled “How the pieces fit”flowchart TD Client["Provider / Client"] --> Model["Model"] Model --> Agent["Agent"] Tools["Tools"] -.-> Agent RAG["RAG<br/>(Embeddings + Vector Store)"] -.-> Agent Memory["Memory"] -.-> Agent Agent --> Output["Structured Output"]The Client authenticates a vendor and creates a Model. An Agent wraps that model and draws on Tools (your code), RAG (documents retrieved from a vector store), and Memory (conversation history) to answer a prompt — as free text or as Structured Output.
Which abstraction do I need?
Section titled “Which abstraction do I need?”Start from the task, not the type. Each row links to the page that covers it.
| I want to… | Reach for… | Page |
|---|---|---|
| prompt a model once | Completions | Completions |
| let the model plan multi-step work | Agents (the agent loop) | Agents |
| hold a conversation | Conversation memory | Memory |
| let the model call my code | Tools | Tools |
| get typed data out of text | Structured Output | Structured Output |
| answer from my documents | RAG + Vector Stores | Vector Stores & RAG |
| stream tokens as they arrive | Streaming | Streaming |
| orchestrate known steps in code | Workflows | Workflows |
| coordinate several agents | Multi-agent systems | Multi-agent systems |
| test without a live model | Mock models | Testing |
A minimal end-to-end example touches the first three layers:
use rig::client::{CompletionClient, ProviderClient};use rig::completion::Prompt;use rig::providers::openai;
#[tokio::main]async fn main() -> Result<(), anyhow::Error> { // provider client -> agent (wraps a completion model) let agent = openai::Client::from_env()? .agent("gpt-5.5") .preamble("You are a helpful assistant.") .build();
let answer = agent.prompt("What is Rig?").await?; println!("{answer}"); Ok(())}Explore each concept
Section titled “Explore each concept”Next steps
Section titled “Next steps”- New to Rig? Start with the Quickstart to build your first agent.
- Want the big picture? See the Architecture overview.
- Ready to build something? Head to the Guides.
