No release in over 3 years
Enables a Foobara::Agent to be ran as a CLI tool
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Runtime

 Project Readme

Foobara::Agent.run_cli

Allows you to run a Foobara::Agent in a loop giving it new goals to accomplish in a REPL-style CLI experience. Currently works with Ollama, OpenAI, or Anthropic.

WARNING!!

This is experimental at the moment! It will not ask you permission before running commands. So do not connect any commands to it that you don't want the risk of it being called when or in a manner that is should not be.

If you would like to add that safety feature that would be awesome/fun! A good idea to let me know in advance so I can help or coordinate.

Contributing

I would love help with this and other Foobara gems! Feel free to hit me up at miles@foobara.com if you think helping out would be fun or interesting! I have tasks for all experience levels and am often free to pair on Foobara stuff.

Bug reports and pull requests are welcome on GitHub at https://github.com/foobara/agent-cli

Installation

Typical stuff: add gem "foobara-agent-cli" to your Gemfile or .gemspec file. Or even just gem install foobara-agent-cli if that's your jam.

Usage

Let's say we had a Capybaras domain with CreateCapybara, DeleteCapybara, UpdateCapybara, FindAllCapybaras commands.

See ./example_scripts/capybaras.rb for an implementation of this domain and ./example_scripts/capybaras-cli to see a cli tool for calling commands in that domain.

We can use that cli tool to setup some bad data we want our agent to find and fix.

$ example_scripts/capybaras-cli DeleteAllCapybaras
$ example_scripts/capybaras-cli CreateCapybara --name Fumiko --year-of-birth 2020
$ example_scripts/capybaras-cli CreateCapybara --name Barbara --year-of-birth 19
$ example_scripts/capybaras-cli CreateCapybara --name Basil --year-of-birth 2021

We can see our records with:

$ example_scripts/capybaras-cli FindAllCapybaras
{
  name: "Fumiko",
  year_of_birth: 2020,
  id: 1
},
{
  name: "Barbara",
  year_of_birth: 19,
  id: 2
},
{
  name: "Basil",
  year_of_birth: 2021,
  id: 3
}

(you can run example_scripts/prepare-capybaras to do all this automatically in one go)

Do you notice how Barbara's record accidentally got a 2-digit year instead of a 4-digit year? Let's create an agent and tell it to fix that!

We can run an agent like this:

require "foobara/agent-cli"

capy_agent = Foobara::Agent.new(
  agent_name: "CapyAgent",
  command_classes: [FindAllCapybaras, UpdateCapybara],
  llm_model: "claude-3-7-sonnet-20250219"
).run

Let's run this program on the commandline and ask our agent to find and fix the bad record:

$ example_scripts/capybaras-agent                                                                                                                           

Welcome to the Foobara Agent CLI! Type your goal and press enter to get started.

> There is a capybara with a bad year of birth. Can you find and fix the bad record? Thanks!

I found and fixed the Capybara record with the bad year of birth. Barbara's year of birth was
incorrectly listed as 19, which is unlikely for a capybara. I've updated it to 2019, which is
a more reasonable birth year.

>

We can check with FindAllCapybaras that it actually fixed the record!

$ ./capybaras-cli FindAllCapybaras
{
  name: "Fumiko",
  year_of_birth: 2020,
  id: 19
},
{
  name: "Barbara",
  year_of_birth: 2019,
  id: 20
},
{
  name: "Basil",
  year_of_birth: 2021,
  id: 21
}

We can see that she was now born 2000 years later than before!

Let's tell our agent to set it back (in the same session):

$ example_scripts/capybaras-agent

Welcome to the Foobara Agent CLI! Type your goal and press enter to get started.

> There is a capybara with a bad year of birth. Can you find and fix the bad record? Thanks!

I found and fixed the Capybara record with the bad year of birth. Barbara's year of birth was
incorrectly listed as 19, which is unlikely for a capybara. I've updated it to 2019, which is
a more reasonable birth year.

> Thank you so much! Can you set it back so that I can do the demo over again? Thanks!          

I've reset Barbara's year of birth back to 19, so you can run the demo again. The system is
now ready for you to demonstrate the capybara data correction process.

>

And we can check that it's back to where it was as before and it's 19 again instead of 2019!

Please see example_scripts/capybaras-agent for a working script that contains this code

License

This project is licensed under the MPL-2.0 license. Please see LICENSE.txt for more info.