Skip to content
RailsDev.io

Agent Skills for Rails: Let AI Extend Your App Without Breaking It

Rails agent skills: package business logic as agent skills so AI coding agents extend your app safely, durably, and upgrade-proof.

Hendra NicholasRails Full-Stack Developer & AI Engineer

Updated 10 min read

Diagram showing a Rails app with an agent-skills layer: business logic encapsulated as versioned skills, AI agent invoking skills through a Rails engine, and guardrails for tests, migrations, and upgrades.
On this page
  1. What I mean by “agent skills”
  2. Why Rails apps are especially vulnerable to agent drift
  3. The contract layer: skills as explicit interfaces
  4. Where skills should live (and where they shouldn’t)
  5. Tests are the upgrade firewall
  6. Making skills discoverable to agents
  7. Skills and the Rails upgrade path
  8. When not to use an agent skill
  9. A practical first step
  10. Honest limits
  11. Frequently asked questions
  12. Conclusion

Rails agent skills are my answer to a year of watching AI coding agents try to extend Rails applications. Most of them fail in the same way: they guess at model associations, patch controller actions without touching tests, and leave behind service objects that nobody can find six months later. The result isn’t just technical debt. It’s upgrade risk. When Rails 8.2 arrives, your app won’t break because of Rails. It will break because an agent added logic in a place the framework doesn’t expect, and your test suite doesn’t cover it.

I’m not here to sell you on “vibe coding” your production SaaS. I’m here to propose something more boring and more useful: treat agent skills as first-class, discoverable units of Rails business logic. If an AI agent is going to touch your app, it should extend it through explicit, versioned, testable interfaces—not by improvising in app/controllers and hoping for the best.

What I mean by “agent skills”

In the agent world, a “skill” is usually a named capability with a description, input schema, and output contract. Think of it like a route, but for an LLM. Instead of the agent reading your entire app/ directory and deciding where to add a discount calculation, it discovers a skill called calculate_order_discount, reads its contract, and calls it.

For Rails, that means mapping business logic to something the agent can find without guessing. A skill isn’t just a Ruby method. It’s a method plus:

  • A stable name and human-readable description
  • Explicit input and output types
  • A location that doesn’t migrate with every refactor
  • Test coverage that runs in CI
  • A record of which Rails version it was last validated against

Your models, jobs, and service objects already contain the logic. What’s missing is the discovery layer. Agents don’t know that PricingService.call is the canonical place for discount math unless you tell them.

Why Rails apps are especially vulnerable to agent drift

Rails has strong conventions, which is usually a blessing. With agents, it becomes a trap. An agent sees app/models, app/controllers, and app/services, and it assumes any file in those directories is fair game. It might add a before_action to ApplicationController, monkey-patch ActiveRecord::Base, or stuff a complex calculation into a helper.

None of those things break immediately. They break six months later when you run rails app:update after a Rails minor release, or when a gem dependency changes and the agent’s patch conflicts with the new framework code. The more an agent improvises inside framework-owned directories, the higher the chance your next upgrade is a multi-day excavation instead of a bundle update.

I’ve seen teams delay Rails upgrades for quarters because their test suite was green but their production behavior had silently diverged from framework expectations. Agent-generated code is often the hidden variable.

The contract layer: skills as explicit interfaces

Before an agent touches your codebase, you should define what it is allowed to extend. I like to start with a small skills directory at the Rails root, outside of app/:

ruby
# config/agent_skills.rb
Rails.application.config.to_prepare do
  Rails.agent_skills ||= {}
  Rails.agent_skills["calculate_order_discount"] = {
    description: "Calculate the applicable discount for an order based on customer tier and promo code.",
    input: { order_id: "Integer", promo_code: "String?" },
    output: { discount_cents: "Integer", reason: "String" },
    implementation: "OrderPricingSkill",
    last_validated_rails: "8.0",
    tests: "test/agent_skills/order_pricing_skill_test.rb"
  }
end

This is a registry, not a framework. It tells both humans and agents where canonical logic lives. The actual implementation can remain a plain Ruby class, a service object, or even a concern—whatever fits your existing style. The registry is the discoverable part.

If you’re already using RubyLLM or another Ruby AI library, you can expose this registry as tool definitions. If you’re not, the registry still serves as documentation for any agent that reads your repository, including Cursor, Copilot, or a custom CLI tool.

