ruby_llm
AGENTS.md4.4k starsChanged 3 months agoMITView on GitHub
How RubyLLM is built. For coding agents first, humans welcome. Read CONTRIBUTING.md for what gets accepted; this file is how to write it. RubyLLM is a Ruby AI framework: chat, tools, agents, structured output, embeddings, reranking, images, video, audio, OCR, moderation, and Rails integration behind one API, with nineteen providers in the box. Plain Ruby (>= 3.2), a handful of small dependencies, no heavyweight abstractions. There are two main parts: the public Ruby API and the providers and protocols that…
- Reads credentials
- Commits and pushes
Trending
Less talk lately.about the whole repository
Who's talking about crmne/ruby_llm
- A Hacker News story“RubyLLM: A delightful Ruby way to work with AI”Hacker News · Mar 11, 2025 · 645 points
- @michaelkoper.com“This new LLM wrapper really shows the beauty of Ruby 👌 github.com/crmne/ruby_llm”Bluesky · Mar 15, 2025 · 19 likes
- A Hacker News story“RubyLLM 1.2.0: Universal OpenAI Compatibility & Custom Models”Hacker News · Apr 17, 2025 · 6 points
- A Hacker News story“Ruby_LLM: A delightful Ruby way to work with AI”Hacker News · Mar 13, 2025 · 4 points
- @hacker-news-jp.bsky.social“RubyLLM: AIをRubyで操作する楽しい方法 RubyLLM: A delightful Ruby way to work with AI 🔺 319 💬 20 🔗 HN Post | Article”Bluesky · Mar 15, 2025 · 3 likes
The biggest 5 of 87 mentions linking to the repository that our crawl found. Each line is their own headline.
See all 87
Talked about on GitHub, Bluesky and Hacker News (87 times).
On GitHub · 46
- Aug 13, 2025gpt-5-mini and other models missing data — parsera-labs/api-llm-specs2 reactions · 1 comment
- Feb 14, 2026chore(deps): update dependency ruby_llm to v1.13.2 — zewelor/ps_events1 reaction · 6 comments
- Nov 11, 2025Use RubyLLM for Gemini recommendations — sh1nj1/plan421 reaction · 9 comments
- Jul 31, 2025Add support for RubyLLM::Message Content — traceloop/openllmetry-ruby1 reaction · 3 comments
- Oct 4, 2026Bump ruby_llm from `be80b6f` to `5ea3d8d` — chloerei/ruby_llm_demo0 reactions
41 more on GitHub
- Aug 17, 2026chore(deps): bump ruby_llm from 1.11.0 to 1.16.0 — Learning-Routes/Learning-routes0 reactions
- Aug 15, 2026Bump ruby_llm from 1.9.2 to 1.16.0 — pappdavid/edemocracy-hu-localisation-verification0 reactions · 1 comment
- Jul 25, 2026Bump ruby_llm from 1.4.0 to 1.16.0 — Stoopidrice/recipe-waifu0 reactions
- Jul 13, 2026Bump ruby_llm from 1.2.0 to 1.16.0 — LMR271/guide-rails0 reactions
- Jul 8, 2026Bump ruby_llm from 1.2.0 to 1.16.0 — Rupa08/plant_care_app0 reactions
- Jul 4, 2026Bump ruby_llm from 1.2.0 to 1.16.0 — jcparfait/Bill0 reactions
- Jul 4, 2026Bump ruby_llm from 1.2.0 to 1.16.0 — naraidk/Chatbot-dog0 reactions
- Jun 24, 2026Bump ruby_llm from 1.15.0 to 1.16.0 — fi11theblanks/situationship-playlist0 reactions
- Jun 16, 2026build(deps): bump ruby_llm from 1.14.1 to 1.16.0 — jbigorra/the-interview0 reactions
- Jun 15, 2026Bump ruby_llm from 1.15.0 to 1.16.0 — GBaum01/Brainstreak0 reactions
- Jun 15, 2026build(deps): bump ruby_llm from 1.15.0 to 1.16.0 — calmacleod/Transactions0 reactions
- Jun 15, 2026Bump ruby_llm from 1.15.0 to 1.16.0 — tomlpzpro/archi_mind0 reactions
- Jun 15, 2026Bump ruby_llm from 1.15.0 to 1.16.0 — Matelis-Git/world-census0 reactions
- Jun 15, 2026Bump ruby_llm from 1.2.0 to 1.16.0 — Claire-d-3/startup-sheriff0 reactions
- Jun 15, 2026Bump ruby_llm from 1.15.0 to 1.16.0 — adrianoterrazas2019-web/nutri-chat0 reactions
- Jun 15, 2026Bump ruby_llm from 1.2.0 to 1.16.0 — ItsMeJade319/AI-vet-chatbot0 reactions
- Jun 15, 2026Bump ruby_llm from 1.15.0 to 1.16.0 — theodora22/AI-Creator-System0 reactions
- Jun 15, 2026Bump ruby_llm from 1.15.0 to 1.16.0 — tomlpzpro/Dreamer-x-maker0 reactions
- Jun 15, 2026Bump ruby_llm from 1.15.0 to 1.16.0 — paul-lesueur/popwearchatbot0 reactions
- Jun 15, 2026Bump ruby_llm from 1.15.0 to 1.16.0 — LhordeS/who-is-the-villain0 reactions
- Jun 15, 2026Bump ruby_llm from 1.2.0 to 1.16.0 — NathanMdt61/OrientIA0 reactions
- Jun 15, 2026Bump ruby_llm from 1.15.0 to 1.16.0 — mjc-gh/isaac0 reactions
- Jun 15, 2026Bump ruby_llm from 1.15.0 to 1.16.0 — AstralVixen373/lore-generator0 reactions
- Jun 15, 2026Bump ruby_llm from 1.2.0 to 1.16.0 — Loranger-dev/dog_chatbot0 reactions
- Jun 15, 2026Bump ruby_llm from 1.15.0 to 1.16.0 — igor-estevao/ruby_llm_review_overview0 reactions
- Jun 15, 2026Bump ruby_llm from 1.15.0 to 1.16.0 — tomasjef/plant-match0 reactions
- Jun 15, 2026Bump ruby_llm from 1.2.0 to 1.16.0 — Tobideimon/THE_BARTENDER0 reactions
- Jun 15, 2026Bump ruby_llm from 1.2.0 to 1.16.0 — Nabi-Biva/nutri-coach0 reactions
- Jun 15, 2026build(deps): bump ruby_llm from 1.14.1 to 1.16.0 — gustavoxpto/instructional-design-app0 reactions
- Jun 15, 2026Bump ruby_llm from 1.2.0 to 1.16.0 — elia48/githealth0 reactions
- Jun 14, 2026Bump ruby_llm from 1.14.1 to 1.16.0 — vyncem/rag_chatbot0 reactions
- Jun 14, 2026build(deps): bump ruby_llm from 1.15.0 to 1.16.0 — pstrzalk/hifumi-dev0 reactions
- Jun 13, 2026Bump ruby_llm from 1.14.0 to 1.16.0 — sdfreund10/calorie-ai0 reactions
- Jun 12, 2026chore(deps): bump ruby_llm from 1.15.0 to 1.16.0 — husseymarcos/handshake0 reactions
- Jun 11, 2026Bump ruby_llm from 1.14.1 to 1.16.0 — vivek-rubylab/rag-chatbot-demo0 reactions
- Jun 11, 2026Bump ruby_llm from 1.2.0 to 1.16.0 — julesLefur/fish_app0 reactions
- Jun 10, 2026Bump ruby_llm from 1.15.0 to 1.16.0 — rodrigotoledo/ai_finance_control0 reactions
- Jun 10, 2026Bump ruby_llm from 1.14.1 to 1.16.0 — cyrillepierre-c44/cyrillepierre0 reactions
- Jun 10, 2026Build(deps): bump ruby_llm from 1.15.0 to 1.16.0 — HandleIT-Club/Mikhael0 reactions
- May 13, 2026chore(deps): bump ruby_llm from 1.14.1 to 1.15.0 — riggy/rygiel_net_v20 reactions
- May 11, 2026Bump ruby_llm from 1.14.1 to 1.15.0 — mattszein/pro-rails0 reactions
On Bluesky · 32
- Mar 15, 2025This new LLM wrapper really shows the beauty of Ruby 👌 github.com/crmne/ruby_llm — @michaelkoper.com19 likes and reposts
- Mar 15, 2025RubyLLM: AIをRubyで操作する楽しい方法 RubyLLM: A delightful Ruby way to work with AI 🔺 319 💬 20 🔗 HN Post | Article — @hacker-news-jp.bsky.social3 likes and reposts · 1 reply
- Mar 28, 2025🔗 crmne/ruby_llm https://github.com/crmne/ruby_llm — @kinduff.com2 likes and reposts
- Mar 24, 2025Loving RubyLLM! Definitely simplifies the integration of LLMs with Rails. As someone who has to build and ship web apps with Gen AI… — @handle.invalid2 likes and reposts · 1 reply
- Mar 15, 2025"RubyLLM: A delightful Ruby way to work with AI" RubyLLM makes using AI easy and fun for Ruby programmers. People are excited about its… — @hackerbriefs.bsky.social2 likes and reposts
27 more on Bluesky
- Mar 15, 2025GitHub - crmne/ruby_llm: A delightful Ruby way to work with AI. No configuration madness, no complex callbacks, no handler hell – just… — @tech-trending.bsky.social2 likes and reposts
- Mar 15, 2025Discovered this fantastic Ruby gem for chatting with LLMs today: github.com/crmne/ruby_llm. Very well put together! 👍🏻 — @ejstembler.bsky.social2 likes and reposts
- Mar 15, 2025RubyLLM: A delightful Ruby way to work with AI view on hacker news — @ycombinatorbot.bsky.social2 likes and reposts
- Mar 15, 2025RubyLLM: A delightful Ruby way to work with AI Discussion — @hackernewsbot.bsky.social2 likes and reposts
- Mar 16, 2025A delightful Ruby way to work with AI. No configuration madness, no complex callbacks, no handler hell – just beautiful, expressive Ruby… — @clipsoflogic.bsky.social1 likes and repost
- Mar 16, 2025https://github.com/crmne/ruby_llm RubyでAIを扱うためのライブラリです。 設定や複雑なコールバックが不要で、美しいRubyコードでAIを操作できます。 AIを使った開発をRubyで行いたい開発者におすすめです。 — @topickapp.bsky.social1 likes and repost
- Mar 16, 2025github.com/crmne/ruby_llm おおー。サクッと使うのにめっちゃ良さそう。 — @hekki.bsky.social1 likes and repost
- Mar 16, 2025RubyLLM: A delightful Ruby way to work with AI https://github.com/crmne/ruby_llm — @mm-hacker-news.bsky.social1 likes and repost
- Mar 16, 2025RubyLLM: A delightful Ruby way to work with AI (@github.com) Main Link | Discussion — @newsycombinator.bsky.social1 likes and repost
- Mar 16, 2025https://github.com/crmne/ruby_llm — @genya0407.social.genya0407.link.ap.brid.gy1 likes and repost
- Mar 15, 2025🌐RubyLLM: AI を扱うための楽しい Ruby の方法 https://github.com/crmne/ruby_llm via #HackerNews — @kdmsnr.com1 likes and repost
- Mar 15, 2025RubyLLM: A delightful Ruby way to work with AI https://github.com/crmne/ruby_llm (http://news.ycombinator.com/item?id=43331847) — @newsyc500.bsky.social1 likes and repost
- Mar 15, 2025RubyLLM: A delightful Ruby way to work with AI view on hacker news — @ycombinatorbot.bsky.social1 likes and repost
- Mar 15, 2025RubyLLM: A delightful Ruby way to work with AI https://github.com/crmne/ruby_llm github.com — @hnbest.bsky.social1 likes and repost
- Mar 15, 2025RubyLLM: A delightful Ruby way to work with AI view on hacker news — @ycombinatorbot.bsky.social1 likes and repost
- Mar 15, 2025RubyLLM: A delightful Ruby way to work with AI https://github.com/crmne/ruby_llm (http://news.ycombinator.com/item?id=43331847) — @newsyc250.bsky.social1 likes and repost
- Mar 15, 2025RubyLLM: A delightful Ruby way to work with AI view on hacker news — @ycombinatorbot.bsky.social1 likes and repost
- Mar 15, 2025RubyLLM: A delightful Ruby way to work with AI https://github.com/crmne/ruby_llm (http://news.ycombinator.com/item?id=43331847) — @newsyc200.bsky.social1 likes and repost
- Mar 15, 2025RubyLLM: A delightful Ruby way to work with AI view on hacker news — @ycombinatorbot.bsky.social1 likes and repost
- Mar 15, 2025RubyLLM: A delightful Ruby way to work with AI (github.com) Discussion | Main Link — @newsycombinatorbot.bsky.social1 likes and repost
- Mar 15, 2025RubyLLM: A delightful Ruby way to work with AI view on hacker news — @ycombinatorbot.bsky.social1 likes and repost
- Mar 15, 2025RubyLLM: A delightful Ruby way to work with AI https://github.com/crmne/ruby_llm https://news.ycombinator.com/item?id=43331847 — @hn100.atproto.rocks1 likes and repost
- Mar 15, 2025RubyLLM: A delightful Ruby way to work with AI view on hacker news — @ycombinatorbot.bsky.social1 likes and repost
- Mar 15, 2025RubyLLM: A delightful Ruby way to work with AI https://github.com/crmne/ruby_llm — @hnbot.gsuscs.xyz1 likes and repost
- Mar 15, 2025RubyLLM: A delightful Ruby way to work with AI #HackerNews https://github.com/crmne/ruby_llm — @hackernewstop5.bsky.social1 likes and repost
- Mar 15, 2025RubyLLM: A delightful Ruby way to work with AI L: https://github.com/crmne/ruby_llm C: https://news.ycombinator.com/item?id=43331847 posted… — @hnws.bsky.social1 likes and repost
- Mar 15, 2025RubyLLM: A delightful Ruby way to work with AI Discussion — @hn100.bsky.social1 likes and repost
On Hacker News · 9
- Mar 11, 2025RubyLLM: A delightful Ruby way to work with AI645 points · 169 comments
- Apr 17, 2025RubyLLM 1.2.0: Universal OpenAI Compatibility & Custom Models6 points
- Mar 13, 2025Ruby_LLM: A delightful Ruby way to work with AI4 points
- Mar 14, 2025Ruby LLM3 points
- Jun 9, 2026RubyLLM 1.16: concurrent tool execution, Rails-style instrumentation, and more2 points
4 more on Hacker News
- Jul 30, 2025RubyLLM 1.4.0: Structured Output, Custom Parameters, and Rails Generators2 points
- Apr 8, 2025RubyLLM 1.1.0: AWS Bedrock support and more2 points
- Apr 2, 2025RubyLLM 1.1.0rc1 is out with Bedrock support and other improvements2 points
- Nov 5, 2025RubyLLM 1.9.1: Rails Namespaces, Vertex AI Auth and Anthropic Uploads1 point
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.
Of the AGENTS.md files we read, the 11,773 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository4 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- .github/copilot-instructions.mdCopilot instructions
- contributingSkill
- rubyllmSkill
The file
Show its rules and text
We split this AGENTS.md into the rules it gives an agent
19 rules. About 0 are common, 11 are distinctive, and 8 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈11
Distinctive · estimate
This author's own choices. Worth a look.
8
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- could be automatic: a setting could enforce it
- Distinctive: line 18
Realtime conversations are outside 2.0's scope: Keep speech generation and transcription, including streamed results.
- Very specific: line 34
Keep operation behavior with its owning domain or protocol.
- Very specific: line 36
Keep application generators, migration-only helpers, and provider scaffolding under lib/generators/ruby_llm/, outside the runtime tree.
- Very specific: line 49
Never edit generated files: lib/ruby_llm/models.json, lib/ruby_llm/aliases.json, docs/_reference/available-models.md.
- Very specific: line 50
Never invent model ids. Every model name in code, specs, and docs must be a real, callable model.
- Distinctive: line 51
Keep diffs small and focused.
- Distinctive: line 53
Never push and never post to GitHub on a maintainer's behalf.
- Very specific: line 109
When you find provider vocabulary in the wrong layer, move it and add the rule to Archspec.rb so it cannot come back.
- Very specific: line 133
No implementation comments.
- Very specific: line 134
Follow the wire-naming idioms above, and generic Ruby ones: no get_/set_ accessor prefixes, no is_ predicates.
- Distinctive: line 147
Keep the RubyLLM module overview current and inspect the rendered API method index.
- Distinctive: line 161
Never use em dashes in new or edited user-facing writing, including release titles, release notes, and agent responses.
- Distinctive: line 169
Do not cut a release for every fix.
- Distinctive: line 174
Before writing release notes, read the previous two stable releases and match their style.
- Distinctive: line 178
Start with a short plain-language summary, followed by a download line when the project ships binaries.
- Very specific: line 183
Use New and Fixed sections as applicable, and Known limitations when there are any.
- Distinctive: line 189
Write about what changed for the user, not the commit history.
- Distinctive: line 192
Every release description is these hand-written notes, never a list generated by GitHub, a changelog tool, or commit subjects.
- Distinctive: line 201
If the release path still generates its notes, switching it to the committed file is part of preparing the next release.
≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
AGENTS.md
How RubyLLM is built. For coding agents first, humans welcome. Read CONTRIBUTING.md for what gets accepted; this file is how to write it.
What this is
RubyLLM is a Ruby AI framework: chat, tools, agents, structured output, embeddings, reranking, images, video, audio, OCR, moderation, and Rails integration behind one API, with nineteen providers in the box. Plain Ruby (>= 3.2), a handful of small dependencies, no heavyweight abstractions.
Framework structure
There are two main parts: the public Ruby API and the providers and protocols that connect it to AI services.
- The public API has two families. Text generation and conversations use
Chat,Message,Tool, andAgent, with structured output, streaming, and loop control. Individual AI operations usepaint,animate,speak,transcribe,ocr,moderate,embed, andrerank, each with a typed result. These operations do not require a conversation; some have streaming or asynchronous lifecycles. - Providers and protocols connect both families to services. Providers supply endpoints, authentication, catalogs, protocol selection, and service-specific settings. Protocols implement request formats, response parsing, streaming, and error normalization. Format quirks belong in protocol dialects selected by providers.
- Shared services support the API. Model and provider resolution, configuration, usage and cost tracking, instrumentation, batches, file storage, and prompt caching belong to the framework as a whole. Do not force an independent operation through
Chatto reuse them. - Rails adds a native application integration. The same conversation API works on application-owned records, with Active Record persistence, Active Storage attachments, Hotwire streaming, Active Job workflows, and generators. Individual operations remain available in Rails services and jobs. Rails integration builds on the Ruby API; the plain-Ruby library has no Rails dependency.
- Conversation history belongs to the application. Build requests from the local transcript. Do not introduce provider-stored conversation cursors or continue a remote history that can diverge from local messages. Defer provider features that require that lifecycle. Preserving native response content for replay is different from storing a conversation remotely.
- Realtime conversations are outside 2.0's scope. Keep speech generation and transcription, including streamed results. A WebSocket transport for one operation does not justify a separate live conversation API. Hosted asynchronous research jobs remain individual operations, not persisted chat sessions.
Source layout
Keep public API objects directly under lib/ruby_llm. This includes objects applications receive and use, such as EmbeddingRequest, SpeechChunk, TranscriptionChunk, VideoJob, UploadedFile, and DownloadedFile, even when their constructors are internal. Put implementation helpers in the namespace that owns them, with matching directories: Protocol::BinaryStreaming, Transport::Connection, Models::Registry, and Support::Inspectable. Use ordinary Zeitwerk naming and update references when moving internal constants; do not use loader.collapse or compatibility aliases to rearrange internal code. Keep operation arguments and public result behavior unchanged. Follow the same namespaces in specs.
| Directory | Responsibility |
transport/ | HTTP, WebSockets, retry boundaries, and connection middleware |
protocol/ | Shared streaming and response assembly |
models/ | Model catalog schemas, reconciliation, and alias lookup |
accounting/ | Usage entries and operation accounting |
files/ | File handling internals such as MIME detection |
tools/ | Shared tool selection and resolution |
support/ | Cross-cutting primitives such as inspection, instrumentation, deprecation, and utility functions |
Keep operation behavior with its owning domain or protocol; support/ is not a place for provider logic or unrelated features. Preserve bundled JSON and generator-template locations when moving code that uses __dir__. Archspec enforces the boundaries independently of these organizational folders.
Keep application generators, migration-only helpers, and provider scaffolding under lib/generators/ruby_llm/, outside the runtime tree. Rake tasks belong in lib/tasks/ or the repository's tasks/. Load this tooling explicitly from its commands or generated migrations. lib/ruby_llm/active_record/ contains the record behavior applications use, not upgrade tooling.
What we are optimizing for
The pitch is the public API. Every change is judged against four things, in this order:
- Ruby-native. The API reads like Ruby that a Rails developer already knows: chainable setters, one name per concept, keyword arguments, value objects with readers, predicates that end in
?, and nothing that looks like a port of a Python SDK. If DHH would raise an eyebrow at a method name, rename it. - Seamless in Rails.
acts_as_chatandacts_as_messagemake an application's own records behave exactly like the plain-Ruby objects. RubyLLM owns its supporting tables, the app owns chats and messages, and every plain-Ruby feature works on a persisted record without a second API. - Providers and protocols in their place. A provider is who you talk to; a protocol is how. Wire vocabulary never leaks into the domain, and the domain never names a provider.
Archspec.rbfails the build when it does. - Craftsmanship. Small focused diffs, specs for every behavior, RDoc on every public method, docs in the Rails-guides voice, no implementation comments, no dead code. Quality is the feature.
Ground rules
- Never edit generated files:
lib/ruby_llm/models.json,lib/ruby_llm/aliases.json,docs/_reference/available-models.md.rake modelsregenerates them. - Never invent model ids. Every model name in code, specs, and docs must be a real, callable model. Check with
RubyLLM.models.find. - Keep diffs small and focused. No drive-by refactors, no style sweeps outside the lines you touch.
- Plain commit messages that describe the change: a subject of at most 60 characters, a body wrapped at 72 that says why. No "Generated with" footers, no Co-Authored-By tags.
- Never push and never post to GitHub on a maintainer's behalf. Commit locally and leave the rest to the maintainer.
- Gem publication starts when a maintainer publishes a GitHub release. A branch or tag push does not publish the gem. Keep the release tag, gem version, and prerelease setting consistent; see CONTRIBUTING.md for the release commands.
Setup
bundle install
overcommit --install # required: installs the git hooks that gate every commitCommands
| Command | What it does |
bundle exec rspec --tag ~live | Fast unit run. No API keys, no cassettes needed. |
bundle exec rspec spec/ruby_llm/chat_spec.rb:42 | One example. |
bundle exec rake test | Full suite through rspec-queue, like CI. |
bundle exec rspec --tag generator | The slow Rails generator specs, excluded from the commit hook. |
overcommit --run | Everything the pre-commit hook runs: RuboCop, Flay, archspec, RSpec. |
bundle exec rubocop | Lint (auto-corrects on commit). |
bundle exec archspec check | Architecture rules from Archspec.rb. |
bundle exec rake conformance | The official MCP client conformance suite against RubyLLM::MCP (needs Node). |
bundle exec rake benchmark | RubyLLM's own overhead, offline; rake "benchmark:compare[v2.0.0]" compares against another ref. |
bundle exec appraisal rails-8.0 rspec | Rails version matrix (7.1 through 8.1, see Appraisals). |
docs/bin/serve.sh | Docs preview at localhost:4002. |
Public API rules
- Chain setters, read state. Every
Chat#with_xreturnsself, acceptsnilto reset, and has a barexreader (instructions are the one exception: they live in the transcript, so readchat.messages). Everywith_xalso has a barexclass macro onAgentand appears in the delegate lists inAgentandActiveRecord::ChatMethods; the delegation specs fail when the three drift. - Feature switches share one shape.
with_thinking,with_citations,with_caching, andwith_compactiontake nothing ortrueto enable,falseto disable, and options as keywords or a Hash. They rejectnil. - One name per concept, everywhere.
max_output_tokensnotmax_tokens,thinkingnotreasoning,cache_readandcache_write,provider_optionsfor the provider's own vocabulary,provider:as a keyword. The registry's capability names come from models.dev and stay as they are (supports?(:reasoning)). - One interface over every provider. RubyLLM is the Ruby-native AI framework, and one consistent API across every provider is a big part of why it exists. When two or more providers can do the same thing, design one RubyLLM name for it and translate it in each protocol:
pages:onocr,uri:andcontent_type:onupload,thinkingacross five different reasoning APIs.provider_optionsis for the one thing only one provider does, never a shortcut past designing the shared name. Study what each provider offers, find the concept they share, and give it a Ruby name a Rails developer would guess. - Capabilities are one query,
supports?(:vision), never asupports_vision?predicate. - RubyLLM's own enumerations are Symbols.
finish_reasonis:stop, a usage entry's status is:succeeded, thinking effort is:medium,Model#typeis:chat. Values that come from a provider or from models.dev (slugs, model ids, MIME types, reasoning option values) stay Strings, and protocols turn Symbols into Strings only at the wire. - Bang methods are for a meaningfully different pair, like
create/create!. Mutation, persistence, blocking, or network activity alone does not earn a bang.cancel,approve,refreshare plain. - Value objects, not hashes. Results are typed (
Message,Tokens,Cost,Citation,Moderation::Result) with readers named after the concept.to_his for serialization,inspectis one short line throughInspectable. - One cost interface.
costreturnsRubyLLM::Cost, using the provider's reported amount when available and calculated cost otherwise. Preserve unknown amounts asnil. The source of a stored amount is internal accounting information, not a second public cost API. - Remote approvals use a predicate. A tool call's
remote?distinguishes provider-executed tools from local Ruby tools. Persist that boolean; its call ID identifies the approval request. Do not use a provider's server label as the execution-mode flag. - Save file and media results consistently. Complete downloadable results expose
save(path), returning the path, andto_blobfor their bytes. ShowRubyLLM.speak(...).save(path)and equivalent calls before manual file writing. Streaming is optional; when an operation also returns its complete result, that result keeps the same saving API. - Errors take the message first and the response as a keyword:
Error.new("msg", response: response). - Let the provider reject what the model can't do. Raise before a request only when the protocol cannot express it, such as an operation the provider lacks or an attachment its wire format cannot carry. Don't check model capabilities, provider limits, or option values the API validates itself: its error is current, and a copy in RubyLLM goes stale. Don't silently downgrade an explicit request either. Trust the shape of a successful response; one rescue that turns a malformed body into a RubyLLM error is enough. Do check what maps a response back onto your inputs, such as indices, IDs, and positions: a wrong mapping corrupts results silently.
- Public means documented. RDoc on the method, an example in
docs/, and:nodoc:on everything that is internal.
Boundaries (enforced by Archspec.rb)
Archspec.rb at the repo root is the architecture documentation, and archspec check fails the build when code violates it. Read it before moving anything across layers. The short version:
- Domain objects (
Chat,Message,Tool,Agent, ...) never referenceRubyLLM::ProvidersorRubyLLM::Protocols, never name a provider or a wire format in a method, and never carry a table of provider values. They delegate through theProvidercontract. - Protocols (
lib/ruby_llm/protocols) are wire formats: Chat Completions, Responses, Anthropic, Gemini, Converse, Cohere, Files, and provider-specific storage APIs. Serialization methods arerender_*, parsing methods areparse_*. A protocol normalizes on the way in and out: it maps its finish reasons ontostop,max_tokens,tool_calls, andcontent_filterin itsfinish_reasonstable, it decides its own request rules (OpenAI strict mode lives in the OpenAI protocols, not inChat), and it turns its error bodies into RubyLLM errors. Register every operation throughprotocol; do not add operation-specific protocol registries or macros. - Providers (
lib/ruby_llm/providers) are adapters: auth, endpoints, catalogs, dialect quirks. A provider declares which protocols it speaks; it never defines a new wire format inline. A protocol that needs something only the provider knows asks its@providerfor it. - Hosting does not create a new protocol. When a cloud provider hosts an existing wire format, reuse that protocol's modules. Keep endpoint and deployment-name differences with the provider; put serialization shared with the original service in the common protocol. Compose only the operations the hosted endpoint supports.
- Support (
Configuration,Models,Model,Connection, errors) is a leaf layer: it knows neither protocols nor concrete providers, nor Active Record. Provider-specific registry behavior, such as how a provider spells a models.dev id, goes through aProviderclass hook (models_dev_alias,models_dev_model_id), not a branch on the slug. - Model metadata comes from models.dev. Report incorrect or missing pricing, limits, release dates, knowledge cutoffs, families, or modalities upstream instead of maintaining parallel tables. Provider model parsers record facts the provider returns. Provider
capabilities.rbfiles may only augment feature capabilities that neither the provider listing nor models.dev can express, based on explicit upstream fields, exact model ids, or unambiguous operation markers, never broad family matchers that guess about current or future models. - Registry reconciliation stays generic. Provider-specific model-id aliases belong with that provider's catalog code, and registry generation diagnostics belong under
tasks/, outside the runtime library. Provider gemmodels.jsonfiles are explicitly registered, read-only fallbacks: the main registry wins conflicts, global refresh never queries or rewrites catalog-backed provider gems, and only the provider gem's ownrake modelsupdates its packaged catalog. - The plain-Ruby library never touches Active Record. Rails integration lives in
lib/ruby_llm/active_recordandlib/ruby_llm/railtie.rbonly, converts withto_llm/from_llm, and delegates through the domain and theProvidercontract.
When you find provider vocabulary in the wrong layer, move it and add the rule to Archspec.rb so it cannot come back.
Rails integration rules
- A persisted chat behaves like a plain chat. Whatever
Chatcan do,acts_as_chatrecords do through the same names, andAgent.findgives back the record with the agent's tools, instructions, and options applied. - RubyLLM owns
ruby_llm_models,ruby_llm_tool_calls,ruby_llm_usages,ruby_llm_batches,ruby_llm_mcp_credentials, andruby_llm_provider_files. Applications own chats and messages. Schema changes go through the install generator for new apps and the upgrade generator for apps on the last release; both must move together in the same change. The upgrade generator carries only the changes since the last release. Replace it each release instead of accumulating upgrade templates, and point apps on older releases to the upgrade guide in that release's documentation. - Persisted usage entries require both a provider and a model, with presence validation and
NOT NULLconstraints. Themodelcolumn names what the provider ran and billed: a model ID, or for an operation without one, the provider's own resource identifier, such as a hosted agent or a guardrail ID and version. Never invent one, including to satisfy a migration. Existing rows without a model must be corrected from their original requests before upgrading. - Every billable provider attempt reaches the usage ledger in Rails and
usage.ruby_llmeverywhere, including failed and blocked attempts the provider billed. Chat records write their own rows; every other attempt, from one-shot operations and chats without a record, gets a row with no chat, attributed to theowner:keyword orRubyLLM.with_usage_owner. A ledger write never breaks the operation, and the plain-Ruby library reaches the ledger only through the hook the railtie installs. - Persistence must survive other processes: cancellation, approvals, and the loop verbs read and write the database, and anything polled inside a job runs outside the query cache.
- Generators write what a Rails scaffold would: omakase style, conventional paths, no starter prose, no TODO comments beyond the one place the developer has to type. An empty prompt file means no instructions.
- Rails specs run against the dummy app in
spec/dummy. Generator specs are tagged:generatorand excluded from the pre-commit run because they are slow.
Testing
- Specs tagged
:livetalk to provider APIs through VCR cassettes inspec/fixtures/vcr_cassettes. Everything else is a plain unit test. Every bug fix ships with a unit spec that fails before the fix. - Cassette names derive from the example's full description. A failing
:liveexample deletes its cassette on purpose, so the next run hits the real API instead of replaying a recording that may be hiding the bug. - Re-record cassettes with
rake vcr:record[openai,anthropic]orrake vcr:record[all](needs real API keys in.env). Check cassettes for leaked keys before committing.bin/gitleaks-stagedruns in the pre-commit hook and CI runs gitleaks again. - Protocol chat modules use
module_function. To unit-test a render or parse method, extend the module (plusToolsandMediawhen the method needs them) onto a bare Object, the way the existing protocol specs do. spec/support/models_to_test.rbdefines the provider and model matrix the live specs iterate over.- Select models with
model_for(:openai)or a named purpose such asmodel_for(:openai, :temperature)from that file. Keep literal IDs only when the exact name is the behavior under test, such as aliases, catalog matching, or wire fixtures. - Changed a wire request? Re-record the cassette. Changed a parsed value? Update the protocol spec, not the domain spec.
Code style
- No implementation comments. A comment earns its place only by stating a constraint the code cannot show. Public API gets RDoc; see
.rdoc_optionsfor what is documented. - Follow the wire-naming idioms above, and generic Ruby ones: no
get_/set_accessor prefixes, nois_predicates. - Flay rejects structural duplication above mass 70. If two providers or protocols share shape, extract, do not copy.
- RuboCop runs with auto-correct on commit; do not disable cops inline unless the existing code already does at that spot for the same reason.
Docs
- The Jekyll site lives in
docs/with four collections:_getting_started,_core_features,_advanced,_reference. Preview withdocs/bin/serve.sh. - Homepage sections alternate between the base background and the darker
home-bandbackground. When adding, removing, or moving a section, preserve the alternation through every following section and the footer. Check the rendered result in light and dark mode, on desktop and mobile. - Keep docs focused on RubyLLM. Do not add provider listings, promotional links, or dedicated setup sections for third-party services that only change an existing provider's API base URL or API key. Their RubyLLM integration instructions belong in their own documentation. Document generic endpoint configuration once; provider-specific additions must satisfy the acceptance policy in
CONTRIBUTING.md, including documentation-only PRs. - Voice is Rails-guides style: second person, present tense, short sentences, code first, motivate before mechanics. No em dashes. No hype, no "simply". RDoc follows the Rails API voice: "Returns the ...", one line where one line will do.
- Let working examples show what the framework can do. Start with the shortest useful public API call, then add options, integration examples, and provider details where readers need them. Keep guide openings consistent: title, description, and "After reading this guide, you will know". Explain concepts before summarizing them in a table.
- Document the shared API once. Adding provider support usually updates an existing example or coverage entry, not a new section. Include provider-specific notes only when a difference changes what the reader must configure, call, or handle. Put setup requirements in provider configuration and link to them. Omit interchangeable examples, wire-format details RubyLLM handles, and accounts of implementation or live-test results from user guides.
- Give each standalone AI operation a discoverable guide, and feature new operations in the release overview. Group closely related operations, such as file uploads and downloads, on one page. Do not bury an operation such as
RubyLLM.tokenizeinside a guide about another feature. - Keep the RubyLLM module overview current and inspect the rendered API method index. RDoc's coverage report does not detect methods it never discovers, including dynamic delegates and Rails macros. Link delegated methods to their shared contract instead of repeating the documentation.
- Front-matter
titleanddescriptionfeed llms.txt and the social-card images. Keep descriptions to one compelling sentence and never use&,<, or>in them. - Cross-link with
{% link _collection/page.md %}, never hard-coded URLs. Use thesite.models.*ids fromdocs/_config.ymlin examples so model names stay current. - A public API change is not done until its docs page changes in the same commit, and
docs/_reference/upgrading.mdrecords anything that breaks.
<!-- github-automation: release-notes -->Releases
This section is maintained account-wide by crmne/github-automation and is replaced when that policy changes. Do not edit it here. If it does not fit this repository, say so in a review or issue, and put repository-specific release steps in a separate section, which takes precedence.
Never use em dashes in new or edited user-facing writing, including release titles, release notes, and agent responses. Use commas, colons, parentheses, or full stops. Existing text does not need to change just to follow this.
The rest of this section applies only when this repository publishes GitHub releases. If it has none, skip it, and do not add tags, release workflows, or release-notes files just to follow it.
Do not cut a release for every fix. Work accumulates on the default branch until there is something substantial to announce: a feature, or a batch of fixes worth a changelog entry. The exception is a regression in something just released, which goes out as soon as it is fixed.
Before writing release notes, read the previous two stable releases and match their style. If there are fewer, read the most recent releases that exist, including prereleases, and follow their format.
- Start with a short plain-language summary, followed by a download line when the project ships binaries.
- Include screenshots or short videos of the main user-visible changes. Capture only synthetic demo content, never real user data. Host the media where earlier releases do, such as release assets or files beside the notes.
- Use
NewandFixedsections as applicable, andKnown limitationswhen there are any. Lead each item with a bold user-facing result and credit who did what with issue or pull request numbers ("By @x; thanks @y"), acknowledging reporters separately from implementers. - Include a
Thankssection listing contributors and reporters, and end with**Full changelog**:and a link comparing the previous tag. - Write about what changed for the user, not the commit history. Describe known limitations honestly.
Every release description is these hand-written notes, never a list generated
by GitHub, a changelog tool, or commit subjects. Commit the notes before
tagging, in the repository's existing release-notes location, or as
packaging/release-notes/vX.Y.Z.md when it has none. Any publishing path that
uses the committed file works, for example softprops/action-gh-release with
body_path and generate_release_notes: false, gh release create
--notes-file, GoReleaser's --release-notes, or gh release edit
--notes-file when another step creates the release.
If the release path still generates its notes, switching it to the committed file is part of preparing the next release. Make a missing notes file stop the release before any tag or release is created.
A release is not finished until every image, video, and download link in its notes loads. Upload the release media right after the release is published and before announcing it, then open the published release and check every image and link.
<!-- /github-automation: release-notes -->Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

