← 开源

⚙️🦀 Build modular and scalable LLM Applications in Rust

AI EngineeringBuild agent workflow (SDK)Rust
增长势头
+524 小时新增 Star+0.1%
9.39k
Star
1.05k
Fork
+84
本周
100
贡献者
创建于 2024-06-05 · 更新于 2026-12-06 · 今日第 2141 名
主要开发者
README

Rig is a harness: a Rust library for writing AI agents, and a coding agent built on top of it.

Guides · API reference · Examples · Agent guide · Plugin guide

The coding agent

A terminal coding agent you can take apart. Its tools, commands, sessions, sign-in and terminal view are each a Bevy plugin, so any of them can be turned off, replaced or added to. Change one, and /reload rebuilds the agent around you while the session carries on.

cargo install rig
rig

It runs on Linux and macOS with Rust 1.97.1 or newer.

  • /plugins lists the plugins and turns each one on or off.
  • /help lists every command.
  • rig -p "fix the failing test" answers one prompt and exits. Add --json to get the run as JSON lines.
  • rig --json stays running for a script or another agent to drive: one request per line on stdin, one event per line on stdout, until stdin closes. rig help-agents prints the whole protocol.

The agent guide covers the rest, and the plugin guide shows how to write a plugin.

Already paying for another coding agent? The optional rig-bridge plugin uses Claude Code, Codex, Grok Build, Antigravity, Muse or Copilot CLI as a model provider, with that program's own sign-in and no API key. Rig keeps the conversation and tools.

rig plugin enable rig_bridge::BridgePlugin
rig --model claude-code/claude-opus-5-5

The library

One interface over more than 20 model providers. Give an agent a plain Rust function as a tool, and switch providers by changing the model line.

cargo add rig
cargo add tokio --features macros,rt-multi-thread
use rig::prelude::*;
use rig::providers::openai::{self, OpenAI};
use rig::tool::ToolExecutionError;

/// Add two numbers.
#[rig::rig_tool]
fn add(x: i64, y: i64) -> Result<i64, ToolExecutionError> {
    Ok(x + y)
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Reads OPENAI_API_KEY.
    let model = OpenAI::from_env()?.completion(openai::GPT_6_2_SOL);
    let agent = AgentBuilder::new(model)
        .preamble("Use your tools to answer.")
        .tool(Add)
        .build();

    let response = agent.prompt("What is 1234 + 4321?").await?;
    println!("{}", response.output());
    Ok(())
}

For Claude, import rig::providers::anthropic::{self, Anthropic} and the model line becomes Anthropic::from_env()?.completion(anthropic::CLAUDE_SONNET_5_5). The agent and the tool stay as they are.

  • A dozen vector stores behind one interface.
  • Agents with tools, streaming and typed hooks.
  • Completion, embedding, transcription, audio and image models.
  • OpenTelemetry GenAI conventions.
  • rig-core and rig-agent build for browser WASM.

Integrations such as vector stores, local models and saved conversations are Cargo features, for example cargo add rig --features memory,fastembed. docs.rs lists every feature.

Community

Ask questions on Discord. CONTRIBUTING.md says how to contribute, and awesome-rig lists projects built on Rig.

Rig is pre-1.0, so releases break APIs. The changelog and migration notes say what changed. Rig is MIT licensed.

排名相邻
同类项目

AI Rank iPhone 版

随时追踪 AI 模型榜单

在 App Store 下载