AI agents in Rails, for a business that actually has customers
Originally published on gkosmo.eu . An agent is a background job that gets to call a few methods I have been putting this post off for months. Partly because "AI agents" is a phrase that makes me tired, and partly because most of what I read about it is either a demo that writes haikus or an architecture diagram with eleven boxes. Here is what I actually run. It's small. You can paste it into a Rails app this afternoon. The gems are rcrewai and rcrewai-rails . I maintain both and I use them on nakyma.io , so this is not a neutral review. It is the thing I reach for. The example A shop. Customers open support tickets. Somebody in the shop reads each one, looks up the customer's orders, decides if it's a refund, a shipping question or something else, and writes a reply. That last person is the bottleneck. We are going to replace the reading and the drafting, and keep the sending. That line matters: agents draft, humans send. Every time I've skipped this rule I regretted it within a week. Setup # Gemfile gem "rcrewai" gem "rcrewai-rails" # config/initializers/rcrewai.rb RCrewAI . configure do | config | config . llm_provider = :anthropic config . anthropic_api_key = ENV . fetch ( "ANTHROPIC_API_KEY" ) config . anthropic_model = ENV . fetch ( "ANTHROPIC_MODEL" , "claude-sonnet-4-5" ) config . temperature = 0.1 end Temperature low. This is a support desk, not a poetry slam. The tool This is the part people get wrong, so it comes first. A tool is a Ruby object the model is allowed to call. Not "the database". Not "ActiveRecord". One method, scoped to one customer, read-only, returning a string. # app/tools/order_lookup_tool.rb class OrderLookupTool < RCrewAI :: Tools :: Base tool_name "order_lookup" description "Recent orders for the customer who opened this ticket. " \ "Returns number, status, total and shipped_at." param :limit , type: :integer , required: false , default: 5 , description: "How many recent orders to return (max 10)" def initialize ( customer :) super ()