# Rails AI: Building AI Features Into Ruby on Rails Apps

> Rails AI means two things: adding AI features to a Ruby on Rails app, and using AI to build the app. This guide covers both, with real architecture advice.

Source: https://llamapress.ai/rails-ai-building-ai-features-into-ruby-on-rails-apps | Updated: 2026-08-28

---

[LlamaPress Blog](https://llamapress.ai/blog)

Rails AI means two things: adding AI features to a Ruby on Rails app, and using AI to build the app. This guide covers both, with real architecture advice.

 [Back to all articles](https://llamapress.ai/blog)

![Kody Kendall](https://llamapress-ai-image-uploads.s3.us-west-2.amazonaws.com/jujc1ep8nuqrdiftdfer1ngp833u)

Written by

### Kody Kendall

AI & Software Engineer | Creator of the Leonardo Coding Agent

Rails AI means two different things, and people search for both. The first meaning is adding AI features into a Ruby on Rails app: a chat assistant, document summarization, or an agent that works with your data. The second meaning is using AI to build the Rails app itself, with an AI coding agent writing the code. Both are real. Both work in production today. This guide covers both.

We live in both worlds. Every customer app we ship runs on Ruby on Rails, and we operate a fleet of production Rails apps for our customers. Our AI agent, Leonardo, writes Rails code, and the people supervising it ship Rails daily. We also maintain an open-source Ruby on Rails AI framework on GitHub. What follows is what that work has taught us, written for the person deciding what to buy, with enough depth that a developer can check our reasoning.

## The Two Meanings of Rails AI

Ruby on Rails is a web framework, meaning a toolkit for building web applications. Rails is about twenty years old as of this writing, and large commercial products still run on it. A huge amount of business software lives in Rails apps: internal tools, customer portals, billing systems, job trackers. If you own one of those apps, "rails ai" means putting AI features into it. If you need a new app, "rails ai" means something newer: an AI agent that writes the Rails code for you, supervised by human engineers.

The two meanings meet in one place. An AI feature is only useful when it sits inside working software, next to your real data, behind your real logins. Rails is good at exactly that part. The framework ships with a database layer, user accounts, background processing, and live page updates. The AI model itself runs behind an API, which is a paid service you call over the internet. So the framework question matters less than vendors imply, and the plumbing question matters more.

## How AI Features Fit Into a Rails App

AI features in Rails apps share one architecture, whatever the feature is. A good Rails AI integration has four parts. If you are hiring someone to build AI in Rails, ask them about each part. The answers tell you quickly whether they have shipped this before.

**Part one: keys stay on the server.** Your app calls an AI provider with an API key, which works like a password for that service. The key must live on your server, never in the browser. A key exposed in a web page lets strangers run up your bill. This sounds obvious. We still see it in the wild.

**Part two: slow work runs in background jobs.** An AI call can take ten seconds or more. A background job is a task that runs outside the web request, so the page never freezes while the model thinks. Rails has first-class support for this, and a correct build uses it for anything longer than a moment. Retries live here too, because AI providers have outages like any other vendor.

**Part three: replies stream to the page.** Streaming means sending the reply word by word as the model produces it. Rails can push those updates to the browser over a built-in live channel. Users forgive a slow answer that visibly grows. They do not forgive a spinner that sits still for twenty seconds.

**Part four: the agent gets tools, and the tools get permissions.** A chat box that only talks is a toy. The useful version is an agent, meaning an AI that can take actions: look up a customer, draft an invoice, update a job status. In Rails, those actions run through your models, the code that owns your data and its rules. Every tool call must pass the same permission checks as a signed-in user. The AI should never get a skeleton key to your database. Your database stays the source of truth, and the AI stays a worker at the edge of it.

![Code on a developer screen, the kind of Ruby on Rails work an AI agent now drafts](https://images.unsplash.com/photo-1515879218367-8466d910aaa4?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=M3w4NTU2MDF8MHwxfHNlYXJjaHwxfHxzb2Z0d2FyZSUyMGRldmVsb3BlciUyMGNvZGUlMjBzY3JlZW58ZW58MHx8fHwxNzg3ODk3Nzg3fDA&ixlib=rb-4.1.0&q=80&w=1080)

Photo by [Chris Ried](https://unsplash.com/@cdr6934?utm_source=leonardo_rails_app&utm_medium=referral) on [Unsplash](https://unsplash.com/photos/a-computer-screen-with-a-bunch-of-code-on-it-ieic5Tq8YMk?utm_source=leonardo_rails_app&utm_medium=referral)

## What We Learned Building an Open-Source Rails AI Framework

We did not learn this architecture from blog posts. We maintain LlamaBot, an open-source Rails AI framework on GitHub, with a gem called llama\_bot\_rails that wires an agent into a Rails app. A gem is a packaged piece of Ruby code you add to a project. Building the framework, then running it inside real customer apps, taught us a few things worth passing on.

The chat window is the easy ten percent. The hard ninety percent is state and safety. The agent needs to remember the conversation, know which user it serves, and act only within that user's permissions. Every action the AI takes should be logged the same way a human user's actions are logged. When something looks wrong a month later, you want a record of who did what, human or machine.

The other lesson is to keep the model swappable. AI models improve every few months, and prices move with them. A build that hard-wires one provider into fifty files ages badly. A build that keeps the model choice in one place lets you upgrade in an afternoon. Ask any vendor how their work handles a model change. A shrug is your answer.

## The Second Meaning: AI That Writes the Rails App

The newer meaning of AI in Rails is an agent on the other side of the keyboard. Our agent, Leonardo, writes Rails code: models, screens, background jobs, tests. Human engineers supervise the work, review it, and ship it. Those same people ship Rails code themselves every day, so the review is real. The result runs like any Rails app, in a repository you can own, readable by any Rails developer you ever hire.

This changes the economics of custom software more than the chat-widget meaning does. Work that a traditional agency quotes in months now produces a working first version in days. The costs fall with the hours. That is why a business that would never have commissioned custom software now can. We wrote a full page on how that model works as a service at [the Ruby on Rails development company where AI writes the code](https://llamapress.ai/the-ruby-on-rails-development-company-where-ai-writes-the-code). And if your current system is a spreadsheet rather than an app, the fastest path is to [have Leonardo turn the spreadsheet into the first version](https://llamapress.ai/excel-to-app). The spreadsheet already holds your tables, fields, and rules.

The two meanings compound. An agent that writes Rails can also wire AI features into the app it writes, using the same four-part architecture above. You get one build, one database, and one vendor to hold accountable.

## When You Do Not Need AI in Your App

Here is the honest section. Most business apps do not need AI features on day one. If a workflow is deterministic, meaning the same input must always produce the same output, plain code is cheaper, faster, and easier to trust. Invoicing math, status changes, scheduling rules, and permission checks should never run through a model that can improvise. A database with good forms and reports solves most of the pain people bring to us.

AI earns its place where the input is messy. Summarizing a long email thread. Drafting a reply for a human to approve. Reading a stack of PDFs into structured rows. Triaging incoming requests by urgency. If none of that describes your workflow, skip the AI line item and spend the budget on the workflow itself. If you are still deciding which camp you are in, our guide on [adding AI to your website, from chat widgets to real workflows](https://llamapress.ai/how-to-add-ai-to-your-website-from-chat-widgets-to-real-workflows) walks the business side of that decision. A vendor who tries to sell you AI before understanding your workflow is selling the label, and you should read that as a warning.

### Put AI to work in your Rails app

Bring us the Rails app you run today, or the workflow you want one built around. Leonardo writes the Rails code. Engineers who ship Rails daily review every line. You keep the code.

[Add AI to Your Rails App](https://llamapress.ai/services) [See How Leonardo Works](https://llamapress.ai/)

Prefer to start with a message? [Contact us](https://llamapress.ai/contact) and tell us what you run today.

## Frequently Asked Questions

### What does Rails AI actually mean?

The phrase covers two things. It can mean AI features built into a Ruby on Rails application, such as chat, summarization, or an agent that acts on your data. It can also mean AI writing the Rails application itself, with an AI coding agent producing the code under human supervision. Both exist in production today, and one project can include both.

### Is Ruby on Rails a good framework for AI features?

Yes. The AI model runs behind a paid API, so any web framework can call it. What Rails adds is the plumbing an AI feature needs: a database layer, user accounts and permissions, background jobs for slow calls, and live page updates for streaming replies. Those pieces ship with the framework. The stack a vendor knows deeply matters more than the stack that is newest.

### How do I add AI to an existing Rails app?

Follow the four-part architecture. Keep the provider's API key on the server. Run AI calls in background jobs so pages never freeze. Stream replies to the browser word by word. Give the agent tools that run through your existing models and permission checks, and log every action. A competent Rails team can add a first scoped feature to a healthy app without a rewrite.

### How much does a Rails AI integration cost?

Scope decides the number. A single scoped feature, like summarization or a drafting assistant, costs a small fraction of what a full agent with tools costs. As of this writing, traditional agencies bill this work by the month, and AI-assisted teams like ours deliver it in days, which is where the savings come from. Be suspicious of any fixed quote offered before someone has looked at your app and your workflow.

### Can an AI agent really write production Rails code?

Yes, with supervision. Our agent Leonardo writes Rails code every day, and every customer app we ship runs on Rails, operated as part of a fleet of production apps. The part that makes it safe is the human layer: engineers who ship Rails themselves review the agent's work before it reaches your users. An unsupervised code generator is a different, riskier product.
