AgentRuby
AgentRuby is a Ruby library that allows you to create and manage workflows using LLMs (Large Language Models). It provides a simple and intuitive interface for defining tasks, managing dependencies, and executing workflows.
Installation
Install the gem and add to the application's Gemfile by executing:
bundle add agent-ruby
If bundler is not being used to manage dependencies, install the gem by executing:
gem install agent-ruby
Usage
require 'agent-ruby'
class CreateNoteTask < AgentRuby::Task
argument :title, String
argument :content, String
argument :folder_id, Integer
def perform(title:, content:, folder_id:)
Post.create(title:, content:, folder_id:)
end
end
class CreateFolderTask < AgentRuby::Task
argument :name, String
argument :path, String
def perform(name:, path:)
Folder.create(name:, path:)
end
end
class WikiAgent < AgentRuby::Agent
action CreateNoteAction
action CreateFolderAction
end
agent = WikiAgent.new("claude-3-7-sonnet-20250219")
agent.hey(
<<~TEXT
- Create a folder named "My Documents"
- Create a post titled "My First Post" with content "Hello, world!" in the folder "My Documents"
TEXT
)
puts agent..last.content
# agent.hey("...") do |chunk|
# puts chunk
# end
Models
RubyLLM.configure do |config|
config.openai_api_key = ENV.fetch('OPENAI_API_KEY', nil)
config.anthropic_api_key = ENV.fetch('ANTHROPIC_API_KEY', nil)
config.gemini_api_key = ENV.fetch('GEMINI_API_KEY', nil)
config.deepseek_api_key = ENV.fetch('DEEPSEEK_API_KEY', nil)
config.bedrock_api_key = ENV.fetch('AWS_ACCESS_KEY_ID', nil)
config.bedrock_secret_key = ENV.fetch('AWS_SECRET_ACCESS_KEY', nil)
config.bedrock_region = ENV.fetch('AWS_REGION', nil)
config.bedrock_session_token = ENV.fetch('AWS_SESSION_TOKEN', nil)
end
Development
After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and the created tag, and push the .gem file to rubygems.org.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/moekiorg/agent-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
Code of Conduct
Everyone interacting in the He project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.