Rig development
Build applications with the Rig Rust LLM framework (rig, rig-core, rig-agent, and companion crates) and operate or extend the rig terminal coding agent (rig-cli, rig-harness, rig-ecs, rig-tools).
Rig is pre-1.0 and breaks public APIs frequently across 0.x releases. Never rely on memorized signatures or older blog snippets: always confirm the project’s pinned version and read live docs from the matching release before writing code.
1. Verify the pinned version and live APIs first
Run these checks in order before implementing or upgrading Rig code:
-
Read the pinned version from the workspace’s
Cargo.lockorCargo.toml(rig,rig-core,rig-agent,rig-harness,rig-ecs). For coding-agent plugins, checkRIG_HOME/project/Cargo.toml(defaultRIG_HOMEis~/.rig), which records either a crates.io version or a local checkout path. -
Query exact Rust signatures for that version:
# In an existing Cargo project, build docs only for the Rig crates you touch: cargo doc -p rig -p rig-core -p rig-agent --no-deps # Search the generated item index (hyphens become underscores in target/doc/): grep -i "AgentBuilder" target/doc/rig_agent/all.html # Before adding a dependency, inspect docs.rs for latest or a pinned <ver>: curl -sL "https://docs.rs/rig/latest/rig/all.html" | grep -i "AgentBuilder"- Feature list for the root facade:
https://docs.rs/crate/rig/latest/features - Machine-readable rustdoc JSON (zstd-compressed):
https://docs.rs/crate/rig/latest/json(replacelatestwith<ver>for a pinned release)
- Feature list for the root facade:
-
Fetch version-tagged Markdown from
0xPlaygrounds/rigwhen you need architecture guides, provider options, or breaking-change diffs. Substitute<ref>withv<version>(for a pinned release) ormain(for HEAD) inhttps://raw.githubusercontent.com/0xPlaygrounds/rig/<ref>/<path>:Topic Repository path ( <path>)Facade overview, quickstart, crate map README.mdRelease-by-release API migration diffs MIGRATING.mdCore contracts, Catalog, providers, WASMcrates/rig-core/README.mdProvider-specific typed request options crates/rig-core/TYPED_OPTIONS.mdAgent runtime, AgentRun, routing, hookscrates/rig-agent/README.mdPersisted sessions and compaction crates/rig-memory/README.mdEffect logs, HTTP replay/record testing crates/rig-cassette/README.mdMCP client tools and dynamic resources crates/rig-rmcp/README.mdCoding agent CLI usage and config docs/agent.mdBevy plugin authoring guide crates/rig-harness/PLUGINS.mdECS kernel ( AgentPass, stages, entities)crates/rig-ecs/README.mdBuilt-in coding tools and remote workspaces crates/rig-tools/README.mdWorking code examples live under
examples/(library) andcorpus/(CI-tested harness plugins) at the same tag. Conceptual guides live athttps://rig.rs/docs, and real-world community projects and templates are cataloged athttps://github.com/0xPlaygrounds/awesome-rig(verify theirCargo.tomlRig version before copying patterns, as community projects may trailmain). Treatdocs.rsand the release tag as the source of truth when guides or examples differ.
2. Crate and feature architecture
Rig splits into a root facade, a portable LLM library stack, opt-in integration crates, and a Bevy-based coding agent harness:
- Root facade (
rig): re-exportsrig-core. Default features enableagent(rig-agent),derive(rig-derive),reqwest+rustls(rig-reqwest), and on native targetscli(rig-cli). Disable defaults (default-features = false) for minimal, custom-transport, or WASM builds. Companion crates map to facade features named without therig-prefix (for examplecargo add rig --features memory,fastembed,qdrant). - Core contracts (
rig-core): messages, models, tools, 20+ built-in providers,conversation(stable message IDs, branches, change log),Catalog(vendor/modelselection withmodels.devand user overrides),Model::checkdry-run option checks, OpenTelemetry GenAI conventions, andInMemoryVectorStore. - Classic agent runtime (
rig-agent):AgentBuilder, the sans-I/O serializableAgentRunstate machine (next_step()yieldingCallModel,CallTools, orDone),Handlersdispatch table,AgentHook::on_model_selectruntime routing,AgentBuilder::memory, andAgentBuilder::record_to. - State, testing, and MCP:
rig-memory: JSON-lines conversation logs (rig-session/4), compaction, turn-boundary forking, andAsyncStore. Pure data (WASM-safe) by default;fsaddsDirStore; SQL stores live inrig-sqlite(SqliteSessionStore) andrig-postgres(PostgresSessionStore) behind theirmemoryfeature.rig-cassette:effect_log(always enabled), classic-agent replay adapters (agent), JSONL log files (jsonl), scrubbed traffic recording (traffic), and native HTTP replay/record fixtures (http,bedrock).rig-rmcp: native-only MCP client (client_config,McpConnection,McpTool,McpClientHandlersynced toToolServerHandle, andresource_contextfor live MCP resources).
- Models and vector stores:
rig-bedrock,rig-vertexai,rig-gemini-grpc,rig-candle,rig-fastembed,rig-typesafeai, and vector-store crates (rig-lancedb,rig-qdrant,rig-postgres,rig-sqlite,rig-mongodb,rig-neo4j,rig-milvus,rig-surrealdb,rig-helixdb,rig-scylladb,rig-s3vectors,rig-vectorize). - Coding agent and Bevy harness:
rig-cli: theriglauncher binary that generates and builds a Cargo project perRIG_HOMEfrom the enabled plugin set.rig-ecs: Bevy ECS kernel (no features, WASM-safe). Models agents, turns (TurnOf), tool calls (CallOf), and effects stepped each frame throughAgentPassstages:Arrive,Review,Commit,Admit,Prepare,Gate,Start.rig-harness: adds sessions, settings, slash commands, and fronts onrig-ecs; stock plugins live inrig-basicsandrig-tui, with optional plugins such asrig-mcp-client,rig-acp,rig-inspect,rig-traffic,rig-fold,rig-steel,rig-bridge, andrig-watch.rig-tools: native coding tools (read,write,edit,search,list,shell,delete) overWorkspace(Local,Remote, andHostssupportingHOST:PATH).
3. Library implementation workflow
- Pick the right dependency layer:
- Standard apps: depend on
rig(addtokiowithmacros,rt-multi-threadand opt into only the companion features you need). - Low-level completion/embedding callers without the agent loop: depend on
rig-core(with--features reqwestfor the default client, or pass a custom transport to<Provider>Config::from_env()?.connect(http)). - Custom schedulers or sans-I/O hosts (ECS, job queues): depend on
rig-agentwithdefault-features = falseand driverig_agent::run::AgentRundirectly.
- Standard apps: depend on
- Validate provider options and routing:
- Use
Model::checkto catch options a selected model drops silently, and consultcrates/rig-core/TYPED_OPTIONS.mdfor provider-specific option structs. - For multi-model routing, register models via
AgentBuilder::named_model/model_route, choose per-run candidates withusing_model, or route per call boundary withAgentHook::on_model_select.
- Use
- Test deterministically with
rig-cassette:- Attach an
EffectLogRecorderviaAgentBuilder::record_to(usekeeping_stream_events()when stream chunk boundaries matter) and stamp logs withAgentReplayExt::stamp. - For HTTP provider fixtures,
RIG_PROVIDER_TEST_MODEdefaults toreplay(recordrefreshes scrubbed fixtures), andRIG_CASSETTE_SNAPSHOTS=check|writevalidates or updates request-body snapshots. Always callfinish()(ortry_finish()outside tests) so unplayed interactions fail instead of passing silently.
- Attach an
4. Coding agent CLI and Bevy plugin workflow
-
Understand home vs project scope:
RIG_HOME(default~/.rig) ownssettings.toml([plugins],[model]),auth/,sessions/,target/,AGENTS.md,skills/, andmcp.json.- A repository provides
AGENTS.md,.rig/skills,.agents/skills, and.rig/mcp.json, never compiled plugins. Give a project a separateRIG_HOMEoutside the repo (for example via.envrc) when it needs a distinct plugin set.
-
Scaffold and verify plugins:
rig plugin new my-plugin # creates RIG_HOME/plugins/my-plugin and registers it rig plugin list # lists crates, areas, and enabled/disabled plugins rig plugin disable NAME # or `rig plugin enable NAME` rig plugin check --build # builds the agent and validates system ordering and settingsRun
/reloadinside an interactive session to rebuild and restart with the same session preserved. -
Follow harness plugin invariants:
- Implement
Plugin + Defaultagainstrig-harness(use rig_harness::prelude::*;). - Load required peer plugins in
buildwithrig_harness::load::<P>so/pluginstracks ownership. Read plugin settings only inbuild, and gate optional integrations withapp.is_plugin_added::<Other>()infinish. - Register systems in
AgentPassunderStage::Prepare,Stage::Gate, orStage::Review, exposing a publicSystemSetwhenever a system mutates shared stage data. UseDecision::decidein gates (first decision wins) andHoldOfentities to pause effects. - Register tools in
buildwithapp.add_tool,app.add_tool_per_call(workspace-aware tools), orapp.add_open_tool(observer-answered tools).
- Implement
5. Pitfalls and compatibility boundaries
serde_jsonfeatures are app-owned:rig-coredoes not forcepreserve_orderorfloat_roundtrip. Addserde_json = { version = "1", features = ["preserve_order", "float_roundtrip"] }in the application’sCargo.tomlif JSON key order or float bit-preservation is required.- WASM boundaries:
rig-core, minimalrig-agent, defaultrig-memory, andrig-ecscompile forwasm32-unknown-unknown(WASI is unsupported). Enablingpdfrequires Web CryptoCrypto.getRandomValues.rig-rmcp,rig-tools, andrig-cassette’shttp/trafficfeatures are native-only. - Coding agent platform and MSRV: the
riglauncher runs on Linux and macOS (not Windows) and tracks a recent Rust MSRV; checkrust-versionin the release’s rootCargo.toml. - Optimistic memory concurrency:
rig-memorychecks log length and appends atomically; handleSessionError::Changedwhenever concurrent runs can target the same conversation log. - Cross-version state and upgrades: serialized
AgentRunenvelopes andrig-memorysession logs require compatible Rig versions. Read the relevant section ofMIGRATING.mdbefore upgrading across0.xreleases.
6. Completion criteria
- The target Rig version is confirmed from
Cargo.lock,Cargo.toml, orRIG_HOME/project/Cargo.toml. - Every Rig type, trait, feature flag, and builder method used in the change is verified against local
cargo doc,docs.rs, or the matching0xPlaygrounds/rigrelease tag. cargo checkand the relevantcargo testsuite (orrig plugin check --buildfor coding-agent plugins) exit 0.