# 0xplaygrounds/rig architecture

> Architecture diagram of the GitHub repository 0xplaygrounds/rig, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/0xplaygrounds/rig
- Repository: https://github.com/0xplaygrounds/rig

## Overview

Rig is a Rust library for building LLM-powered applications. A host configures a model, then uses the classic agent runtime to turn prompts into model requests, dispatch tool calls, and return results; alternatively, it can call the shared model abstraction directly. The core also provides provider and vector-store integrations, embeddings, multimodal operations, and an ECS runtime with checkpointing. Relationships below are limited to those documented in the README or visible in sampled source/index references; unsampled subsystems are represented by their listed directories without speculative internal flows.

Main entry points: [`crates/rig-agent/src/agent/engine.rs`](https://github.com/0xplaygrounds/rig/blob/main/crates/rig-agent/src/agent/engine.rs) (Agent Engine), [`crates/rig-core/src/driver.rs`](https://github.com/0xplaygrounds/rig/blob/main/crates/rig-core/src/driver.rs) (Model Adapter), [`src/lib.rs`](https://github.com/0xplaygrounds/rig/blob/main/src/lib.rs) (Rig Facade), [`crates/rig-agent/src/agent/builder.rs`](https://github.com/0xplaygrounds/rig/blob/main/crates/rig-agent/src/agent/builder.rs) (Agent Builder)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_facade["Library Surface"]
  node_facade["Rig Facade<br/>[lib.rs]"]
end

subgraph group_agent["Agent Runtime"]
  node_agent_builder["Agent Builder<br/>[builder.rs]"]
  node_agent_engine["Agent Engine<br/>[engine.rs]"]
  node_agent_run["Run State Machine<br/>[mod.rs]"]
  node_agent_hooks["Lifecycle Hooks<br/>[hook.rs]"]
  node_agent_stream["Agent Streaming<br/>[streaming.rs]"]
  node_agent_tools["Tool Registry<br/>[server.rs]"]
  node_agent_bus["Effect Bus<br/>[mod.rs]"]
end

subgraph group_core["Model Core"]
  node_model["Model Adapter<br/>[driver.rs]"]
  node_operations["Model Operations<br/>[operation.rs]"]
  node_wire["Provider Wire<br/>[wire.rs]"]
  node_completion["Completion Contract<br/>[mod.rs]"]
  node_provider_response["Provider Responses"]
end

subgraph group_integrations["Providers And Stores"]
  node_providers["Provider Mappings"]
  node_vector_stores[("Vector Stores")]
  node_embeddings["Embeddings"]
  node_multimodal["Media Operations"]
  node_bedrock["Bedrock Runtime<br/>[client.rs]"]
end

subgraph group_runtime["Stateful Execution"]
  node_ecs["ECS Runtime"]
  node_cassette["Effect Replay"]
end

node_developer(("Application Host"))
node_provider_service(("Model Provider"))

node_developer -->|"uses"| node_facade
node_facade -->|"re-exports"| node_agent_builder
node_facade -->|"re-exports"| node_model
node_developer -->|"configures"| node_agent_builder
node_agent_builder -.->|"starts runtime"| node_agent_engine
node_agent_engine -->|"advances state"| node_agent_run
node_agent_engine -->|"fires hooks"| node_agent_hooks
node_agent_engine -->|"streams turns"| node_agent_stream
node_agent_engine -->|"dispatches tools"| node_agent_tools
node_agent_engine -->|"uses dispatch"| node_agent_bus
node_agent_engine -->|"executes model"| node_model
node_model -->|"encodes and decodes"| node_wire
node_model -->|"runs operation"| node_operations
node_model -->|"returns response"| node_provider_response
node_operations -->|"defines completion"| node_completion
node_wire -.->|"sends request"| node_provider_service
node_providers -->|"implements mappings"| node_wire
node_bedrock -->|"calls AWS Bedrock"| node_provider_service
node_developer -->|"uses integrations"| node_vector_stores
node_developer -->|"requests embeddings"| node_embeddings
node_developer -->|"uses modalities"| node_multimodal
node_developer -->|"selects runtime"| node_ecs
node_ecs -.->|"supports replay"| node_cassette

click node_facade "https://github.com/0xplaygrounds/rig/blob/main/src/lib.rs"
click node_agent_builder "https://github.com/0xplaygrounds/rig/blob/main/crates/rig-agent/src/agent/builder.rs"
click node_agent_engine "https://github.com/0xplaygrounds/rig/blob/main/crates/rig-agent/src/agent/engine.rs"
click node_agent_run "https://github.com/0xplaygrounds/rig/blob/main/crates/rig-agent/src/run/mod.rs"
click node_agent_hooks "https://github.com/0xplaygrounds/rig/blob/main/crates/rig-agent/src/agent/hook.rs"
click node_agent_stream "https://github.com/0xplaygrounds/rig/blob/main/crates/rig-agent/src/agent/streaming.rs"
click node_agent_tools "https://github.com/0xplaygrounds/rig/blob/main/crates/rig-agent/src/tool/server.rs"
click node_agent_bus "https://github.com/0xplaygrounds/rig/blob/main/crates/rig-agent/src/bus/mod.rs"
click node_model "https://github.com/0xplaygrounds/rig/blob/main/crates/rig-core/src/driver.rs"
click node_operations "https://github.com/0xplaygrounds/rig/blob/main/crates/rig-core/src/operation.rs"
click node_wire "https://github.com/0xplaygrounds/rig/blob/main/crates/rig-core/src/wire.rs"
click node_completion "https://github.com/0xplaygrounds/rig/blob/main/crates/rig-core/src/completion/mod.rs"
click node_provider_response "https://github.com/0xplaygrounds/rig/blob/main/crates/rig-core/src/provider_response.rs"
click node_providers "https://github.com/0xplaygrounds/rig/tree/main/crates/rig-core/src/providers"
click node_vector_stores "https://github.com/0xplaygrounds/rig/tree/main/crates/rig-core/src/vector_store"
click node_embeddings "https://github.com/0xplaygrounds/rig/tree/main/crates/rig-core/src/embeddings"
click node_multimodal "https://github.com/0xplaygrounds/rig/tree/main/crates/rig-core/src"
click node_bedrock "https://github.com/0xplaygrounds/rig/blob/main/crates/rig-bedrock/src/client.rs"
click node_ecs "https://github.com/0xplaygrounds/rig/tree/main/crates/rig-ecs/src"
click node_cassette "https://github.com/0xplaygrounds/rig/tree/main/crates/rig-cassette/src"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_facade toneBlue
class node_agent_builder,node_agent_engine,node_agent_run,node_agent_hooks,node_agent_stream,node_agent_tools,node_agent_bus toneAmber
class node_model,node_operations,node_wire,node_completion,node_provider_response toneMint
class node_providers,node_vector_stores,node_embeddings,node_multimodal,node_bedrock toneRose
class node_ecs,node_cassette,node_developer,node_provider_service toneIndigo
```

## Components

### Library Surface

- [Rig Facade](https://github.com/0xplaygrounds/rig/blob/main/src/lib.rs): `src/lib.rs`

### Agent Runtime

- [Agent Builder](https://github.com/0xplaygrounds/rig/blob/main/crates/rig-agent/src/agent/builder.rs): `crates/rig-agent/src/agent/builder.rs`
- [Agent Engine](https://github.com/0xplaygrounds/rig/blob/main/crates/rig-agent/src/agent/engine.rs): `crates/rig-agent/src/agent/engine.rs`
- [Run State Machine](https://github.com/0xplaygrounds/rig/blob/main/crates/rig-agent/src/run/mod.rs): `crates/rig-agent/src/run/mod.rs`
- [Lifecycle Hooks](https://github.com/0xplaygrounds/rig/blob/main/crates/rig-agent/src/agent/hook.rs): `crates/rig-agent/src/agent/hook.rs`
- [Agent Streaming](https://github.com/0xplaygrounds/rig/blob/main/crates/rig-agent/src/agent/streaming.rs): `crates/rig-agent/src/agent/streaming.rs`
- [Tool Registry](https://github.com/0xplaygrounds/rig/blob/main/crates/rig-agent/src/tool/server.rs): `crates/rig-agent/src/tool/server.rs`
- [Effect Bus](https://github.com/0xplaygrounds/rig/blob/main/crates/rig-agent/src/bus/mod.rs): `crates/rig-agent/src/bus/mod.rs`

### Model Core

- [Model Adapter](https://github.com/0xplaygrounds/rig/blob/main/crates/rig-core/src/driver.rs): `crates/rig-core/src/driver.rs`
- [Model Operations](https://github.com/0xplaygrounds/rig/blob/main/crates/rig-core/src/operation.rs): `crates/rig-core/src/operation.rs`
- [Provider Wire](https://github.com/0xplaygrounds/rig/blob/main/crates/rig-core/src/wire.rs): `crates/rig-core/src/wire.rs`
- [Completion Contract](https://github.com/0xplaygrounds/rig/blob/main/crates/rig-core/src/completion/mod.rs): `crates/rig-core/src/completion/mod.rs`
- [Provider Responses](https://github.com/0xplaygrounds/rig/blob/main/crates/rig-core/src/provider_response.rs): `crates/rig-core/src/provider_response.rs`

### Providers And Stores

- [Provider Mappings](https://github.com/0xplaygrounds/rig/tree/main/crates/rig-core/src/providers): `crates/rig-core/src/providers`
- [Vector Stores](https://github.com/0xplaygrounds/rig/tree/main/crates/rig-core/src/vector_store): `crates/rig-core/src/vector_store`
- [Embeddings](https://github.com/0xplaygrounds/rig/tree/main/crates/rig-core/src/embeddings): `crates/rig-core/src/embeddings`
- [Media Operations](https://github.com/0xplaygrounds/rig/tree/main/crates/rig-core/src): `crates/rig-core/src`
- [Bedrock Runtime](https://github.com/0xplaygrounds/rig/blob/main/crates/rig-bedrock/src/client.rs): `crates/rig-bedrock/src/client.rs`

### Stateful Execution

- [ECS Runtime](https://github.com/0xplaygrounds/rig/tree/main/crates/rig-ecs/src): `crates/rig-ecs/src`
- [Effect Replay](https://github.com/0xplaygrounds/rig/tree/main/crates/rig-cassette/src): `crates/rig-cassette/src`

### Other components

- **Application Host**
- **Model Provider**

## Connections

- Application Host → Rig Facade: uses (evidence: `README.md`)
- Rig Facade → Agent Builder: re-exports (evidence: `README.md`)
- Rig Facade → Model Adapter: re-exports (evidence: `README.md`)
- Application Host → Agent Builder: configures (evidence: `README.md`)
- Agent Builder → Agent Engine: starts runtime
- Agent Engine → Run State Machine: advances state (evidence: `crates/rig-agent/src/agent/engine.rs`)
- Agent Engine → Lifecycle Hooks: fires hooks (evidence: `crates/rig-agent/src/agent/engine.rs`)
- Agent Engine → Agent Streaming: streams turns (evidence: `crates/rig-agent/src/agent/engine.rs`)
- Agent Engine → Tool Registry: dispatches tools (evidence: `crates/rig-agent/src/agent/engine.rs`)
- Agent Engine → Effect Bus: uses dispatch (evidence: `crates/rig-agent/src/agent/engine.rs`)
- Agent Engine → Model Adapter: executes model (evidence: `README.md`)
- Model Adapter → Provider Wire: encodes and decodes (evidence: `crates/rig-core/src/driver.rs`)
- Model Adapter → Model Operations: runs operation (evidence: `crates/rig-core/src/driver.rs`)
- Model Adapter → Provider Responses: returns response (evidence: `crates/rig-core/src/driver.rs`)
- Model Operations → Completion Contract: defines completion (evidence: `crates/rig-core/src/operation.rs`)
- Provider Wire → Model Provider: sends request
- Provider Mappings → Provider Wire: implements mappings (evidence: `README.md`)
- Bedrock Runtime → Model Provider: calls AWS Bedrock (evidence: `crates/rig-bedrock/src/client.rs`)
- Application Host → Vector Stores: uses integrations (evidence: `README.md`)
- Application Host → Embeddings: requests embeddings (evidence: `README.md`)
- Application Host → Media Operations: uses modalities (evidence: `README.md`)
- Application Host → ECS Runtime: selects runtime (evidence: `README.md`)
- ECS Runtime → Effect Replay: supports replay
