autoflux 0.4.0 → 0.5.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: 85b6aa4923d77e37e9e4c0323b9d7b4ea211d1c826b832f439ffef41fc2838a4
4
- data.tar.gz: 1f83f0a1a66cca3f03fdd0905625406e87fb5e43f9c8a8a467d4508d1fb2a450
3
+ metadata.gz: 2d8e62b48ee54fa55a2f7f86dfdbe3fee25458b0c68cefc6ad54b976414523fa
4
+ data.tar.gz: c5e255652c99c2b01dc3535219788110035b71bd71fdabcd5a97fdc52431165d
5
5
  SHA512:
6
- metadata.gz: 5014bfa1497302ff5a839f2ed914ca483af355faf5c33f6f5f543e2e3a4729a09515c58e473b6ecb2e6e03dd345a7354371728475f2fbee5998d1db514b7a465
7
- data.tar.gz: 95a4935d4ca50f9817412184781ce486b5273ba349be6441f5842f746b8f61543f849d5c3d23fb39375e02f265078e7596809d7599a4a6135d76c2b16725950b
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 a interface implements `call` method to process the command.
52
+ The agent is an object with have `#name` and `#call` methods.
53
53
 
54
54
  ```ruby
55
- agent = ->(prompt, **context) {
56
- case prompt
57
- when 'hello'
58
- 'Hello, how can I help you?'
59
- when 'bye'
60
- 'Goodbye'
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
- agent = ->(prompt, workflow:, **) {
71
- workflow.io.write("User: #{prompt}")
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.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Autoflux
4
- VERSION = "0.4.0"
4
+ VERSION = "0.5.0"
5
5
  end
@@ -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(agent:, io:, id: nil, step: Step::Start.new)
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
@@ -1,6 +1,7 @@
1
1
  module Autoflux
2
2
  # Agent implements the _Agent interface.
3
3
  interface _Agent
4
+ def name: () -> String
4
5
  def call: (String? prompt, workflow: Workflow) -> _ToS
5
6
  end
6
7
  end
@@ -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, io: _IO, ?id: String?, ?step: _Step) -> void
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 }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: autoflux
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aotokitsuruya