Density Labs / AI agents with Rails

Building AI agents with Rails.

Most AI agent tutorials assume Python and a greenfield repo. Most real businesses run on a mature app with users, data, and revenue, and a lot of them run on Ruby on Rails. The good news: Rails is an excellent place to ship production AI agents, precisely because agents in production are less about the model and more about the boring, reliable machinery Rails already gives you.

Why Rails is a good fit for AI agents

A production AI agent is mostly the parts around the model: background jobs to run long tool calls, a database to hold state and results, retries and idempotency, access control, and an audit trail of what the agent did and why. Rails ships all of that out of the box, ActiveJob, ActiveRecord, strong conventions, so you spend your time on the agent logic, not the plumbing. The model call is a small piece in the middle of a system Rails is already built to run reliably.

The patterns that keep agents reliable

PatternWhy it matters in production
Tools as plain Ruby objectsEach tool is a testable service object with clear inputs and outputs, not a prompt trick.
Agent runs in a background jobLong, looping tool calls belong in ActiveJob, not a web request, with retries and timeouts.
State in the databasePersist each step so a failed run can resume, and so you can see what the agent decided.
A human gate on the hard caseWhen confidence is low or a lookup fails, stop and ask a person. Decide that case on purpose.
Climb only as high as neededMost tasks are a chain or a workflow. Reach for a full agent only when the path is genuinely unspecifiable.

Getting an LLM agent to production in a Rails app

The demo is the easy part. Production means the agent reads your real data through the models you already have, writes back through the same validations your app enforces, runs under monitoring and cost controls, and has an owner. That is an engineering job inside your codebase, not a proof of concept bolted on the side, and it is exactly the kind of work a forward deployed engineer does. When you decide whether a workflow even warrants an agent, the discipline is the same one from agentic AI, explained from production: reach for the loop only when the task demands it.

The full method is in Building AI Agents with Rails: ship production AI agents on Ruby on Rails, part of the Density Labs AI Series. Need senior Rails and AI engineers who ship? We forward deploy them, and we place pre-vetted engineers through PreVetted.