ruby-openai-swarm 0.3.0 → 0.3.0.1

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: 161226570a77888c84129d825b862ab7868f1d9f54b233eee7ab13950427678e
4
- data.tar.gz: e976c2a6bb9dae417b53fdc8f3f8216d3346a295b7e18838d89d24faff5612ce
3
+ metadata.gz: 98aa27742c5ae980d9c1c8b9457beb2e61a4ff3a1548790d4205cd0f68cef039
4
+ data.tar.gz: 37d7a5280f47c2a454a2aba4a5f64587787f1e829fc07b6c27accc90f63f91f8
5
5
  SHA512:
6
- metadata.gz: 65cb09238a9e1ee5fb57d2cd9e73b56d0259bafc3dc19290e449a5db75fefce0d0cf92e65a946f525c5e6571db70e813edaa11a26c436d2a3c28c3baa88bff9f
7
- data.tar.gz: d90997ebfbbf64a4d9a815510db0653e07f73f2c7b53e5d5837bcfc760589ecabeca2aba87a799b92f67c1c7c82baa3cd64c44445390e6896bae16d8a5aa67e9
6
+ metadata.gz: 0d671ef9fa72e895bfd3b3e62561fccfc3894a6f19605dd43e68da14b0c9f958d22559da8d9eecd981277a7db035ed39c17535f261cf40849f16a95ac6884516
7
+ data.tar.gz: 96c6229510613dbb8b858200916bb9ab22583b7918d604adae0b1bc85bb5b89cfae28a6c833b8c16b2acc1758d1d89643c61f240c896ff6d1d3153536801b46d
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ruby-openai-swarm (0.3.0)
4
+ ruby-openai-swarm (0.3.0.1)
5
5
  ruby-openai (~> 7.3)
6
6
 
7
7
  GEM
@@ -36,7 +36,7 @@ module OpenAISwarm
36
36
  @parallel_tool_calls = parallel_tool_calls
37
37
  @resource = resource
38
38
  @noisy_tool_calls = noisy_tool_calls
39
- @strategy = AgentStrategyOptions.new(strategy)
39
+ @strategy = Agents::StrategyOptions.new(strategy)
40
40
  end
41
41
  end
42
42
  end
@@ -0,0 +1,24 @@
1
+ module OpenAISwarm
2
+ module Agents
3
+ class ChangeTracker
4
+ attr_reader :current_agent, :previous_agent
5
+
6
+ def initialize(agent)
7
+ update(agent)
8
+ end
9
+
10
+ def update(agent)
11
+ @previous_agent = @current_agent
12
+ @current_agent = agent
13
+ end
14
+
15
+ def agent_changed?
16
+ previous_agent&.name != current_agent&.name
17
+ end
18
+
19
+ def switch_agent_reset_message?
20
+ agent_changed? && current_agent.strategy.switch_agent_reset_message
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,11 @@
1
+ module OpenAISwarm
2
+ module Agents
3
+ class StrategyOptions
4
+ attr_accessor :switch_agent_reset_message
5
+
6
+ def initialize(strategy = {})
7
+ @switch_agent_reset_message = strategy[:switch_agent_reset_message] || false
8
+ end
9
+ end
10
+ end
11
+ end
@@ -148,7 +148,7 @@ module OpenAISwarm
148
148
  end
149
149
 
150
150
  def run(agent:, messages:, context_variables: {}, model_override: nil, stream: false, debug: false, max_turns: Float::INFINITY, execute_tools: true)
151
- agent_tracker = OpenAISwarm::AgentChangeTracker.new(agent)
151
+ agent_tracker = OpenAISwarm::Agents::ChangeTracker.new(agent)
152
152
  if stream
