autoflux 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 10be8379032b489e881578406d74b7f9f0c80b480fc61b5ccf6c7e8e041f59ab
4
- data.tar.gz: d1567e48c28a48cd432c6bb4aa5c8c1856e8b920c3c8768f5c0ac4764bdc8dcc
3
+ metadata.gz: 4057f638e916ef5cca2980912c4daf1b0928cc929766156f7859ae93d2a596f6
4
+ data.tar.gz: a71fc9aaa77da24cb1c4dd9ea7dcd46b7386d640aaef737eb143d960bd1183c7
5
5
  SHA512:
6
- metadata.gz: acccc975d159aaf9d9262b2fa1cdc0a1cd2d8fc5a2bf3181121a721efe65d6731b733f7f588b0cfac30efe68d0979b14c54aca5b0bbcc0cb6a10bc8b0b38bfff
7
- data.tar.gz: 5c99079282673226f90293ec9e0ec03ac65c1a658441bdf91511aadcc01ce2aa729d6accee8b7f864aa29b69e58b8eed9f4bc63ea6bc404e0048a799e0e4e1a5
6
+ metadata.gz: 59926823b4d02b924f919f63df286be8e912e3a13921e8033ba7db333d21ff95ad0f5e4be669f604bf1bfea6c9c3ec90f4c2844375ad768c05dd835b9c9df2c6
7
+ data.tar.gz: 5ab23c20f3a229f5cc864b4814a08d8a25d3e38de97ef04c41ba77470c97ca0a9b1b297caaf86f8b01a54ef67ae69524d6b2deef91b10eb397b935879dc322ca
data/LICENSE.txt CHANGED
@@ -1,21 +1,201 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2025 Aotokitsuruya
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2025 Qiu ZhengXian
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
data/README.md CHANGED
@@ -27,12 +27,12 @@ Autoflux provides a default state machine for a chat workflow.
27
27
  ```mermaid
28
28
  stateDiagram-v2
29
29
  [*] --> Start
30
- Start --> User
31
- User --> Assistant
32
- Assistant --> User
30
+ Start --> Command
31
+ Command --> Assistant
32
+ Assistant --> Command
33
33
  Assistant --> Tool
34
34
  Tool --> Assistant
35
- User --> Stop
35
+ Command --> Stop
36
36
  Stop --> [*]
37
37
  ```
38
38
 
@@ -57,7 +57,7 @@ When receive "exit" from the user, the workflow transition to the stop state.
57
57
 
58
58
  ### Agent
59
59
 
60
- The agent is an adapter to the LLM model. You can ihnerit the `Autoflux::Agent` class to implement your own agent.
60
+ The agent is an adapter to the LLM model. You can inherit the `Autoflux::Agent` class to implement your own agent.
61
61
 
62
62
  ```ruby
63
63
  # :nodoc:
@@ -99,7 +99,7 @@ The memory is chat history which keep in the workflow. You can decide to use it
99
99
 
100
100
  ### Tool
101
101
 
102
- The tool is a function that can be used in the agent's response. You can ihnerit the `Autoflux::Tool` class to implement your own tool.
102
+ The tool is a function that can be used in the agent's response. You can inherit the `Autoflux::Tool` class to implement your own tool.
103
103
 
104
104
  ```ruby
105
105
  # :nodoc:
@@ -128,17 +128,17 @@ The tool is require the name and description. The parameters is optional.
128
128
 
129
129
  ### IO
130
130
 
131
- The IO is an adapter to the input and output. You can ihnerit the `Autoflux::IO` class to implement your own IO.
131
+ The IO is an adapter to the input and output. You can inherit the `Autoflux::IO` class to implement your own IO.
132
132
 
