contributing
Contribute to the RubyLLM AI framework - set up the repo, run and record specs, work on conversations, individual AI operations, providers, protocols, Rails integration, and docs. Use when fixing a bug, building a feature, writing specs, or changing documentation in the RubyLLM codebase.
crmne · Static checks on file
Installation
Read the source and dependencies before running a command. Copying does not install or execute anything.
npx skills add crmne/ruby_llm --skill contributingAbout this skill
name: contributing description: Contribute to the RubyLLM AI framework - set up the repo, run and record specs, work on conversations, individual AI operations, providers, protocols, Rails integration, and docs. Use when fixing a bug, building a feature, writing specs, or changing documentation in the RubyLLM codebase.
Contributing to RubyLLM
Read AGENTS.md at the repo root first: it has the ground rules, the command table, and the architecture constraints that archspec check enforces. This skill adds the step-by-step recipes.
Choose the layer
The public API covers conversations (Chat, Message, Tool, Agent, structured output, streaming, and loop control) and individual operations (paint, animate, speak, transcribe, ocr, moderate, embed, and rerank). Both connect to services through providers and protocols: providers supply endpoints, authentication, catalogs, and protocol selection; protocols implement formats and their dialects.
Model resolution, configuration, accounting, instrumentation, batches, and provider resources support the framework as a whole. Keep independent operations independent of Chat. Rails integration adds Active Record, Active Storage, Hotwire, jobs, and generators around the same Ruby API; it does not define a second conversation API.
The fast loop
bundle exec rspec --tag ~live # unit tests only, no keys, seconds not minutes
bundle exec rspec spec/ruby_llm/chat_spec.rb:42 # one example
overcommit --run # what the commit hook will run
Run the fast loop while developing. Run overcommit --run before declaring anything done: it runs RuboCop (auto-correct), Flay (duplication), archspec (architecture), and the unit suite, and the commit fails if any of them do.
Working with cassettes
Specs tagged :live replay recorded provider traffic from spec/fixtures/vcr_cassettes. The cassette name derives from the example's full description, so renaming an example orphans its cassette.
To re-record after changing request shapes:
rake vcr:record[openai] # deletes that provider's cassettes, reruns the suite
rake vcr:record[openai,anthropic] # several providers
rake vcr:record[all] # everything (long, needs many keys)
Recording needs real API keys in .env. To re-record a single spec, delete its cassette file and run the spec with the provider's key set.
Rules that bite:
- A failing
:liveexample deletes its own cassette on purpose. Do not "fix" a red spec by restoring the cassette; fix the code, then re-record. - Review every new or changed cassette for leaked keys and personal data before committing. The pre-commit hook runs gitleaks, but eyes first.
- A spec that can neither replay (no cassette) nor record (no key) skips with a message naming the env var it needs. That is expected on a fork without keys.
Adding or changing a chat option
- Add
with_xtolib/ruby_llm/chat.rb(chainable, returnsself). - Add the matching bare
xclass macro tolib/ruby_llm/agent.rb. The archspec build fails without it. - Thread the option through the
Providercontract, never by referencing a concrete provider or protocol fromChat. - Implement per protocol in
lib/ruby_llm/protocols/*(render_*for request payloads,parse_*for responses). - Spec it in
spec/ruby_llm/chat_<x>_spec.rb; add live coverage over the matrix inspec/support/models_to_test.rbwhen providers differ. - Document it on the matching page in
docs/_core_features/.
Working on an individual AI operation
- Start with the public operation and its typed result. Keep the shared RubyLLM names consistent across providers.
- Route service calls through the
Providercontract and registered protocols. Keep request rendering, response parsing, and format quirks in protocols. - Reuse model resolution, configuration, usage accounting, and instrumentation where applicable. Preserve the operation's streaming or job lifecycle.
- Test public behavior and protocol translation at their respective layers. Document the operation in its feature guide and keep its Getting Started example short.
Adding a provider
For smaller or emerging providers, ship a community gem instead of a core PR (the core bar is high, see CONTRIBUTING.md):
bundle exec ruby_llm provider-gem Acme --api-base https://api.acme.ai/v1
That scaffolds a complete gem with specs and CI. For an approved core provider:
script/generate-provider acme
Then make it real:
lib/ruby_llm/providers/acme.rbdeclares auth, API base, and which protocols it speaks (protocol :chat_completions, ...). If the provider has its own wire format, that format is a new protocol underlib/ruby_llm/protocols/, not code inside the provider.- Replace the scaffold's example capabilities with the provider's real ones, and identify the model-catalog source.
- Register the provider in
lib/ruby_llm.rb(the entrypoint is the only place concrete providers get wired in). - Record cassettes covering normal chat and streaming chat at minimum.
- Document configuration in
docs/_getting_started/configuration-providers.md.
Rails work
- Rails specs run against the dummy app in
spec/dummy;acts_as_chatandacts_as_messagelive inlib/ruby_llm/active_record/. - The Rails integration builds on the domain layer and the
Providercontract only. It converts records withto_llm/from_llm; plain-Ruby objects never define those. - Preserve the Ruby conversation API on records, Active Storage attachment support, and the persisted message lifecycle used by Hotwire streaming and background jobs. Individual operations remain callable directly from Rails services and jobs.
- Generators live in
lib/generators/ruby_llm/(install, upgrade, chat_ui, agent, tool, schema, provider). Their specs are tagged:generatorand excluded from the pre-commit run; run them explicitly with `bundle exe