SuperAGI
Use the SuperAGI API with Ruby! 🦄❤️
Create and Manage Agents in your Ruby app...
🚢 Hire me: peaceterms.com
🎮 Ruby AI Builders Discord | 🐦 Twitter | 🤖 OpenAI Gem | 🧠 Anthropic Gem | 🚂 Midjourney Gem
Bundler
Add this line to your application's Gemfile:
gem "superagi"
And then execute:
$ bundle install
Gem install
Or install with:
$ gem install superagi
and require with:
require "superagi"
Usage
- Get your API key from https://app.superagi.com/
- Click Go to settings, API Keys, Create Key
Quickstart
For a quick test you can pass your token directly to a new client:
client = SuperAGI::Client.new(secret_key: "secret_key_goes_here")
With Config
For a more robust setup, you can configure the gem with your API keys, for example in an superagi.rb
initializer file. Never hardcode secrets into your codebase - instead use something like dotenv to pass the keys safely into your environments.
SuperAGI.configure do |config|
config.secret_key = ENV.fetch("SUPERAGI_SECRET_KEY")
end
Then you can create a client like this:
client = SuperAGI::Client.new
You can still override the config defaults when making new clients; any options not included will fall back to any global config set with SuperAGI.configure. e.g. in this example the request_timeout, etc. will fallback to any set globally using SuperAGI.configure, with only the secret_key overridden:
client = SuperAGI::Client.new(secret_key: "secret_key_goes_here")
Custom timeout or base URI
The default timeout for any request using this library is 120 seconds. You can change that by passing a number of seconds to the request_timeout
when initializing the client. You can also change the base URI used for all requests, eg. if you're running SuperAGI locally with the default docker-compose
setup you can use http://superagi-backend-1:8001/
.
client = SuperAGI::Client.new(
secret_key: "secret_key_goes_here",
uri_base: "http://superagi-backend-1:8001/",
request_timeout: 240,
extra_headers: {
"Extra-Header" => "43200",
}
)
or when configuring the gem:
SuperAGI.configure do |config|
config.secret_key = ENV.fetch("SUPERAGI_SECRET_KEY")
config.uri_base = "http://superagi-backend-1:8001/" # Optional
config.request_timeout = 240 # Optional
config.extra_headers = {
"abc" => "123",
"def": "456",
} # Optional
end
Create Agent
An agent is the primary entity in SuperAGI that carries out tasks. To create one:
response = client.agent.create(
parameters: {
name: "Motivational Quote Generator",
description: "Generates motivational quotes",
goal: ["I need a motivational quote"],
instruction: ["Write a new motivational quote"],
iteration_interval: 500,
max_iterations: 2,
constraints: [],
tools: []
})
puts response
# => {"agent_id"=>15312}
Update Agent
To update an agent, pass the ID and 1 or more of the parameters you want to update:
response = client.agent.update(
id: 15312,
parameters: {
name: "Updated name",
})
puts response
# => {"agent_id"=>15312}
Run Agent
To run an agent:
response = client.agent.run(id: 15312)
puts response
# => {"run_id"=>29970}
Pause Agent
To pause an agent:
client.agent.run(id: 15312)
response = client.agent.pause(id: 15312)
puts response
# => {"result"=>"success"}
Resume Agent
To resume an agent:
client.agent.run(id: 15312)
client.agent.pause(id: 15312)
response = client.agent.resume(id: 15312)
puts response
# => {"result"=>"success"}
Agent Status
To get the status of Agent runs:
response = client.agent.status(id: 15312)
puts response
# => [{"run_id"=>29970,"status"=>"CREATED"}]
Agent Resources
To get the resources output by Agent runs:
run_id = client.agent.run(id: 15312)["run_id"]
response = client.agent.resources(parameters: { run_ids: [run_id] })
puts response
# => {}
Development
After checking out the repo, run bin/setup
to install dependencies. You can 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
.
Warning
If you have an SUPERAGI_SECRET_KEY
in your ENV
, running the specs will use this to run the specs against the actual API, which will be slow and cost you money - 2 cents or more! Remove it from your environment with unset
or similar if you just want to run the specs against the stored VCR responses.
Release
First run the specs without VCR so they actually hit the API. This will cost 2 cents or more. Set SUPERAGI_SECRET_KEY in your environment or pass it in like this:
SUPERAGI_SECRET_KEY=123abc bundle exec rspec
Then update the version number in version.rb
, update CHANGELOG.md
, run bundle install
to update Gemfile.lock, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/alexrudall/superagi. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
License
The gem is available as open source under the terms of the MIT License.
Code of Conduct
Everyone interacting in the Ruby SuperAGI project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.