superagi 0.2.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 +4 -4
- data/CHANGELOG.md +7 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +3 -3
- data/README.md +34 -0
- data/lib/superagi/agent.rb +12 -65
- data/lib/superagi/agent_validation.rb +70 -0
- data/lib/superagi/version.rb +1 -1
- data/lib/superagi.rb +1 -0
- metadata +3 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: a210eeb7bb52e127cb2b9ab235b3a483eb779dbf16bed7802fadb5eae17bc0c5
         | 
| 4 | 
            +
              data.tar.gz: b3287833b9493ccf4d34ff90e95e47d0e11623da94d568c956ebdd26cf1d92c1
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: a5e3d55aec92a571d6b88a28cc14b82beae6ddc5a44d10216e4e54d863f2141ca59aad221c6bdcc8aeea044c2acd84c1187acd1e25bd0b57ac183744252f83c8
         | 
| 7 | 
            +
              data.tar.gz: 9cd0bab2daff3d82a80495c12fa2e2bb83b777cf7a23f76065715980486e1269c29baa48ba5b644fa906150fb18ae2c96a89dede4ac15a586ecba50fb7902c3b
         | 
    
        data/CHANGELOG.md
    CHANGED
    
    | @@ -5,6 +5,13 @@ 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 | 
            +
             | 
| 8 15 | 
             
            ## [0.2.0] - 2023-10-28
         | 
| 9 16 |  | 
| 10 17 | 
             
            ### Added
         | 
    
        data/Gemfile
    CHANGED
    
    
    
        data/Gemfile.lock
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            PATH
         | 
| 2 2 | 
             
              remote: .
         | 
| 3 3 | 
             
              specs:
         | 
| 4 | 
            -
                superagi (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 | 
| 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. | 
| 78 | 
            +
              rake (~> 13.1)
         | 
| 79 79 | 
             
              rspec (~> 3.12)
         | 
| 80 80 | 
             
              rubocop (~> 1.50.2)
         | 
| 81 81 | 
             
              superagi!
         | 
    
        data/README.md
    CHANGED
    
    | @@ -148,6 +148,29 @@ puts response | |
| 148 148 | 
             
            # => {"run_id"=>29970}
         | 
| 149 149 | 
             
            ```
         | 
| 150 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 | 
            +
             | 
| 151 174 | 
             
            ### Agent Status
         | 
| 152 175 |  | 
| 153 176 | 
             
            To get the status of Agent runs:
         | 
| @@ -158,6 +181,17 @@ puts response | |
| 158 181 | 
             
            # => [{"run_id"=>29970,"status"=>"CREATED"}]
         | 
| 159 182 | 
             
            ```
         | 
| 160 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 | 
            +
             | 
| 161 195 | 
             
            ## Development
         | 
| 162 196 |  | 
| 163 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.
         | 
    
        data/lib/superagi/agent.rb
    CHANGED
    
    | @@ -1,5 +1,7 @@ | |
| 1 1 | 
             
            module SuperAGI
         | 
| 2 2 | 
             
              class Agent
         | 
| 3 | 
            +
                include SuperAGI::AgentValidation
         | 
| 4 | 
            +
             | 
| 3 5 | 
             
                def initialize(client:)
         | 
| 4 6 | 
             
                  @client = client
         | 
| 5 7 | 
             
                end
         | 
| @@ -10,7 +12,7 @@ module SuperAGI | |
| 10 12 | 
             
                end
         | 
| 11 13 |  | 
| 12 14 | 
             
                def update(id:, parameters:)
         | 
| 13 | 
            -
                  parameters =  | 
| 15 | 
            +
                  parameters = valid_parameters(method: :update, parameters: parameters)
         | 
| 14 16 | 
             
                  @client.json_put(path: "/agent/#{id}", parameters: parameters)
         | 
| 15 17 | 
             
                end
         | 
| 16 18 |  | 
| @@ -18,76 +20,21 @@ module SuperAGI | |
| 18 20 | 
             
                  @client.json_post(path: "/agent/#{id}/run", parameters: {})
         | 
| 19 21 | 
             
                end
         | 
| 20 22 |  | 
| 21 | 
            -
                 | 
| 22 | 
            -
             | 
| 23 | 
            -
             | 
| 24 | 
            -
                # def resume(id:)
         | 
| 25 | 
            -
                # end
         | 
| 26 | 
            -
             | 
| 27 | 
            -
                def status(id:)
         | 
| 28 | 
            -
                  @client.json_post(path: "/agent/#{id}/run-status", parameters: {})
         | 
| 29 | 
            -
                end
         | 
| 30 | 
            -
             | 
| 31 | 
            -
                # def resources(id:)
         | 
| 32 | 
            -
                # end
         | 
| 33 | 
            -
             | 
| 34 | 
            -
                private
         | 
| 35 | 
            -
             | 
| 36 | 
            -
                ARRAY_PARAMETERS = %w[
         | 
| 37 | 
            -
                  constraints
         | 
| 38 | 
            -
                  goal
         | 
| 39 | 
            -
                  tools
         | 
| 40 | 
            -
                ].freeze
         | 
| 41 | 
            -
             | 
| 42 | 
            -
                DEFAULT_CREATE_PARAMETERS = {
         | 
| 43 | 
            -
                  agent_workflow: "Goal Based Workflow",
         | 
| 44 | 
            -
                  model: "gpt-4"
         | 
| 45 | 
            -
                }.freeze
         | 
| 46 | 
            -
                REQUIRED_CREATE_PARAMETERS = (%w[
         | 
| 47 | 
            -
                  description
         | 
| 48 | 
            -
                  instruction
         | 
| 49 | 
            -
                  iteration_interval
         | 
| 50 | 
            -
                  max_iterations
         | 
| 51 | 
            -
                  name
         | 
| 52 | 
            -
                ] + ARRAY_PARAMETERS + DEFAULT_CREATE_PARAMETERS.keys).freeze
         | 
| 53 | 
            -
             | 
| 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)
         | 