153
153
  return run_and_stream(
154
154
  agent: agent,
@@ -168,7 +168,7 @@ module OpenAISwarm
168
168
 
169
169
  while history.length - init_len < max_turns && active_agent
170
170
  agent_tracker.update(active_agent)
171
- history = [history.first] if agent_tracker.switch_agent_reset_message?
171
+ history = OpenAISwarm::Util.latest_role_user_message(history) if agent_tracker.switch_agent_reset_message?
172
172
 
173
173
  completion = get_chat_completion(
174
174
  agent_tracker,
@@ -212,7 +212,7 @@ module OpenAISwarm
212
212
 
213
213
  # TODO(Grayson): a lot of copied code here that will be refactored
214
214
  def run_and_stream(agent:, messages:, context_variables: {}, model_override: nil, debug: false, max_turns: Float::INFINITY, execute_tools: true)
215
- agent_tracker = OpenAISwarm::AgentChangeTracker.new(agent)
215
+ agent_tracker = OpenAISwarm::Agents::ChangeTracker.new(agent)
216
216
  active_agent = agent
217
217
  context_variables = context_variables.dup
218
218
  history = messages.dup
@@ -220,7 +220,7 @@ module OpenAISwarm
220
220
 
221
221
  while history.length - init_len < max_turns && active_agent
222
222
  agent_tracker.update(active_agent)
223
- history = [history.first] if agent_tracker.switch_agent_reset_message?
223
+ history = OpenAISwarm::Util.latest_role_user_message(history) if agent_tracker.switch_agent_reset_message?
224
224
 
225
225
  message = OpenAISwarm::Util.message_template(agent.name)
226
226
  completion = get_chat_completion(
@@ -1,5 +1,13 @@
1
1
  module OpenAISwarm
2
2
  module Util
3
+ class << self
4
+ def latest_role_user_message(history)
5
+ return history if history.empty?
6
+ filtered_messages = symbolize_keys_to_string(history.dup)
7
+ last_user_message = filtered_messages.reverse.find { |msg| msg['role'] == 'user' }
8
+ last_user_message ? [last_user_message] : history
9
+ end
10
+ end
3
11
  def self.debug_print(debug, *args)
4
12
  return unless debug
5
13
  timestamp = Time.now.strftime("%Y-%m-%d %H:%M:%S")
@@ -1,3 +1,3 @@
1
1
  module OpenAISwarm
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.0.1"
3
3
  end
@@ -1,8 +1,8 @@
1
1
  require 'ruby-openai-swarm/version'
2
2
  require 'ruby-openai-swarm/core_ext'
3
3
  require 'ruby-openai-swarm/agent'
4
- require 'ruby-openai-swarm/agent_change_tracker'
5
- require 'ruby-openai-swarm/agent_strategy_options'
4
+ require 'ruby-openai-swarm/agents/change_tracker'
5
+ require 'ruby-openai-swarm/agents/strategy_options'
6
6
  require 'ruby-openai-swarm/response'
7
7
  require 'ruby-openai-swarm/result'
8
8
  require 'ruby-openai-swarm/util'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-openai-swarm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Grayson
@@ -106,8 +106,8 @@ files:
106
106
  - examples/weather_agent/run.rb
107
107
  - lib/ruby-openai-swarm.rb
108
108
  - lib/ruby-openai-swarm/agent.rb
109
- - lib/ruby-openai-swarm/agent_change_tracker.rb
110
- - lib/ruby-openai-swarm/agent_strategy_options.rb
109
+ - lib/ruby-openai-swarm/agents/change_tracker.rb
110
+ - lib/ruby-openai-swarm/agents/strategy_options.rb
111
111
  - lib/ruby-openai-swarm/configuration.rb
112
112
  - lib/ruby-openai-swarm/core.rb
113
113
  - lib/ruby-openai-swarm/core_ext.rb
@@ -1,22 +0,0 @@
1
- module OpenAISwarm
2
- class AgentChangeTracker
3
- attr_reader :current_agent, :previous_agent
4
-
5
- def initialize(agent)
6
- update(agent)
7
- end
8
-
9
- def update(agent)
10
- @previous_agent = @current_agent
11
- @current_agent = agent
12
- end
13
-
14
- def agent_changed?
15
- previous_agent&.name != current_agent&.name
16
- end
17
-
18
- def switch_agent_reset_message?
19
- agent_changed? && current_agent.strategy.switch_agent_reset_message
20
- end
21
- end
22
- end
@@ -1,9 +0,0 @@
1
- module OpenAISwarm
2
- class AgentStrategyOptions
3
- attr_accessor :switch_agent_reset_message
4
-
5
- def initialize(strategy = {})
6
- @switch_agent_reset_message = strategy[:switch_agent_reset_message] || false
7
- end
8
- end
9
- end