RubyLLM 2.2: The AI Framework for Coding Agents

RubyLLM 2.2: The AI Framework for Coding Agents

RubyLLM 2.2 is out! I released it on stage at SF Ruby, and it’s the release I’m proudest of.

The code a model writes now runs in a sandbox on your own servers, and skills and file stores build on it. Tools can ask a person and wait for the answer. A chat survives a deploy. And there are context budgets, tests without a provider, and four new providers.

It’s also the first release I built for a new kind of user: the coding agent. More and more of the code that uses RubyLLM is written by Claude Code, Codex and Cursor, so I spent as much time making RubyLLM easy for them to use as I did on features. The talk was about that, and about the idea that you don’t need frameworks anymore. I wrote the whole story up, with the benchmark: How I Optimized RubyLLM for Coding Agents.

Here’s what’s new.

Code in a Sandbox, on Your Own Servers

A model that can run code calculates exactly, reshapes your data, and makes charts, spreadsheets and PDFs. But that code was written by a model, so it should never run in your app’s process.

So I made a new gem, mxc: Microsoft’s MXC, from Ruby, and improved. It uses the operating system’s own isolation, Bubblewrap on Linux and Seatbelt on macOS, and you can bound everything: files, network, CPU time, memory. I think it’s really beautiful code:

class WorkspaceSandbox < MXC::Sandbox
  writable "storage/workspace"
  network false
  timeout 120
  limits cpu_time: 60, memory: 1.gigabyte
end

chat = RubyLLM.chat.with_code_execution(sandbox: WorkspaceSandbox, python: %w[pandas matplotlib])
chat.ask "Plot monthly revenue from this export", with: "revenue.csv"

The files the code makes come back as attachments. See Code Execution.

Skills

Some tasks need a procedure, not a sentence: how your company formats an invoice, or the script that turns a spreadsheet into slides. Skills keep them in folders, in the open format every coding agent speaks, and the model loads one only when a task needs it. With code execution, their scripts run in the sandbox.

chat = RubyLLM.chat.with_skills(:invoices).with_code_execution(python: %w[reportlab])
chat.ask "Bill order 1042 to ACME", with: "order-1042.json"

And why should we use npx skills when we have Ruby? I made the skill gem. It installs skills into your coding agent, and into your Rails app, with a skills.lock. RubyLLM ships its own skill inside the gem, so Claude Code, Codex or Cursor learn the RubyLLM way with one command:

gem exec skill add "$(bundle show ruby_llm)" --skill rubyllm --agents coding

File Stores

That 40-page PDF you attached to the first question? It used to travel with every question after it. With a file store, the model sees it once and then works with it through tools, like a coding agent does: list, search, read, write, edit.

chat = RubyLLM.chat.with_file_store
chat.ask "Which clauses changed?", with: ["contract-v1.pdf", "contract-v2.pdf"]
chat.ask "Quote the new termination clause"

With code execution, the code runs in the store’s folder, like a coding agent’s workspace, and what it writes is saved back. See File Stores.

Tools Ask a Person

Window or aisle? A tool can now ask the person running the chat, and carry on with the answer. The call pauses, no process sits there waiting, and when they answer, execute runs again from the top. So: ask first, then act.

class BookFlight < RubyLLM::Tool
  description "Books a flight"
  parameter :destination, description: "The city to fly to"

  def execute(destination:)
    seat = ask("Window or aisle?", choices: %w[window aisle]) or return "No seat chosen."
    Flights.book!(destination, seat:)
  end
end

An approval is just a question with yes and no, and MCP servers ask theirs the same way. From any process, three verbs: answer, approve, or decline with a note so the model knows why.

question = chat.pending_questions.first

question.answer "window"
question.approve remember: true
question.decline "I'll choose at the gate"

chat.complete

remember: true means your users don’t get asked again for that tool. Asking a Person has the rest.

A Chat Survives a Deploy

Chats are long-running background jobs. So what happens when you deploy in the middle of a reply?

Now a persisted chat runs in one process at a time, so a double click never runs a tool twice. If a deploy or a crash cuts off a reply, Chat.interrupted finds it, and the generated ResumeInterruptedChatsJob picks it up as soon as the server boots:

Chat.interrupted.find_each { |chat| ChatResponseJob.perform_later(chat.id) }

And a tool call that had already started never runs again. The model hears it may have partly run, and decides what to do. See Agents in Background Jobs.

Context Budgets

One giant tool result used to break the whole chat. Not anymore:

config.context_budget = { per_result: 0.25, per_request: 0.7 }

Results longer than their share get cut, and the oldest ones are left out of a request that would be too big, while keeping the prompt cache warm. New Rails apps get this line from the generator.

Tests Without a Provider

A really requested one. Script what the model says, and test your real chats, agents and pages with no provider and no API key:

stub_replies tool_call(:weather, city: "Berlin"), "It is sunny.", cost: 0.01
assert_equal "It is sunny.", SupportAgent.new.ask("Weather?").content

A Generator for Every Building Block

Agents, tools, schemas, MCP servers, skills, sandboxes, evaluations and judges:

bin/rails generate ruby_llm:mcp Linear https://mcp.linear.app/mcp
bin/rails generate ruby_llm:skill invoices "Bills an order to a customer as a PDF."
bin/rails generate ruby_llm:sandbox Workspace

And the generated chat UI now lets you switch models in the middle of a conversation, and shows a card for every question a tool asks.

Twenty-Three Providers

Moonshot AI, MiniMax, Z.ai and Meta join. That’s twenty-three providers and 518 provider features built in, each checked against the provider’s own docs. The coverage table has every one.

There’s a lot more, like queued messages, subagents and exclusive tools, in What’s New in 2.2.

Where It All Comes From

DHH didn’t design a web framework in a room. He built Basecamp and pulled out what kept working. RubyLLM comes from Chat with Work the same way. Every feature in 2.2 earned its place there first: bots that ask before they act, survive deploys, run code and work with your files.

Upgrading

bundle update ruby_llm
bin/rails generate ruby_llm:upgrade
bin/rails db:migrate

A few names changed: pending_questions replaces the separate lists of approvals and inputs, and decline replaces deny. The upgrade guide has each one.

Still on 1.16? You’re missing a lot: tool approvals, cancel, fallbacks and the cost ledger in 2.0, then a real MCP client, judgments, evaluations and OpenTelemetry in 2.1. Upgrade one release at a time.

Try it, and tell me what you find.

Newsletter