Sovereign multi-provider AI mesh for Ruby & Rails
AiAgentRouter · native FFI core · circuit breaking · cloud failover
Install from RubyGems: https://rubygems.org/gems/ruby_llm_mesh
Gem name:
ruby_llm_mesh(underscores) — matches this GitHub repo and the official RubyGems listing. Do not confuse with hyphenated names in design sketches.
ruby_llm_mesh routes intents across:
- A native sovereign mesh (
chimera_coreRust cdylib via FFI) for local P2P-style execution - Real cloud / local LLM HTTP — OpenAI, Anthropic, and OpenAI-compatible nodes (Ollama, LM Studio, …)
When the native library is not compiled, a pure-Ruby fallback keeps the API working. Circuit breaking, optional semantic cache, peer health for multi-node local meshes, RAG helpers, and Rails hooks remain available.
gem install ruby_llm_meshOr in a Gemfile:
gem "ruby_llm_mesh"Then bundle install.
Gem page: rubygems.org/gems/ruby_llm_mesh
Requires Rust / cargo:
bundle exec rake compile
# → ext/chimera_core/target/release/libchimera_core.so (or .dylib / .dll)Without compile, NativeCore uses an in-process Ruby fallback. require "ruby_llm_mesh" never crashes on a missing .so.
require "ruby_llm_mesh"
AiAgentRouter.configure do |c|
c.openai_api_key = ENV["OPENAI_API_KEY"]
c.anthropic_api_key = ENV["ANTHROPIC_API_KEY"]
c.mesh_port = 4233
c.auto_boot_mesh = true
c.fallback_providers = %i[openai anthropic local_node]
end
# Strategy-based execution (v2)
response = AiAgentRouter.execute(
intent: "Summarize circuit breakers in one sentence.",
strategy: :auto # :p2p_mesh | :cloud | :openai | :anthropic | :local_node
)
puts response.content
puts response.provider # => :p2p_mesh or a cloud provider
# Classic complete API (unchanged shape from 0.1.x)
response = AiAgentRouter.complete(
prompt: "Hello from the mesh",
providers: %i[anthropic openai local_node],
fallback: true
)| Strategy | Behavior |
|---|---|
:auto |
Boot native mesh if auto_boot_mesh; use P2P when alive, else real cloud ladder |
:p2p_mesh |
Native chimera_core (or Ruby fallback) only |
:cloud |
HTTP via fallback_providers / default_providers |
:openai / :anthropic / :local_node / :local_mesh |
Single-provider routing |
Cloud paths call the real provider HTTP clients — they are not stubbed simulation strings.
| Option | Default | Description |
|---|---|---|
mesh_port |
4233 |
Native mesh listen port |
auto_boot_mesh |
true |
Auto-start node for :auto / :p2p_mesh |
fallback_providers |
%i[openai anthropic local_node] |
Ladder for :cloud / :auto failover |
default_providers |
%i[openai anthropic local_node] |
Ladder for complete |
fallback |
true |
Continue to next provider on failure |
timeout |
30 |
HTTP open/read timeout (seconds) |
openai_* / anthropic_* / local_node_* |
env-backed | Provider credentials & endpoints |
circuit_failure_threshold / circuit_reset_timeout |
3 / 60 |
Circuit breaker |
semantic_cache_enabled |
false |
Opt-in vector similarity cache |
semantic_cache_threshold / semantic_cache_ttl |
0.92 / 3600 |
Cache match & TTL |
redis_url |
ENV["REDIS_URL"] |
Optional Redis for distributed cache |
peer_discovery_enabled / peer_urls |
off / [] |
Multi-peer local node health |
logger |
nil |
#info / #warn / #error or #call |
| C export | Ruby |
|---|---|
start_node(port) |
RubyLlmMesh.boot_mesh! / NativeCore.start_node |
node_alive() |
RubyLlmMesh.mesh_alive? / NativeCore.node_alive? |
execute_wasm_payload(intent) |
NativeCore.execute_wasm_payload → Hash |
stop_node() |
NativeCore.stop_node |
Same as 0.1.x: per-provider circuits, fallback ladders, AllProvidersFailedError. Providers: :openai, :anthropic, :local_node (alias :local_mesh for peer-aware local routing).
chunks = RubyLlmMesh::Rag::Chunker.new(size: 500, overlap: 50).chunk(long_text)
embedder = RubyLlmMesh::Rag::Embeddings.new(dimensions: 256)
hits = embedder.top_k("billing refunds", documents, k: 3)class Conversation < ApplicationRecord
acts_as_ai_agent
end- Bump the gem to
2.0.0(~> 0.1will not pick this up). complete/AiAgentRouter.completeremain; preferexecutefor mesh strategies.- Install
ffi(declared dependency). Compile native core only if you want the Rust engine. - If you configured RubyGems trusted publishing against
push_gem.yml, update the workflow filename torelease.yml.
bundle install
bundle exec rake test # no Rust required
bundle exec rake compile # optional native build
bundle exec rake test:native # cargo testReleases publish via RubyGems Trusted Publishing using .github/workflows/release.yml on tags matching v*.
| Field | Value |
|---|---|
| Gem name | ruby_llm_mesh |
| GitHub repository owner | theworker02 |
| GitHub repository name | ruby_llm_mesh |
| Workflow filename | release.yml |
| Environment name | release |
Create a GitHub Environment named release. Pushing tag v2.0.0 runs OIDC publish via rubygems/release-gem@v1.
| Token | Hex |
|---|---|
| Ruby | #9B1B30 |
| Coral | #E85D4C |
| Charcoal | #1A1A1A |
Docs: https://theworker02.github.io/ruby_llm_mesh/
Designed with Cursor models Opus and Fable 5.
- Code of Conduct — Contributor Covenant 2.1; see also CONTRIBUTING.md
- Privacy Policy — no phone-home telemetry; prompts and API keys stay with endpoints you configure
MIT — see LICENSE.txt.