Where skills should live (and where they shouldn’t)

Skills belong in stable, non-framework directories. I recommend lib/agent_skills/ or app/skills/ if you prefer keeping everything under app. The key is that the location is intentional and excluded from casual controller/model sprawl.

ruby
# app/skills/order_pricing_skill.rb
module AgentSkills
  class OrderPricingSkill
    def self.call(order_id:, promo_code: nil)
      order = Order.find(order_id)
      result = PricingService.calculate_discount(order: order, promo_code: promo_code)
      { discount_cents: result.discount_cents, reason: result.reason }
    rescue ActiveRecord::RecordNotFound
      raise ArgumentError, "Order #{order_id} not found"
    end
  end
end

Notice what this class does not do: it doesn’t render views, it doesn’t touch params, and it doesn’t assume a web request context. It takes explicit inputs and returns explicit outputs. That makes it easy to test and easy for an agent to invoke without understanding your controller layer.

Avoid putting skills in:

  • app/controllers — agents will treat them as endpoints and couple them to HTTP
  • app/models as callbacks — agents will struggle to isolate side effects
  • config/initializers — these run at boot and are hard to test in isolation
  • lib/tasks unless they are strictly Rake wrappers around a skill

Tests are the upgrade firewall

Every agent skill needs a test that runs in CI. Not an integration test that spins up a browser. A focused unit test that validates the contract:

ruby
# test/agent_skills/order_pricing_skill_test.rb
require "test_helper"

class AgentSkills::OrderPricingSkillTest < ActiveSupport::TestCase
  test "returns discount for tiered customer" do
    order = orders(:one)
    result = AgentSkills::OrderPricingSkill.call(order_id: order.id, promo_code: "WELCOME20")

    assert_equal 2000, result[:discount_cents]
    assert_equal "promo_code_applied", result[:reason]
  end

  test "raises on missing order" do
    assert_raises(ArgumentError) do
      AgentSkills::OrderPricingSkill.call(order_id: -1, promo_code: nil)
    end
  end
end

The second part of the firewall is a version pin. In your skill registry, record which Rails version the skill was last validated against. When you upgrade Rails, add a CI step that flags any skill whose last_validated_rails is older than the target version. It doesn’t have to block the deploy, but it should force a human to review whether the skill still behaves correctly.

I don’t have benchmark data showing how many fewer upgrade incidents this prevents. It’s an operational observation from client work, not a controlled study.

Verification note: I have not independently verified specific upgrade failure rates attributable to agent-generated code in Rails applications. The claim that framework-owned directories increase upgrade risk is based on consulting experience, not published statistics.

Making skills discoverable to agents

Discovery is where most Rails AI integrations fall down. An agent can’t use a skill it can’t find. You have three practical options, depending on how much infrastructure you want to build.

First, the simplest: commit the skill registry to your repository and instruct your agent in its system prompt to read config/agent_skills.rb before modifying business logic. This costs nothing and works with any agent that can read files.

Second, if you’re already exposing your Rails app to external agents, consider an MCP server. The Model Context Protocol lets agents discover capabilities dynamically. There is an official Ruby SDK for building MCP servers, and you can expose each agent skill as an MCP tool with its input schema and description.

Verification note: I have not verified the current stability or release status of the official Ruby MCP SDK. Treat it as an emerging integration point and check the repository before depending on it in production.

Third, if you use RubyLLM or a similar library, you can register skills as tools directly in your Ruby code. The pattern is similar: define the tool schema, map it to a Ruby callable, and let the LLM decide when to invoke it.

Whichever approach you choose, the skill description matters more than the implementation. Agents match on semantics, not file names. Write descriptions like “Calculates applicable discount for an order” rather than “Order pricing logic.”

Skills and the Rails upgrade path

This is the part I care about most. Rails upgrades are already stressful. You don’t need an agent’s experimental service object surfacing as a deprecation warning in Rails 8.2.

When you prepare for an upgrade, treat agent skills as part of your surface area. Before running rails app:update:

  1. List all skills in your registry.
  2. Run their tests against the current Rails version.
  3. Note any skill whose last_validated_rails predates the target release.
  4. For flagged skills, write a test that exercises the skill under the new Rails version, or deprecate the skill and inline the logic where it belongs.

