Rig

repository·main·Indexed 27 days ago

https://github.com/0xplaygrounds/rig

An opinionated Rust library for building scalable, modular, and ergonomic LLM-powered applications. Rig provides a unified interface for over 20 model providers (including OpenAI, Anthropic, and Gemini) and 10+ vector stores (such as MongoDB, LanceDB, and Qdrant). It supports agentic workflows, streaming, multi-turn prompting, and local model inference via rig-candle. The library includes a classic agent runtime in rig-agent and supports native targets as well as wasm32-unknown-unknown.

Tokens
28.5K
Snippets
74
Records
176
Agent score
92%

What's inside rig

  1. Understand Rig Runtime Choices

    main

    Rig is architected to separate provider/backend contracts from agent orchestration through two main components:

    • rig-core: Contains provider-neutral messages, completion models, portable tools, memory, and vector-store contracts, along with built-in provider mappings.
    • rig-agent: Contains the agent orchestration logic, including the builder, prompt/streaming traits, typed hooks, contextual tools, extraction, and the serializable AgentRun state machine. This is enabled by default.

    The root rig crate re-exports both, allowing most users to simply depend on rig.

  2. Install Rig-Bedrock and Rig-Core

    main

    To use AWS Bedrock as a model provider with Rig, add both rig-bedrock and rig-core to your Cargo.toml dependencies. You can use cargo add to fetch the latest versions automatically.

    [dependencies]
    rig-bedrock = "0.4.5"
    rig-core = "0.36.0"

    Or via CLI

    cargo add rig-bedrock rig-core
  3. Install Rig-SQLite

    main

    To use the Rig-SQLite vector store, add rig-sqlite and rig-core to your Cargo.toml. You will also need serde (with derive features) and serde_json to handle metadata.

    You can install the latest versions using the following commands:

    cargo add rig-sqlite rig-core serde_json
    cargo add serde --features derive
    [dependencies]
    rig-sqlite = "0.2.6"
    rig-core = "0.37.0"
    serde = { version = "1", features = ["derive"] }
    serde_json = "1"
  4. Install the Rig-Lancedb companion crate

    main

    To use LanceDB as a vector store with Rig, add rig-lancedb and rig-core to your Cargo.toml. You can use cargo add to fetch the latest versions automatically.

    Pre-requisite: If running locally, you must have protoc (the Protobuf Compiler) installed on your system.

    cargo add rig-lancedb rig-core
  5. Deploy HelixDB queries and schema for rig-helixdb

    main

    The rig-helixdb integration requires a specific queries/schema configuration to function. To deploy a minimum viable configuration using the provided example files:

    1. Navigate to the configuration directory: cd helixdb-cfg
    2. Deploy the configuration: helix push dev

    This deploys the necessary queries and schema into your HelixDB instance.

  6. Use the rig-agent runtime

    main

    The rig-agent crate provides Rig's classic agent runtime, including builders, serializable sans-I/O run state, blocking and streaming drivers, typed hooks, contextual tools, and extraction.

    While most applications should use the root rig facade (where this runtime is enabled by default), you can import construction and prompting explicitly from rig-agent and rig-core.

    use rig_agent::prelude::*;
    use rig_core::{client::ProviderClient, providers::openai};
    
    let client = openai::Client::from_env()?;
    let agent = client.agent(openai::GPT_5_2).build();
    let answer = agent.prompt("Explain ownership briefly.").await?;
  7. Configure AWS credentials for Rig-Bedrock

    main

    Rig-Bedrock requires AWS credentials to be available in your environment before initializing the client. Ensure the following environment variables are set:

    • AWS_DEFAULT_REGION
    • AWS_SECRET_ACCESS_KEY
    • AWS_ACCESS_KEY_ID
    export AWS_DEFAULT_REGION=us-east-1
    export AWS_SECRET_ACCESS_KEY=.......
    export AWS_ACCESS_KEY_ID=......