133
133
  ```ruby
134
134
  # :nodoc:
135
135
  class ConsoleIO < Autoflux::IO
136
- def input
136
+ def read
137
137
  print 'User: '
138
138
  gets.chomp
139
139
  end
140
140
 
141
- def output(message)
141
+ def write(message)
142
142
  puts "Assistant: #{message}"
143
143
  end
144
144
  end
data/Rakefile CHANGED
@@ -9,4 +9,10 @@ require "rubocop/rake_task"
9
9
 
10
10
  RuboCop::RakeTask.new
11
11
 
12
- task default: %i[spec rubocop]
12
+ require "steep/rake_task"
13
+ Steep::RakeTask.new do |t|
14
+ t.check.severity_level = :error
15
+ t.watch.verbose
16
+ end
17
+
18
+ task default: %i[spec rubocop steep]
data/Steepfile ADDED
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ # D = Steep::Diagnostic
4
+ #
5
+ target :lib do
6
+ check "lib"
7
+ signature "sig"
8
+ ignore_signature "sig/test"
9
+
10
+ library "securerandom"
11
+ library "json"
12
+
13
+ # configure_code_diagnostics(D::Ruby.default) # `default` diagnostics setting (applies by default)
14
+ # configure_code_diagnostics(D::Ruby.strict) # `strict` diagnostics setting
15
+ # configure_code_diagnostics(D::Ruby.lenient) # `lenient` diagnostics setting
16
+ # configure_code_diagnostics(D::Ruby.silent) # `silent` diagnostics setting
17
+ # configure_code_diagnostics do |hash| # You can setup everything yourself
18
+ # hash[D::Ruby::NoMethod] = :information
19
+ # end
20
+ end
21
+
22
+ # target :test do
23
+ # unreferenced! # Skip type checking the `lib` code when types in `test` target is changed
24
+ # signature "sig/test" # Put RBS files for tests under `sig/test`
25
+ # check "test" # Type check Ruby scripts under `test`
26
+ #
27
+ # configure_code_diagnostics(D::Ruby.lenient) # Weak type checking for test code
28
+ #
29
+ # # library "pathname" # Standard libraries
30
+ # end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Autoflux
4
+ module Step
5
+ # The Assistant state is used to call the agent.
6
+ class Assistant < Base
7
+ OUTPUT_ROLE_NAME = "assistant"
8
+
9
+ def call(workflow:)
10
+ res = workflow.agent.call(memory: workflow.memory)
11
+ workflow.memory.push(res)
12
+ return Tool.new if res["tool_calls"]&.any?
13
+
14
+ workflow.io.write(res["content"]) if res["role"] == OUTPUT_ROLE_NAME
15
+
16
+ Command.new
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Autoflux
4
+ module Step
5
+ # The Step::Base is abstract class to represent the interface of the state
6
+ class Base
7
+ # @rbs workflow: Workflow
8
+ def call(**)
9
+ raise NotImplementedError
10
+ end
11
+
12
+ def name
13
+ self.class.name || "Step"
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Autoflux
4
+ module Step
5
+ # The Command step is used to get the user input.
6
+ class Command < Base
7
+ EXIT_COMMAND = "exit"
8
+
9
+ def call(workflow:)
10
+ input = workflow.io.read
11
+ return Stop.new if input == EXIT_COMMAND
12
+
13
+ workflow.memory.push(role: :user, content: input)
14
+ Assistant.new
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Autoflux
4
+ module Step
5
+ # The Start step is used to start the workflow.
6
+ class Start < Base
7
+ def call(**) = Command.new
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Autoflux
4
+ module Step
5
+ # The Stop step is used to stop the workflow.
6
+ class Stop < Base
7
+ def call(**) = nil
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Autoflux
4
+ module Step
5
+ # The Tool state is used to call the tools provided by the agent.
6
+ class Tool < Base
7
+ def call(workflow:)
8
+ workflow.memory.last["tool_calls"]&.each do |tool|
9
+ workflow.memory.push(
10
+ role: :tool,
11
+ content: run(workflow: workflow, tool: tool).to_json,
12
+ tool_call_id: tool["id"]
13
+ )
14
+ end
15
+
16
+ Assistant.new
17
+ end
18
+
19
+ protected
20
+
21
+ def run(workflow:, tool:)
22
+ name = tool.dig("function", "name")
23
+ params = JSON.parse(tool.dig("function", "arguments"), symbolize_names: true)
24
+ return { status: "error", message: "Tool not found" } unless workflow.agent.tool?(name)
25
+
26
+ workflow.agent.tool(name).call(**params) # steep:ignore
27
+ rescue JSON::ParserError
28
+ { status: "error", message: "Invalid arguments" }
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Autoflux
4
+ # The Step means a state in the workflow
5
+ module Step
6
+ require "autoflux/step/base"
7
+ require "autoflux/step/start"
8
+ require "autoflux/step/stop"
9
+ require "autoflux/step/command"
10
+ require "autoflux/step/assistant"
11
+ require "autoflux/step/tool"
12
+ end
13
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Autoflux
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
@@ -1,15 +1,29 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "securerandom"
4
+
3
5
  module Autoflux
4
6
  # The workflow is a state machine to manage the flow of agentic AI.
5
7
  class Workflow
6
- attr_reader :agent, :state, :memory, :io
8
+ class << self
9
+ # Generate a random UUID.
10
+ #
11
+ # @return [String]
12
+ def next_id
13
+ return SecureRandom.uuid_v7 if RUBY_VERSION >= "3.3" # steep:ignore
14
+
15
+ SecureRandom.uuid
16
+ end
17
+ end
18
+
19
+ attr_reader :id, :agent, :memory, :io
7
20
 
8
21
  # @rbs state: State
9
- def initialize(agent:, io:, state: Start.new, memory: Memory.new)
22
+ def initialize(agent:, io:, id: nil, step: Step::Start.new, memory: Memory.new)
23
+ @id = id || Workflow.next_id
10
24
  @agent = agent
11
25
  @io = io
12
- @state = state
26
+ @step = step
13
27
  @memory = memory
14
28
  end
15
29
 
@@ -18,7 +32,27 @@ module Autoflux
18
32
  # @rbs system_prompt: String?
19
33
  def run(system_prompt: nil)
20
34
  memory.push(role: :system, content: system_prompt) unless system_prompt.nil?
21
- @state = @state.call(workflow: self) until @state.nil?
35
+ @step = step.call(workflow: self) while @step
36
+ end
37
+
38
+ # Stop the workflow.
39
+ def stop
40
+ @step = Step::Stop.new
41
+ end
42
+
43
+ # Get the current step. If the step is nil, return a Stop step.
44
+ def step
45
+ @step || Step::Stop.new
46
+ end
47
+
48
+ # Get the hash representation of the workflow.
49
+ #
50
+ # @return [Hash]
51
+ def to_h
52
+ {
53
+ id: id,
54
+ step: step.name
55
+ }
22
56
  end
23
57
  end
24
58
  end
data/lib/autoflux.rb CHANGED
@@ -10,11 +10,6 @@ module Autoflux
10
10
  require_relative "autoflux/agent"
11
11
  require_relative "autoflux/io"
12
12
  require_relative "autoflux/memory"
13
- require_relative "autoflux/state"
14
- require_relative "autoflux/start"
15
- require_relative "autoflux/user"
16
- require_relative "autoflux/assistant"
17
- require_relative "autoflux/tools"
18
- require_relative "autoflux/stop"
13
+ require_relative "autoflux/step"
19
14
  require_relative "autoflux/workflow"
20
15
  end
@@ -0,0 +1,16 @@
1
+ module Autoflux
2
+ # Agent implements the _Agent interface.
3
+ interface _Agent
4
+ def tool?: (String name) -> bool
5
+ def tool: (String name) -> _Tool?
6
+ def call: (memory: _Memory) -> untyped
7
+ end
8
+
9
+ # The Agent is a abstract class to represent the adapter of the Language Model.
10
+ class Agent
11
+ include _Agent
12
+
13
+ @_tools: Array[_Tool]
14
+ def initialize: (?tools: Array[_Tool]?) -> void
15
+ end
16
+ end
@@ -0,0 +1,11 @@
1
+ module Autoflux
2
+ interface _IO
3
+ def read: () -> String
4
+ def write: (String data) -> String
5
+ end
6
+
7
+ # The IO is abstract class to represent the interface of the IO
8
+ class IO
9
+ include _IO
10
+ end
11
+ end
@@ -0,0 +1,20 @@
1
+ module Autoflux
2
+ interface _Memory
3
+ def data: () -> Array[untyped]
4
+ def push: (untyped data) -> untyped
5
+ def last: () -> untyped
6
+ end
7
+
8
+ # The Memory is a class to store the memory of the workflow.
9
+ class Memory
10
+ include _Memory
11
+
12
+ @data: Array[untyped]
13
+ @verbose: bool
14
+
15
+ attr_reader verbose: bool
16
+
17
+ # @rbs data: Array[Hash]
18
+ def initialize: (?data: Array[untyped], ?verbose: bool) -> void
19
+ end
20
+ end
@@ -0,0 +1,21 @@
1
+ module Autoflux
2
+ # The Stdio is a class to represent the standard input/output.
3
+ class Stdio < IO
4
+ @input: untyped
5
+
6
+ @output: untyped
7
+
8
+ @prompt: untyped
9
+
10
+ attr_accessor prompt: untyped
11
+
12
+ # @rbs input: IO
13
+ # @rbs output: IO
14
+ def initialize: (?input: untyped, ?output: untyped, ?prompt: untyped?) -> void
15
+
16
+ def read: () -> untyped
17
+
18
+ # @rbs data: String
19
+ def write: (untyped data) -> untyped
20
+ end
21
+ end
@@ -0,0 +1,36 @@
1
+ module Autoflux
2
+ interface _Step
3
+ def name: () -> String
4
+ def call: (workflow: Workflow) -> untyped
5
+ end
6
+
7
+ module Step
8
+ # The Step::Base is abstract class to represent the interface of the state
9
+ class Base
10
+ include Autoflux::_Step
11
+ end
12
+
13
+ # The Start step is used to start the workflow.
14
+ class Start < Base
15
+ end
16
+
17
+ # The Stop step is used to stop the workflow.
18
+ class Stop < Base
19
+ end
20
+
21
+ # The Assistant state is used to call the agent.
22
+ class Assistant < Base
23
+ OUTPUT_ROLE_NAME: "assistant"
24
+ end
25
+
26
+ # The Tool state is used to call the tools provided by the agent.
27
+ class Tool < Base
28
+ def run: (workflow: Workflow, tool: untyped) -> untyped
29
+ end
30
+
31
+ # The Command step is used to get the user input.
32
+ class Command < Base
33
+ EXIT_COMMAND: "exit"
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,20 @@
1
+ module Autoflux
2
+ interface _Tool
3
+ def name: () -> String
4
+ def description: () -> String
5
+ def parameters: () -> untyped
6
+
7
+ def call: (**untyped) -> untyped
8
+ end
9
+
10
+ # The Tool is a abstract class to represent the adapter of tools which can be used by the Language Model.
11
+ class Tool
12
+ include _Tool
13
+
14
+ @name: String
15
+ @description: String
16
+ @parameters: untyped
17
+
18
+ def initialize: (name: String, description: String, ?parameters: untyped?) -> void
19
+ end
20
+ end
@@ -0,0 +1,39 @@
1
+ module Autoflux
2
+ # The workflow is a state machine to manage the flow of agentic AI.
3
+ class Workflow
4
+ @id: String
5
+ @agent: _Agent
6
+ @io: _IO
7
+ @step: _Step
8
+ @memory: _Memory
9
+
10
+ # Generate a random UUID.
11
+ #
12
+ # @return [String]
13
+ def self.next_id: () -> String
14
+
15
+ attr_reader id: String
16
+ attr_reader agent: _Agent
17
+ attr_reader memory: _Memory
18
+ attr_reader io: _IO
19
+
20
+ # @rbs state: State
21
+ def initialize: (agent: _Agent, io: _IO, ?id: String?, ?step: _Step, ?memory: _Memory) -> void
22
+
23
+ # Run the workflow.
24
+ #
25
+ # @rbs system_prompt: String?
26
+ def run: (?system_prompt: String?) -> void
27
+
28
+ # Stop the workflow.
29
+ def stop: () -> void
30
+
31
+ # Get the current step. If the step is nil, return a Stop step.
32
+ def step: () -> _Step
33
+
34
+ # Get the hash representation of the workflow.
35
+ #
36
+ # @return [Hash]
37
+ def to_h: () -> { id: String, step: String }
38
+ end
39
+ end
data/sig/autoflux.rbs CHANGED
@@ -1,4 +1,6 @@
1
1
  module Autoflux
2
2
  VERSION: String
3
- # See the writing guide of rbs: https://github.com/ruby/rbs#guides
3
+
4
+ class Error < StandardError
5
+ end
4
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: autoflux
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aotokitsuruya
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-01-05 00:00:00.000000000 Z
11
+ date: 2025-01-06 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A lightweight AI agent framework for Ruby
14
14
  email:
@@ -24,24 +24,33 @@ files:
24
24
  - LICENSE.txt
25
25
  - README.md
26
26
  - Rakefile
27
+ - Steepfile
27
28
  - commitlint.config.js
28
29
  - lib/autoflux.rb
29
30
  - lib/autoflux/agent.rb
30
- - lib/autoflux/assistant.rb
31
31
  - lib/autoflux/io.rb
32
32
  - lib/autoflux/memory.rb
33
- - lib/autoflux/start.rb
34
- - lib/autoflux/state.rb
35
33
  - lib/autoflux/stdio.rb
36
- - lib/autoflux/stop.rb
34
+ - lib/autoflux/step.rb
35
+ - lib/autoflux/step/assistant.rb
36
+ - lib/autoflux/step/base.rb
37
+ - lib/autoflux/step/command.rb
38
+ - lib/autoflux/step/start.rb
39
+ - lib/autoflux/step/stop.rb
40
+ - lib/autoflux/step/tool.rb
37
41
  - lib/autoflux/tool.rb
38
- - lib/autoflux/tools.rb
39
- - lib/autoflux/user.rb
40
42
  - lib/autoflux/version.rb
41
43
  - lib/autoflux/workflow.rb
42
44
  - package-lock.json
43
45
  - package.json
44
46
  - sig/autoflux.rbs
47
+ - sig/autoflux/agent.rbs
48
+ - sig/autoflux/io.rbs
49
+ - sig/autoflux/memory.rbs
50
+ - sig/autoflux/stdio.rbs
51
+ - sig/autoflux/step.rbs
52
+ - sig/autoflux/tool.rbs
53
+ - sig/autoflux/workflow.rbs
45
54
  homepage: https://github.com/elct9620/autoflux
46
55
  licenses:
47
56
  - Apache-2.0
@@ -64,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
64
73
  - !ruby/object:Gem::Version
65
74
  version: '0'
66
75
  requirements: []
67
- rubygems_version: 3.5.9
76
+ rubygems_version: 3.5.22
68
77
  signing_key:
69
78
  specification_version: 4
70
79
  summary: A lightweight AI agent framework
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Autoflux
4
- # The Assistant state is used to call the agent.
5
- class Assistant
6
- OUTPUT_ROLE_NAME = "assistant"
7
-
8
- def call(workflow:)
9
- res = workflow.agent.call(memory: workflow.memory)
10
- workflow.memory.push(res)
11
- return Tools.new if res["tool_calls"]&.any?
12
-
13
- workflow.io.write(res["content"]) if res["role"] == OUTPUT_ROLE_NAME
14
-
15
- User.new
16
- end
17
- end
18
- end
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Autoflux
4
- # The Start state is used to start the workflow.
5
- class Start < State
6
- def call(**) = User.new
7
- end
8
- end
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Autoflux
4
- # The State is abstract class to represent the interface of the state
5
- class State
6
- # @rbs workflow: Workflow
7
- def call(**)
8
- raise NotImplementedError
9
- end
10
- end
11
- end
data/lib/autoflux/stop.rb DELETED
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Autoflux
4
- # The Stop state is used to stop the workflow.
5
- class Stop < State
6
- def call(**) = nil
7
- end
8
- end
@@ -1,30 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Autoflux
4
- # The Tools state is used to call the tools provided by the agent.
5
- class Tools
6
- def call(workflow:)
7
- workflow.memory.last["tool_calls"]&.each do |tool|
8
- workflow.memory.push(
9
- role: :tool,
10
- content: run(workflow: workflow, tool: tool).to_json,
11
- tool_call_id: tool["id"]
12
- )
13
- end
14
-
15
- Assistant.new
16
- end
17
-
18
- protected
19
-
20
- def run(workflow:, tool:)
21
- name = tool.dig("function", "name")
22
- params = JSON.parse(tool.dig("function", "arguments"), symbolize_names: true)
23
- return { status: "error", message: "Tool not found" } unless workflow.agent.tool?(name)
24
-
25
- workflow.agent.tool(name).call(**params)
26
- rescue JSON::ParserError
27
- { status: "error", message: "Invalid arguments" }
28
- end
29
- end
30
- end
data/lib/autoflux/user.rb DELETED
@@ -1,17 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Autoflux
4
- # The User state is used to get the user input.
5
- class User
6
- EXIT_COMMAND = "exit"
7
-
8
- def call(workflow:)
9
- input = workflow.io.read
10
- return Stop.new if input == EXIT_COMMAND
11
-
12
- workflow.memory.push(role: :user, content: input)
13
-
14
- Assistant.new
15
- end
16
- end
17
- end