If you use Solid Queue or Solid Cache in Rails 8, skills that enqueue jobs or touch the cache should be reviewed for concurrency assumptions. An agent might have written a skill that assumes synchronous execution, which breaks under background job processing.

I can’t give you a version-specific checklist for Rails 8.1 versus 8.2 because I don’t know which patch releases will exist by the time you read this. The principle is version-agnostic: explicit skills are easier to audit than implicit logic scattered across controllers.

Verification note: I have not verified specific Rails 8.1 or 8.2 deprecations, release dates, or patch versions. Refer to the official Rails release notes for upgrade guidance.

When not to use an agent skill

Not every controller action needs to be a skill. If the logic is purely presentational—formatting JSON for a Turbo Stream response, say—keep it in the controller or a view component. Skills are for business logic that might be reused, extended, or audited: pricing, eligibility checks, state transitions, report generation.

Also, don’t expose destructive skills to agents without human-in-the-loop confirmation. A skill called refund_payment should require approval, not be auto-invoked by an agent responding to a Slack message. The skill registry is a good place to record which skills are read-only and which are mutating.

A practical first step

If you want to try this on an existing Rails app, start small:

  1. Pick one piece of business logic that agents keep guessing at—usually pricing, access control, or report generation.
  2. Extract it into app/skills/ with explicit inputs and outputs.
  3. Add it to config/agent_skills.rb with a description and test path.
  4. Write one test that validates the contract.
  5. Tell your coding agent to consult the registry before touching that domain.

You don’t need an MCP server, a vector database, or a new gem. You need a directory, a registry file, and the discipline to point agents at it instead of letting them improvise.

Honest limits

Agent skills won’t make your Rails app immune to bad AI-generated code. An agent can still ignore your registry, write a controller directly, and break your test suite. What skills do is raise the cost of improvisation and lower the cost of doing the right thing.

I also don’t know whether “agent skills” will become a standard Rails pattern or remain a consulting heuristic. The ecosystem is moving fast, and I’m not going to pretend I have a crystal ball. If you’re looking for a broader view on where Rails fits in the current AI landscape, my guide to AI integration in Rails covers production-grade AI integration in more depth, and my Rails MCP server post goes deeper on exposing Rails apps to agents via the official Ruby SDK (for the protocol itself, see modelcontextprotocol.io). For the library I recommend in the registry example above, see the RubyLLM documentation.

What I can say with confidence is this: Rails upgrades are hard enough without mysterious logic in app/controllers. If you’re going to let agents extend your production app, make them do it through explicit, tested, discoverable skills. Your future self running bundle update rails will thank you.

Frequently asked questions

What are agent skills in Rails?

Named, versioned interfaces that expose a slice of your business logic — an input schema, an output contract, a stable location and test coverage — so an AI agent can discover and call them instead of improvising inside app/controllers or app/models.

Are agent skills a framework or a library?

Neither, as I use the term. It is a registry pattern (a config file maps skill names to implementations and metadata) plus conventions — the mechanism can be a plain Ruby class and a Rails.application.config block.

Do I need RubyLLM to use agent skills?

No. The registry serves any consumer that can read the repo, including Claude Code, Cursor and custom CLIs. RubyLLM just makes it trivial to expose the registry as tool definitions.

Where should skills live in a Rails app?

In a stable, intentional directory outside framework-owned paths — lib/agent_skills/ or app/skills/ — excluded from casual sprawl and covered by CI.

How do skills survive Rails upgrades?

Because they are plain Ruby classes behind explicit contracts with their own tests, an upgrade changes the framework, not the skill. The registry records the Rails version each skill was last validated against, so audits are mechanical.

What is the smallest useful first step?

One skill: your most-asked discount/pricing/eligibility rule. Registry it, test it, and watch where an agent tries to go next.

Conclusion

Agent skills are a boring, versioned contract between your human workflow and whatever agent is extending the app — and that is exactly why they hold up across Rails upgrades. Start with one high-traffic skill (discount calculation is a fine pilot), registry it, test it, and let the next agent extend the app through it instead of improvising in your controllers.

If you’re building this pattern into a production Rails app, send me a short brief and book a discovery call — my AI software development work includes agent design, tool registries and guardrails. For the broader picture, see my guide to AI integration in Rails and my Rails MCP server walkthrough of the official Ruby SDK.

Keep reading