Intro to Rsmolagent

So I Made a Thing: RSmolagent for Ruby Devs Who Just Want Stuff to Work Hey folks! gkosmo here. I wanted to chat about this little library I put together called RSmolagent. It's basically just me wanting to have the cool AI agent stuff that Python devs have, but in Ruby, and without all the fuss. Why I Built This Thing Look, I'm a Ruby dev. I like Ruby. It's elegant, it's fun to write, and it just makes me happy. But lately, all the cool AI agent frameworks are in Python. You've got LangChain (which is awesome but huge), and you've got smolagent (which is nice and simple). I kept thinking: "Why can't we have something like smolagent but for Ruby?" I didn't want to switch to Python just to build AI agents, and I definitely didn't want to deal with some complex Ruby-Python bridge setup that would break in weird ways. So I did what any slightly stubborn developer would do - I built my own version. What's an "Agent" Anyway? Before I dive in, let's talk about what an "agent" is in this context. It's pretty simple: You've got an LLM (like GPT-4) You give it access to some tools (like web search, calculators, APIs) It figures out which tools to use to complete a task It uses the results from those tools to give you a final answer That's it. Nothing magical. The LLM is the brain, the tools are the hands, and RSmolagent is the nervous system connecting them. How RSmolagent Works The core idea is dead simple: # You create an LLM provider llm = RSmolagent::OpenAIProvider.new( model_id: "gpt-4", client: your_openai_client ) # You create some tools web_search = RSmolagent::Tools::WebSearchTool.new calculator = MyCalculatorTool.new # You create an agent with those tools agent = RSmolagent::Agent.new( llm_provider: llm, tools: [web_search, calculator] ) # You run the agent with a task result = agent.run("What's the population of Tokyo multiplied by 3?") Behind the scenes, the agent: Asks the LLM what to do The LLM says "I should search for Tokyo's population, then multiply it by 3" The agent executes the web search tool The agent sends the results back to the LLM The LLM says "now I need to calculate this" The agent runs the calculator tool The LLM gets the final answer It's a loop, but a pretty straightforward one. Making Your Own Tools The real fun comes when you make your own tools. Here's a dead simple example: class DadJokeTool

Mar 11, 2025 - 09:19
 0
Intro to Rsmolagent

So I Made a Thing: RSmolagent for Ruby Devs Who Just Want Stuff to Work

Hey folks! gkosmo here. I wanted to chat about this little library I put together called RSmolagent. It's basically just me wanting to have the cool AI agent stuff that Python devs have, but in Ruby, and without all the fuss.

Why I Built This Thing

Look, I'm a Ruby dev. I like Ruby. It's elegant, it's fun to write, and it just makes me happy. But lately, all the cool AI agent frameworks are in Python. You've got LangChain (which is awesome but huge), and you've got smolagent (which is nice and simple).

I kept thinking: "Why can't we have something like smolagent but for Ruby?" I didn't want to switch to Python just to build AI agents, and I definitely didn't want to deal with some complex Ruby-Python bridge setup that would break in weird ways.

So I did what any slightly stubborn developer would do - I built my own version.

What's an "Agent" Anyway?

Before I dive in, let's talk about what an "agent" is in this context. It's pretty simple:

  1. You've got an LLM (like GPT-4)
  2. You give it access to some tools (like web search, calculators, APIs)
  3. It figures out which tools to use to complete a task
  4. It uses the results from those tools to give you a final answer

That's it. Nothing magical. The LLM is the brain, the tools are the hands, and RSmolagent is the nervous system connecting them.

How RSmolagent Works

The core idea is dead simple:

# You create an LLM provider
llm = RSmolagent::OpenAIProvider.new(
  model_id: "gpt-4",
  client: your_openai_client
)

# You create some tools
web_search = RSmolagent::Tools::WebSearchTool.new
calculator = MyCalculatorTool.new

# You create an agent with those tools
agent = RSmolagent::Agent.new(
  llm_provider: llm,
  tools: [web_search, calculator]
)

# You run the agent with a task
result = agent.run("What's the population of Tokyo multiplied by 3?")

Behind the scenes, the agent:

  1. Asks the LLM what to do
  2. The LLM says "I should search for Tokyo's population, then multiply it by 3"
  3. The agent executes the web search tool
  4. The agent sends the results back to the LLM
  5. The LLM says "now I need to calculate this"
  6. The agent runs the calculator tool
  7. The LLM gets the final answer

It's a loop, but a pretty straightforward one.

Making Your Own Tools

The real fun comes when you make your own tools. Here's a dead simple example:

class DadJokeTool < RSmolagent::Tool
  def initialize
    super(
      name: "dad_joke",
      description: "Get a random dad joke",
      input_schema: {} # No inputs needed
    )
  end

  def execute(args)
    jokes = [
      "Why don't scientists trust atoms? Because they make up everything!",
      "I told my wife she was drawing her eyebrows too high. She looked surprised.",
      "What do you call a fake noodle? An impasta!"
    ]
    jokes.sample
  end
end

Now your agent can tell dad jokes. Revolutionary, I know.

But seriously, you can build tools that:

  • Query your database
  • Call your company's internal APIs
  • Control IoT devices
  • Generate images
  • Whatever else you can code in Ruby

The Code Is Stupidly Simple (By Design)

I intentionally kept the codebase tiny. There are basically four main parts:

  1. Agent - Manages the conversation loop
  2. Tool - Base class for all tools
  3. LLMProvider - Talks to language models
  4. Memory - Keeps track of conversation history

That's it. The entire thing is a few hundred lines of code. You could read the entire library in 15 minutes.

Why so simple? Because I wanted something I could understand entirely, modify easily, and not worry about mysterious bugs in some deep dependency chain.

A Real Example

Let's build something slightly more useful - a research assistant that can search the web and summarize what it finds:

require 'rsmolagent'
require 'ruby/openai'

# Set up OpenAI client
client = OpenAI::Client.new(access_token: ENV["OPENAI_API_KEY"]) 
llm = RSmolagent::OpenAIProvider.new(
  model_id: "gpt-3.5-turbo",
  client: client
)

# Create web search tool
web_search = RSmolagent::Tools::WebSearchTool.new

# Create the agent
agent = RSmolagent::Agent.new(
  llm_provider: llm,
  tools: [web_search],
  max_steps: 5
)

# Ask a research question
puts "What do you want to research?"
question = gets.chomp

puts "Researching... (this might take a bit)"
result = agent.run(question)

puts "\nHere's what I found:\n#{result}"

Just like that, you've got a research assistant. No complex setup, no weird Python dependencies, just plain Ruby.

It's Not Perfect (And That's Okay)

Look, RSmolagent isn't trying to compete with LangChain or even smolagent in terms of features. It's a minimal implementation that:

  1. Works with Ruby
  2. Is easy to understand
  3. Gets the job done

It might not have every bell and whistle, but it's a solid foundation you can build on. And since the code is so simple, extending it is straightforward.

Give It a Try

If you're a Ruby dev curious about AI agents but don't want to learn a whole new language or framework, give RSmolagent a shot. It's open source, it's simple, and it works.

Clone it, hack on it, build something cool with it. And if you improve it, send a PR! This is just the beginning.

Because at the end of the day, programming should be fun. And nothing's more fun than building a little AI assistant that can actually do useful stuff.

Catch you later,
gkosmo