| 66 | 
            -
                  validate_arrays(parameters: parameters)
         | 
| 67 | 
            -
                  parameters
         | 
| 23 | 
            +
                def pause(id:)
         | 
| 24 | 
            +
                  @client.json_post(path: "/agent/#{id}/pause", parameters: {})
         | 
| 68 25 | 
             
                end
         | 
| 69 26 |  | 
| 70 | 
            -
                def  | 
| 71 | 
            -
                   | 
| 72 | 
            -
                  when :create then DEFAULT_CREATE_PARAMETERS.merge(parameters)
         | 
| 73 | 
            -
                  when :update then DEFAULT_UPDATE_PARAMETERS.merge(parameters)
         | 
| 74 | 
            -
                  end
         | 
| 27 | 
            +
                def resume(id:)
         | 
| 28 | 
            +
                  @client.json_post(path: "/agent/#{id}/resume", parameters: {})
         | 
| 75 29 | 
             
                end
         | 
| 76 30 |  | 
| 77 | 
            -
                def  | 
| 78 | 
            -
                   | 
| 79 | 
            -
                                        when :create then REQUIRED_CREATE_PARAMETERS
         | 
| 80 | 
            -
                                        when :update then REQUIRED_UPDATE_PARAMETERS
         | 
| 81 | 
            -
                                        end
         | 
| 82 | 
            -
                  required_parameters.each do |key|
         | 
| 83 | 
            -
                    raise ArgumentError, "#{key} is required" unless parameters[key.to_sym]
         | 
| 84 | 
            -
                  end
         | 
| 31 | 
            +
                def status(id:)
         | 
| 32 | 
            +
                  @client.json_post(path: "/agent/#{id}/run-status", parameters: {})
         | 
| 85 33 | 
             
                end
         | 
| 86 34 |  | 
| 87 | 
            -
                def  | 
| 88 | 
            -
                   | 
| 89 | 
            -
             | 
| 90 | 
            -
                  end
         | 
| 35 | 
            +
                def resources(parameters:)
         | 
| 36 | 
            +
                  parameters = valid_parameters(method: :resources, parameters: parameters)
         | 
| 37 | 
            +
                  @client.json_post(path: "/agent/resources/output", parameters: parameters)
         | 
| 91 38 | 
             
                end
         | 
| 92 39 | 
             
              end
         | 
| 93 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/version.rb
    CHANGED
    
    
    
        data/lib/superagi.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.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- | 
| 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
         |