superagi 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b1109bc83d866891b9a49c0f029536824dd65895a64941e24a3b6c00e2e15f1d
4
- data.tar.gz: 815b50f3d3c237354c64b46da34f61fafec6252bcdae843d5989ba1198f10040
3
+ metadata.gz: a210eeb7bb52e127cb2b9ab235b3a483eb779dbf16bed7802fadb5eae17bc0c5
4
+ data.tar.gz: b3287833b9493ccf4d34ff90e95e47d0e11623da94d568c956ebdd26cf1d92c1
5
5
  SHA512:
6
- metadata.gz: e9a06e3bb7db1570373e08767485484b4052df9f0731a8b8f44e6bbf67528a8d217d1c0f96e6be158167f0aad9255a3c004ca3b8db405a4ca725910d4cd28a04
7
- data.tar.gz: c84e0b997d14bbe4466a8a71431d0ff400e415f6d110a88143c0f1fe64e611fa80922f95a89c8494c12f43e016435c4d2505eb3f92f3f0d9c8156b995911a02e
6
+ metadata.gz: a5e3d55aec92a571d6b88a28cc14b82beae6ddc5a44d10216e4e54d863f2141ca59aad221c6bdcc8aeea044c2acd84c1187acd1e25bd0b57ac183744252f83c8
7
+ data.tar.gz: 9cd0bab2daff3d82a80495c12fa2e2bb83b777cf7a23f76065715980486e1269c29baa48ba5b644fa906150fb18ae2c96a89dede4ac15a586ecba50fb7902c3b
data/CHANGELOG.md CHANGED
@@ -5,6 +5,21 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.3.0] - 2023-10-30
9
+
10
+ ### Added
11
+
12
+ - Add SuperAGI::Agent#pause and Agent#resume to pause and resume an agent run.
13
+ - Add SuperAGI::Agent#resources to get the output of an agent run.
14
+
15
+ ## [0.2.0] - 2023-10-28
16
+
17
+ ### Added
18
+
19
+ - Add SuperAGI::Agent#update to create a new agent.
20
+ - Add SuperAGI::Agent#run to run an agent.
21
+ - Add SuperAGI::Agent#status to get the status of an agent run.
22
+
8
23
  ## [0.1.0] - 2023-10-25
9
24
 
10
25
  ### Added
data/Gemfile CHANGED
@@ -5,7 +5,7 @@ gemspec
5
5
 
6
6
  gem "byebug", "~> 11.1.3"
7
7
  gem "dotenv", "~> 2.8.1"
8
- gem "rake", "~> 13.0"
8
+ gem "rake", "~> 13.1"
9
9
  gem "rspec", "~> 3.12"
10
10
  gem "rubocop", "~> 1.50.2"
11
11
  gem "vcr", "~> 6.1.0"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- superagi (0.1.0)
4
+ superagi (0.3.0)
5
5
  faraday (>= 1)
6
6
  faraday-multipart (>= 1)
7
7
 
@@ -32,7 +32,7 @@ GEM
32
32
  ast (~> 2.4.1)
33
33
  public_suffix (5.0.3)
34
34
  rainbow (3.1.1)
35
- rake (13.0.6)
35
+ rake (13.1.0)
36
36
  regexp_parser (2.8.0)
37
37
  rexml (3.2.6)
38
38
  rspec (3.12.0)
@@ -75,7 +75,7 @@ PLATFORMS
75
75
  DEPENDENCIES
76
76
  byebug (~> 11.1.3)
77
77
  dotenv (~> 2.8.1)
78
- rake (~> 13.0)
78
+ rake (~> 13.1)
79
79
  rspec (~> 3.12)
80
80
  rubocop (~> 1.50.2)
