Rails Agent logoRails Agent

Guide

Tool calling from Rails models

The Rails advantage for agents is direct access to application models—if tools are authorized and scoped like any other API.

Updated 2026-07-28 · Rails Agent · Tiny Bubble Company

Direct answer

Define tools that wrap existing Rails services and models so agents can look up orders, update tickets, or read account state. Keep authorization in the tool or service layer; never rely on the model alone to enforce policy.

Safe tool design

  • Pass explicit IDs from trusted context
  • Authorize the acting user or workspace
  • Return structured errors the agent can recover from
  • Prefer read tools before write tools
  • Require approvals for irreversible writes

Code shape

class OrdersTool < RailsAgents::Tool
  description "Look up an order by number for the current account"

  def call(order_number:)
    order = Current.account.orders.find_by!(number: order_number)
    { status: order.status, total: order.total_cents }
  end
end

Frequently asked questions

Should the LLM write SQL?

No. Expose curated tools. Unscoped SQL from a model is a security and reliability risk.

How does this differ from function calling demos?

Production tool calling includes auth, idempotency, tracing, and often HITL—not only a JSON schema.

Ship production Rails AI agents

Install rails-agent-stack, open /agents, and go from scaffold to deploy with Playbooks, memory, guardrails, and monitoring included.