superagi 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/Gemfile.lock +1 -1
- data/README.md +59 -8
- data/lib/superagi/agent.rb +44 -25
- data/lib/superagi/http.rb +7 -0
- data/lib/superagi/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 477d9cd1d2f1dcdbdcc691730e62692e5ca732f555f7126d0814dc7e6b938f65
|
4
|
+
data.tar.gz: 38e0496835095a59ca7f825dc0125da3053f39c2bbbc5358690ad0da9f971082
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef9fa9c5e6ea03936a65dff236d338d3e7ffff9923149c86040175a0a1399b20a6e6545571765c386b21022cdb0c66baabbc42d3362a4011edc930e46279dad6
|
7
|
+
data.tar.gz: ad7df73c2df566c168c5e90eb5e3b2b1ff7a25e0b4bb681c7e8528d02d963d30087788a59c0ccca90aa5b68e8b4326f35081bfb4f91f14b2f47a66dbf3d21907
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,14 @@ 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.2.0] - 2023-10-28
|
9
|
+
|
10
|
+
### Added
|
11
|
+
|
12
|
+
- Add SuperAGI::Agent#update to create a new agent.
|
13
|
+
- Add SuperAGI::Agent#run to run an agent.
|
14
|
+
- Add SuperAGI::Agent#status to get the status of an agent run.
|
15
|
+
|
8
16
|
## [0.1.0] - 2023-10-25
|
9
17
|
|
10
18
|
### Added
|
data/Gemfile.lock
CHANGED
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/
|
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: "
|
85
|
+
uri_base: "http://superagi-backend-1:8001/",
|
86
86
|
request_timeout: 240,
|
87
87
|
extra_headers: {
|
88
|
-
"
|
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 = "
|
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,60 @@ 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
|
+
### Agent Status
|
152
|
+
|
153
|
+
To get the status of Agent runs:
|
154
|
+
|
155
|
+
```ruby
|
156
|
+
response = client.agent.status(id: 15312)
|
157
|
+
puts response
|
158
|
+
# => [{"run_id"=>29970,"status"=>"CREATED"}]
|
159
|
+
```
|
160
|
+
|
110
161
|
## Development
|
111
162
|
|
112
163
|
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.
|
data/lib/superagi/agent.rb
CHANGED
@@ -1,22 +1,22 @@
|
|
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"}]}'
|
8
|
-
|
9
3
|
def initialize(client:)
|
10
4
|
@client = client
|
11
5
|
end
|
12
6
|
|
13
7
|
def create(parameters:)
|
14
|
-
parameters = valid_parameters(parameters: parameters)
|
8
|
+
parameters = valid_parameters(method: :create, parameters: parameters)
|
15
9
|
@client.json_post(path: "/agent", parameters: parameters)
|
16
10
|
end
|
17
11
|
|
18
|
-
|
19
|
-
|
12
|
+
def update(id:, parameters:)
|
13
|
+
parameters = DEFAULT_UPDATE_PARAMETERS.merge(parameters)
|
14
|
+
@client.json_put(path: "/agent/#{id}", parameters: parameters)
|
15
|
+
end
|
16
|
+
|
17
|
+
def run(id:)
|
18
|
+
@client.json_post(path: "/agent/#{id}/run", parameters: {})
|
19
|
+
end
|
20
20
|
|
21
21
|
# def pause(id:)
|
22
22
|
# end
|
@@ -24,43 +24,62 @@ module SuperAGI
|
|
24
24
|
# def resume(id:)
|
25
25
|
# end
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
# def status(id:)
|
31
|
-
# end
|
27
|
+
def status(id:)
|
28
|
+
@client.json_post(path: "/agent/#{id}/run-status", parameters: {})
|
29
|
+
end
|
32
30
|
|
33
31
|
# def resources(id:)
|
34
32
|
# end
|
35
33
|
|
36
34
|
private
|
37
35
|
|
38
|
-
DEFAULT_PARAMETERS = {
|
39
|
-
agent_workflow: "Goal Based Workflow",
|
40
|
-
model: "gpt-4"
|
41
|
-
}.freeze
|
42
36
|
ARRAY_PARAMETERS = %w[
|
43
37
|
constraints
|
44
38
|
goal
|
45
39
|
tools
|
46
40
|
].freeze
|
47
|
-
|
41
|
+
|
42
|
+
DEFAULT_CREATE_PARAMETERS = {
|
43
|
+
agent_workflow: "Goal Based Workflow",
|
44
|
+
model: "gpt-4"
|
45
|
+
}.freeze
|
46
|
+
REQUIRED_CREATE_PARAMETERS = (%w[
|
48
47
|
description
|
49
48
|
instruction
|
50
49
|
iteration_interval
|
51
50
|
max_iterations
|
52
51
|
name
|
53
|
-
] + ARRAY_PARAMETERS +
|
52
|
+
] + ARRAY_PARAMETERS + DEFAULT_CREATE_PARAMETERS.keys).freeze
|
54
53
|
|
55
|
-
|
56
|
-
|
57
|
-
|
54
|
+
# Update parameters need to always include any List types, even if they are empty,
|
55
|
+
# otherwise the API will return a NoneType error.
|
56
|
+
DEFAULT_UPDATE_PARAMETERS = {
|
57
|
+
constraints: [],
|
58
|
+
goal: [],
|
59
|
+
tools: []
|
60
|
+
}.freeze
|
61
|
+
REQUIRED_UPDATE_PARAMETERS = DEFAULT_UPDATE_PARAMETERS.keys.freeze
|
62
|
+
|
63
|
+
def valid_parameters(method:, parameters:)
|
64
|
+
parameters = default_parameters(method: method, parameters: parameters)
|
65
|
+
validate_presence(method: method, parameters: parameters)
|
58
66
|
validate_arrays(parameters: parameters)
|
59
67
|
parameters
|
60
68
|
end
|
61
69
|
|
62
|
-
def
|
63
|
-
|
70
|
+
def default_parameters(method:, parameters:)
|
71
|
+
case method
|
72
|
+
when :create then DEFAULT_CREATE_PARAMETERS.merge(parameters)
|
73
|
+
when :update then DEFAULT_UPDATE_PARAMETERS.merge(parameters)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def validate_presence(method:, parameters:)
|
78
|
+
required_parameters = case method
|
79
|
+
when :create then REQUIRED_CREATE_PARAMETERS
|
80
|
+
when :update then REQUIRED_UPDATE_PARAMETERS
|
81
|
+
end
|
82
|
+
required_parameters.each do |key|
|
64
83
|
raise ArgumentError, "#{key} is required" unless parameters[key.to_sym]
|
65
84
|
end
|
66
85
|
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
|
data/lib/superagi/version.rb
CHANGED
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.
|
4
|
+
version: 0.2.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-
|
11
|
+
date: 2023-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|