81
81
  superagi!
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/alexrudall/superagi/blob/main/LICENSE.txt)
5
5
  [![CircleCI Build Status](https://circleci.com/gh/alexrudall/superagi.svg?style=shield)](https://circleci.com/gh/alexrudall/superagi)
6
6
 
7
- Use the [SuperAGI API](https://superagi.com/blog/superagi-api/) with Ruby! 🦄❤️
7
+ Use the [SuperAGI API](https://superagi.com/docs/) with Ruby! 🦄❤️
8
8
 
9
9
  Create and Manage Agents in your Ruby app...
10
10
 
@@ -77,18 +77,15 @@ client = SuperAGI::Client.new(secret_key: "secret_key_goes_here")
77
77
 
78
78
  #### Custom timeout or base URI
79
79
 
80
- 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.
80
+ 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/`.
81
81
 
82
82
  ```ruby
83
83
  client = SuperAGI::Client.new(
84
84
  secret_key: "secret_key_goes_here",
85
- uri_base: "https://app.alternativeapi.com/",
85
+ uri_base: "http://superagi-backend-1:8001/",
86
86
  request_timeout: 240,
87
87
  extra_headers: {
88
- "X-Proxy-TTL" => "43200", # For https://github.com/6/superagi-caching-proxy-worker#specifying-a-cache-ttl
89
- "X-Proxy-Refresh": "true", # For https://github.com/6/superagi-caching-proxy-worker#refreshing-the-cache
90
- "Helicone-Auth": "Bearer HELICONE_API_KEY", # For https://docs.helicone.ai/getting-started/integration-method/superagi-proxy
91
- "helicone-stream-force-format" => "true", # Use this with Helicone otherwise streaming drops chunks # https://github.com/alexrudall/superagi/issues/251
88
+ "Extra-Header" => "43200",
92
89
  }
93
90
  )
94
91
  ```
@@ -98,7 +95,7 @@ or when configuring the gem:
98
95
  ```ruby
99
96
  SuperAGI.configure do |config|
100
97
  config.secret_key = ENV.fetch("SUPERAGI_SECRET_KEY")
101
- config.uri_base = "https://app.alternativeapi.com/" # Optional
98
+ config.uri_base = "http://superagi-backend-1:8001/" # Optional
102
99
  config.request_timeout = 240 # Optional
103
100
  config.extra_headers = {
104
101
  "abc" => "123",
@@ -107,6 +104,94 @@ SuperAGI.configure do |config|
107
104
  end
108
105
  ```
109
106
 
107
+ ### Create Agent
108
+
109
+ An agent is the primary entity in SuperAGI that carries out tasks. To create one:
110
+
111
+ ```ruby
112
+ response = client.agent.create(
113
+ parameters: {
114
+ name: "Motivational Quote Generator",
115
+ description: "Generates motivational quotes",
116
+ goal: ["I need a motivational quote"],
117
+ instruction: ["Write a new motivational quote"],
118
+ iteration_interval: 500,
119
+ max_iterations: 2,
120
+ constraints: [],
121
+ tools: []
122
+ })
123
+ puts response
124
+ # => {"agent_id"=>15312}
125
+ ```
126
+
127
+ ### Update Agent
128
+
129
+ To update an agent, pass the ID and 1 or more of the parameters you want to update:
130
+
131
+ ```ruby
132
+ response = client.agent.update(
133
+ id: 15312,
134
+ parameters: {
135
+ name: "Updated name",
136
+ })
137
+ puts response
138
+ # => {"agent_id"=>15312}
139
+ ```
140
+
141
+ ### Run Agent
142
+
143
+ To run an agent:
144
+
145
+ ```ruby
146
+ response = client.agent.run(id: 15312)
147
+ puts response
148
+ # => {"run_id"=>29970}
149
+ ```
150
+
151
+ ### Pause Agent
152
+
153
+ To pause an agent:
154
+
155
+ ```ruby
156
+ client.agent.run(id: 15312)
157
+ response = client.agent.pause(id: 15312)
158
+ puts response
159
+ # => {"result"=>"success"}
160
+ ```
161
+
162
+ ### Resume Agent
163
+
164
+ To resume an agent:
165
+
166
+ ```ruby
167
+ client.agent.run(id: 15312)
168
+ client.agent.pause(id: 15312)
169
+ response = client.agent.resume(id: 15312)
170
+ puts response
171
+ # => {"result"=>"success"}
172
+ ```
173
+
174
+ ### Agent Status
175
+
176
+ To get the status of Agent runs:
177
+
178
+ ```ruby
179
+ response = client.agent.status(id: 15312)
180
+ puts response
181
+ # => [{"run_id"=>29970,"status"=>"CREATED"}]
182
+ ```
183
+
184
+ ### Agent Resources
185
+
186
+ To get the resources output by Agent runs:
187
+
188
+ ```ruby
189
+ run_id = client.agent.run(id: 15312)["run_id"]
190
+ response = client.agent.resources(parameters: { run_ids: [run_id] })
191
+ puts response
192
+ # => {}
193
+ ```
194
+
110
195
  ## Development
111
196
 
112
197
  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.
@@ -1,74 +1,40 @@
1
1
  module SuperAGI
2
2
  class Agent
3
- # '{"loc":["body","constraints"],"msg":"field
4
- # required","type":"value_error.missing"},{"loc":["body","tools"],"msg":"field
5
- # required","type":"value_error.missing"},{"loc":["body","iteration_interval"],"msg":"field
6
- # required","type":"value_error.missing"},{"loc":["body","max_iterations"],"msg":"field
7
- # required","type":"value_error.missing"}]}'
3
+ include SuperAGI::AgentValidation
8
4
 
9
5
  def initialize(client:)
10
6
  @client = client
11
7
  end
12
8
 
13
9
  def create(parameters:)
14
- parameters = valid_parameters(parameters: parameters)
10
+ parameters = valid_parameters(method: :create, parameters: parameters)
15
11
  @client.json_post(path: "/agent", parameters: parameters)
16
12
  end
17
13
 
18
- # def update(id:, parameters: {})
19
- # end
20
-
21
- # def pause(id:)
22
- # end
23
-
24
- # def resume(id:)
25
- # end
26
-
27
- # def delete(id:)
28
- # end
29
-
30
- # def status(id:)
31
- # end
32
-
33
- # def resources(id:)
34
- # end
14
+ def update(id:, parameters:)
15
+ parameters = valid_parameters(method: :update, parameters: parameters)
16
+ @client.json_put(path: "/agent/#{id}", parameters: parameters)
17
+ end
35
18
 
36
- private
19
+ def run(id:)
20
+ @client.json_post(path: "/agent/#{id}/run", parameters: {})
21
+ end
37
22
 
38
- DEFAULT_PARAMETERS = {
39
- agent_workflow: "Goal Based Workflow",
40
- model: "gpt-4"
41
- }.freeze
42
- ARRAY_PARAMETERS = %w[
43
- constraints
44
- goal
45
- tools
46
- ].freeze
47
- REQUIRED_PARAMETERS = (%w[
48
- description
49
- instruction
50
- iteration_interval
51
- max_iterations
52
- name
53
- ] + ARRAY_PARAMETERS + DEFAULT_PARAMETERS.keys).freeze
23
+ def pause(id:)
24
+ @client.json_post(path: "/agent/#{id}/pause", parameters: {})
25
+ end
54
26
 
55
- def valid_parameters(parameters:)
56
- parameters = DEFAULT_PARAMETERS.merge(parameters)
57
- validate_presence(parameters: parameters)
58
- validate_arrays(parameters: parameters)
59
- parameters
27
+ def resume(id:)
28
+ @client.json_post(path: "/agent/#{id}/resume", parameters: {})
60
29
  end
61
30
 
62
- def validate_presence(parameters:)
63
- REQUIRED_PARAMETERS.each do |key|
64
- raise ArgumentError, "#{key} is required" unless parameters[key.to_sym]
65
- end
31
+ def status(id:)
32
+ @client.json_post(path: "/agent/#{id}/run-status", parameters: {})
66
33
  end
67
34
 
68
- def validate_arrays(parameters:)
69
- ARRAY_PARAMETERS.each do |key|
70
- raise ArgumentError, "#{key} must be an array" unless parameters[key.to_sym].is_a?(Array)
71
- end
35
+ def resources(parameters:)
36
+ parameters = valid_parameters(method: :resources, parameters: parameters)
37
+ @client.json_post(path: "/agent/resources/output", parameters: parameters)
72
38
  end
73
39
  end
74
40
  end
@@ -0,0 +1,70 @@
1
+ module SuperAGI
2
+ module AgentValidation
3
+ private
4
+
5
+ ARRAY_CREATE_PARAMETERS = %w[
6
+ constraints
7
+ goal
8
+ tools
9
+ ].freeze
10
+
11
+ DEFAULT_CREATE_PARAMETERS = {
12
+ agent_workflow: "Goal Based Workflow",
13
+ model: "gpt-4"
14
+ }.freeze
15
+ REQUIRED_CREATE_PARAMETERS = (%w[
16
+ description
17
+ instruction
18
+ iteration_interval
19
+ max_iterations
20
+ name
21
+ ] + ARRAY_CREATE_PARAMETERS + DEFAULT_CREATE_PARAMETERS.keys).freeze
22
+
23
+ # Update parameters need to always include any List types, even if they are empty,
24
+ # otherwise the API will return a NoneType error.
25
+ DEFAULT_UPDATE_PARAMETERS = {
26
+ constraints: [],
27
+ goal: [],
28
+ tools: []
29
+ }.freeze
30
+ REQUIRED_UPDATE_PARAMETERS = DEFAULT_UPDATE_PARAMETERS.keys.freeze
31
+
32
+ REQUIRED_RESOURCES_PARAMETERS = %w[run_ids].freeze
33
+
34
+ def valid_parameters(method:, parameters:)
35
+ parameters = default_parameters(method: method, parameters: parameters)
36
+ validate_presence(method: method, parameters: parameters)
37
+ validate_arrays(method: method, parameters: parameters)
38
+ parameters
39
+ end
40
+
41
+ def default_parameters(method:, parameters:)
42
+ case method
43
+ when :create then DEFAULT_CREATE_PARAMETERS.merge(parameters)
44
+ when :update then DEFAULT_UPDATE_PARAMETERS.merge(parameters)
45
+ else parameters
46
+ end
47
+ end
48
+
49
+ def validate_presence(method:, parameters:)
50
+ required_parameters = case method
51
+ when :create then REQUIRED_CREATE_PARAMETERS
52
+ when :update then REQUIRED_UPDATE_PARAMETERS
53
+ when :resources then REQUIRED_RESOURCES_PARAMETERS
54
+ end
55
+ required_parameters.each do |key|
56
+ raise ArgumentError, "#{key} is required" unless parameters[key.to_sym]
57
+ end
58
+ end
59
+
60
+ def validate_arrays(method:, parameters:)
61
+ array_parameters = case method
62
+ when :create, :update then ARRAY_CREATE_PARAMETERS
63
+ when :resources then REQUIRED_RESOURCES_PARAMETERS
64
+ end
65
+ array_parameters.each do |key|
66
+ raise ArgumentError, "#{key} must be an array" unless parameters[key.to_sym].is_a?(Array)
67
+ end
68
+ end
69
+ end
70
+ end
data/lib/superagi/http.rb CHANGED
@@ -13,6 +13,13 @@ module SuperAGI
13
13
  end&.body)
14
14
  end
15
15
 
16
+ def json_put(path:, parameters:)
17
+ to_json(conn.put(uri(path: path)) do |req|
18
+ req.headers = headers
19
+ req.body = parameters.to_json
20
+ end&.body)
21
+ end
22
+
16
23
  def delete(path:)
17
24
  to_json(conn.delete(uri(path: path)) do |req|
18
25
  req.headers = headers
@@ -1,3 +1,3 @@
1
1
  module SuperAGI
2
- VERSION = "0.1.0".freeze
2
+ VERSION = "0.3.0".freeze
3
3
  end
data/lib/superagi.rb CHANGED
@@ -3,6 +3,7 @@ require "faraday/multipart"
3
3
 
4
4
  require_relative "superagi/http"
5
5
  require_relative "superagi/client"
6
+ require_relative "superagi/agent_validation"
6
7
  require_relative "superagi/agent"
7
8
 
8
9
  module SuperAGI
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: superagi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-10-26 00:00:00.000000000 Z
11
+ date: 2023-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -69,6 +69,7 @@ files:
69
69
  - lib/ruby/superagi.rb
70
70
  - lib/superagi.rb
71
71
  - lib/superagi/agent.rb
72
+ - lib/superagi/agent_validation.rb
72
73
  - lib/superagi/client.rb
73
74
  - lib/superagi/compatibility.rb
74
75
  - lib/superagi/http.rb