autoflux 0.4.0 → 0.5.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/README.md +31 -14
- data/lib/autoflux/version.rb +1 -1
- data/lib/autoflux/workflow.rb +15 -3
- data/sig/autoflux/agent.rbs +1 -0
- data/sig/autoflux/workflow.rbs +4 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2d8e62b48ee54fa55a2f7f86dfdbe3fee25458b0c68cefc6ad54b976414523fa
|
4
|
+
data.tar.gz: c5e255652c99c2b01dc3535219788110035b71bd71fdabcd5a97fdc52431165d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f176ff0cdd42e11b03f2137102482fd7de9401a1b389b896616f878c0e670c4e6dc74e81fc8126a21b5350468658cb47dc547785743f1004337d7b3949637b73
|
7
|
+
data.tar.gz: 7ec3e5dd178cb03687d396e9194c471a2c97bbee1e88ba97d3ed674410120f8d5b6418b35187f1c7fc1a1ca115738891e45c9af77df648b49fd2f7c6e767b393
|
data/README.md
CHANGED
@@ -49,31 +49,48 @@ When the `io` is `EOF`, the workflow will stop.
|
|
49
49
|
|
50
50
|
### Agent
|
51
51
|
|
52
|
-
The agent is
|
52
|
+
The agent is an object with have `#name` and `#call` methods.
|
53
53
|
|
54
54
|
```ruby
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
else
|
62
|
-
'I do not understand'
|
63
|
-
end
|
64
|
-
}
|
55
|
+
require 'autoflux/openai'
|
56
|
+
|
57
|
+
agent = Autoflux::OpenAI.new(
|
58
|
+
name: "chat",
|
59
|
+
model: "gpt-4o-mini"
|
60
|
+
)
|
65
61
|
```
|
66
62
|
|
67
63
|
The workflow will pass itself as context to the agent.
|
68
64
|
|
69
65
|
```ruby
|
70
|
-
|
71
|
-
|
72
|
-
|
66
|
+
class MyAgent
|
67
|
+
attr_reader :name
|
68
|
+
|
69
|
+
def initialize(name:)
|
70
|
+
@name = name
|
71
|
+
end
|
72
|
+
|
73
|
+
def call(params, workflow:)
|
74
|
+
workflow.io.write("Hello, #{params[:name]}!")
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
73
78
|
```
|
74
79
|
|
75
80
|
Workflow never knows the how the agent works and which tool is used.
|
76
81
|
|
82
|
+
The agent can switch by workflow if the workflow knows it. You can use it in the agent's tool to switch the agent.
|
83
|
+
|
84
|
+
```ruby
|
85
|
+
workflow = Autoflux::Workflow.new(
|
86
|
+
agent: agent1, # if not given the first agent in `agents` will be used
|
87
|
+
agents: [agent1, agent2],
|
88
|
+
io: io,
|
89
|
+
)
|
90
|
+
|
91
|
+
workflow.switch_agent("agent2")
|
92
|
+
```
|
93
|
+
|
77
94
|
### IO
|
78
95
|
|
79
96
|
The IO is an adapter to let the workflow interact with the user.
|
data/lib/autoflux/version.rb
CHANGED
data/lib/autoflux/workflow.rb
CHANGED
@@ -18,14 +18,17 @@ module Autoflux
|
|
18
18
|
|
19
19
|
include Enumerable
|
20
20
|
|
21
|
-
attr_reader :id, :agent, :io
|
21
|
+
attr_reader :id, :agent, :io, :agents
|
22
22
|
|
23
23
|
# @rbs state: State
|
24
|
-
def initialize(
|
24
|
+
def initialize(io:, agent: nil, agents: [], id: nil, step: Step::Start.new)
|
25
25
|
@id = id || Workflow.next_id
|
26
|
-
@agent = agent
|
26
|
+
@agent = agent || agents.first
|
27
|
+
@agents = agents
|
27
28
|
@io = io
|
28
29
|
@step = step
|
30
|
+
|
31
|
+
raise Error, "No agent provided" unless @agent
|
29
32
|
end
|
30
33
|
|
31
34
|
def each
|
@@ -44,6 +47,15 @@ module Autoflux
|
|
44
47
|
each(&block || ->(_workflow) {})
|
45
48
|
end
|
46
49
|
|
50
|
+
# Switch the agent.
|
51
|
+
def switch_agent(name)
|
52
|
+
new_agent = agents.find { |agent| agent.name == name }
|
53
|
+
return false unless new_agent
|
54
|
+
|
55
|
+
@agent = new_agent
|
56
|
+
true
|
57
|
+
end
|
58
|
+
|
47
59
|
# Stop the workflow.
|
48
60
|
def stop
|
49
61
|
@step = Step::Stop.new
|
data/sig/autoflux/agent.rbs
CHANGED
data/sig/autoflux/workflow.rbs
CHANGED
@@ -5,6 +5,7 @@ module Autoflux
|
|
5
5
|
|
6
6
|
@id: String
|
7
7
|
@agent: _Agent
|
8
|
+
@agents: Array[_Agent]
|
8
9
|
@io: _IO
|
9
10
|
@step: _Step
|
10
11
|
|
@@ -12,11 +13,13 @@ module Autoflux
|
|
12
13
|
|
13
14
|
attr_reader id: String
|
14
15
|
attr_reader agent: _Agent
|
16
|
+
attr_reader agents: Array[_Agent]
|
15
17
|
attr_reader io: _IO
|
16
18
|
|
17
|
-
def initialize: (agent: _Agent,
|
19
|
+
def initialize: (io: _IO, ?agent: _Agent, ?agents: Array[_Agent], ?id: String?, ?step: _Step) -> void
|
18
20
|
def each: { (Workflow) -> void } -> void
|
19
21
|
def run: () ?{ (Workflow) -> void } -> void
|
22
|
+
def switch_agent: (String name) -> bool
|
20
23
|
def stop: () -> void
|
21
24
|
def step: () -> _Step
|
22
25
|
def to_h: () -> { id: String, step: String }
|