Skip to content(if available)orjump to list(if available)

Coding agent in 94 lines of Ruby

Coding agent in 94 lines of Ruby

24 comments

·May 14, 2025

rbitar

RubyLLM has been a joy to work with so nice to see it’s being used here. This project is also great and will make it easier to build an agent that can fetch data outside of the codebase for context and/or experiment with different system prompts. I’ve been a personal fan of claude code but this will be fun to work with

fullstackwife

This reminds me about PHP hello world programs which would take a string from GET, use it as a path, read a file from this path, and return the content in the response. You could make a website while not using any knowledge about websites.

Agents are the new PHP scripts!

RangerScience

This is very cool, somewhat inspiring, and (personally) very informative: I didn't actually know what "agentic" AI use was, but this did an excellent job (incidentally!) explaining it.

Might poke around...

What makes something a good potential tool, if the shell command can (technically) can do anything - like running tests?

(or it is just the things requiring user permission vs not?)

tough

> What makes something a good potential tool, if the shell command can (technically) can do anything - like running tests?

Think of it as -semantic- wrappers so the LLM can -decide- what action to take at any given moment given its context, the user prompt, and available tools names and descriptions.

creating wrappers for the most used basic tools even if they all pipe to terminal unix commands can be useful.

also giving it speicif knowledge base it can consult on demand like a wiki of its own stack etc

notpushkin

Also it’s safer than just giving unrestricted shell access to an LLM.

behnamoh

> it's only 400 lines of Ruby

also the article:

> it uses RubyLLM

(which itself is a lot more code added to 400 lines claimed by the author).

> Ruby leads to programmer happiness...

Am I the only one who finds Ruby code cryptic and less clear than JS, Python, and Rust?

As a person who's dabbled a bit in Rust and Ruby, I'm surprised people find Ruby intuitive and simple. For example:

> def execute(path:)

why the "incomplete" colon?

> module Tools

> class ListFiles < RubyLLM::Tool

what's with the "<"?

> param :command, desc: "The command to execute"

again, the colons are confusing...

nomilk

> def execute(path:)

> why the "incomplete" colon?

Just ruby's syntax to denote 'keyword arguments', i.e. when calling this method, you must explicitly use the parameter name, like so: execute(path: "/some/path")

> class ListFiles < RubyLLM::Tool

> what's with the "<"?

Just ruby's way of denoting inheritance i.e. class A < B means class A inherits from B

> param :command, desc: "The command to execute"

> again, the colons are confusing...

The colons can be confusing, but you get used to them. The first one in :command is denoting a symbol. You could think of it as just a string. Any method that expects a symbol could be rewritten to uses a string instead, but symbols are a tad more elegant (one less keypress). The second one, desc:, is a keyword argument being passed to the param method. You could rewrite it as param(:command, desc: "The command to execute")

I sometimes wonder what ruby would be like without symbols, and part of me thinks the tradeoff would be worth it (less elegant, since there'd be "strings" everywhere instead of :symbols, but it would be a bit easer to learn/read.

null

[deleted]

jeffrwells

As someone who writes a lot of Ruby and has for a long time, I have never thought the metric Ruby optimizes for is “intuitive” (I think it is, but been doing it too long / too close to it so it’s intuitive to me)

The stated optimization from Matz (who created Ruby) is “developer happiness”

The important optimization for me is “fidelity to business logic”, eg less cruft and ruby syntactic sugar means you could sit at your computer and read your business rules (in code) out loud in real time and be understood by a non-dev

null

[deleted]

tptacek

You could chuck RubyLLM and still golf it down pretty far. Nothing RubyLLM is doing is magic. Read the linked article that inspired it (which is in Go); there's even less magic there.

Some of the complaints here are just about Ruby syntax, which: shrug.

Mystery-Machine

> As a person who's dabbled a bit in Rust and Ruby

You say you "dabbled" a bit in Ruby and then proceed to demonstrate your lack of understading of basic Ruby syntax.

behnamoh

hence the word "dabbled".

BugsJustFindMe

> As a person who's dabbled a bit in Rust and Ruby, I'm surprised people find Ruby intuitive and simple

IMO it's because they mostly just don't think about the chaos they're doing. You encounter a function call that ends in a hash. Does the function being called use that as a hash or does it explode the hash to populate some extra trailing parameters? You have no way to know without going and looking. To me that's super dumb. To them it's just another day in unexpected behavior land.

jaredsohn

re: function that ends in a hash

I assume this is referring to passing hashes in as parameters to methods. Ruby 3 made this more explicit; you must use ** to convert a hash into positional arguments and you must use {} around your key/values if the first argument is a hash.

BugsJustFindMe

I'm glad the light was eventually seen after 25 years, but that's a significantly breaking change which means the update often doesn't happen. A lot of Ruby 2 codebases still exist with people still doing Ruby 2 bad behaviors.

jeffrwells

Why the us vs them mentality? How is that productive? Did people who love Ruby do something to you?

Pretty hard to grow and learn new concepts if you immediately label anything you don’t understand yet as “super dumb”

BugsJustFindMe

This isn't any new concept to learn. There are real consequences to the other people who need to read and improve the code later to not being able to form rapid linear intuition about the meaning of values being passed around programs without looking somewhere else. It's like reading a garden path sentence where the understanding of the beginning can only exist after working backwards from the end. And there's definitely a distinct dichotomy between developers who detect the discommoding and developers who don't.

Mystery-Machine

Just out of curiosity, I never understood why people do `ENV.fetch("ANTHROPIC_API_KEY", nil)` which is the equivalent of `ENV["ANTHROPIC_API_KEY"]`. I thought the whole point of calling `.fetch` was to "fail fast". Instead of assigning `nil` as default and having `NoMethodError: undefined method 'xxx' for nil` somewhere random down the line, you could fail on the actual line where a required (not optional) ENV var wasn't found. Can someone please explain?

jaredsohn

There might be code later that says that if the anthropic api key is not set, then turn off the LLM feature. Wouldn't make sense for this LLM-related code but the concept makes sense for using various APIs from dev.

null

[deleted]

paulddraper

94 lines if you import thousands of lines and connect to remote services.

Useless metric.

jeffrwells

LOC or code golf is indeed not a metric to optimize to 0, but hating on importing libraries is a bad take.

As CTO at Redo do you demand everything written in assembly? Does your entire company’s code run in one file or do you use abstraction to simplify?

I’m not quite clear on how expressing a really complex and paradigm shifting approach of agents in a more concise way is a bad thing

dismalaf

Unless you're writing a kernel from scratch, you're calling lots of code someone else wrote once upon a time...