ruby-openai-swarm 0.5.1 → 0.5.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 326dc0fd2fb1f748c48c67f3f610e7dd3d14911f712e4016ab8cd13a19d6fd6e
4
- data.tar.gz: 4d12edacb8d5daa6fe863daa72a06b1f3cad8ded0c01a2c882995ac8b23e1561
3
+ metadata.gz: 2d9005515439f2abbfdc06d0817942f46a0f995762c0cdabd278f526d0d8cafa
4
+ data.tar.gz: 35d99ba8158c440803dc1d4d2579a1f025298ed14e1e44d0524149d7309f56ac
5
5
  SHA512:
6
- metadata.gz: 584b8772071a78dfdf43eb33f1e3d31c7c0b47618ffe4d766d07bfdd305781975655a8a1c7b9e9dc4f0e6dee8766881ce3e921ac063bff7a2eb6c7f4dbc1e1bf
7
- data.tar.gz: 99c9ff59009c4822397299566a19b0ac07d02d81b47ad03c1449dd7700ca3e9ed5ea62ec1d75223fb1f6ef1c27d44efe93d02717d587527c30c7b41541f2e8b5
6
+ metadata.gz: 8fbed7f9fc741e9ac0ff68aea0379244ddbfed36d9d9b1f42f40749db459a13c7e2fea90928710f243c9070aa1999197d5466caeb0a8a196f33a56b3ea65b9fb
7
+ data.tar.gz: 51eba945de062849593f0dcd49bbd98551213edab5bc2599dba2b42ceebdd8f29483606b239878fea641f3669888cf5ada02a5d003a049ed01a280f1626eca8b
@@ -28,7 +28,7 @@ module OpenAISwarm
28
28
  # )
29
29
  # end
30
30
 
31
- def get_chat_completion(agent_tracker, history, context_variables, model_override, stream, debug)
31
+ def get_chat_completion(agent_tracker, history, context_variables, model_override, stream, debug, metadata = nil)
32
32
  agent = agent_tracker.current_agent
33
33
  context_variables = context_variables.dup
34
34
  instructions = agent.instructions.respond_to?(:call) ? agent.instructions.call(context_variables) : agent.instructions
@@ -56,6 +56,14 @@ module OpenAISwarm
56
56
  tools: Util.request_tools_excluded(tools, agent_tracker.tracking_agents_tool_name, agent.strategy.prevent_agent_reentry),
57
57
  }
58
58
 
59
+ # Add metadata if provided
60
+ # Add support for LiteLLM observability with Langfuse
61
+ # See: https://docs.litellm.ai/docs/observability/langfuse_integration
62
+ if metadata && metadata.is_a?(Hash)
63
+ metadata_hash = metadata.deep_transform_values { |val| val.to_s.to_sym == :agent_name ? agent&.name : val }
64
+ create_params[:metadata] = metadata_hash
65
+ end
66
+
59
67
  # TODO: https://platform.openai.com/docs/guides/function-calling/how-do-functions-differ-from-tools
60
68
  # create_params[:functions] = tools unless tools.empty?
61
69
  # create_params[:function_call] = agent.tool_choice if agent.tool_choice
@@ -168,7 +176,7 @@ module OpenAISwarm
168
176
  partial_response
169
177
  end
170
178
 
171
- def run(agent:, messages:, context_variables: {}, model_override: nil, stream: false, debug: false, max_turns: Float::INFINITY, execute_tools: true)
179
+ def run(agent:, messages:, context_variables: {}, model_override: nil, stream: false, debug: false, max_turns: Float::INFINITY, execute_tools: true, metadata: nil)
172
180
  agent_tracker = OpenAISwarm::Agents::ChangeTracker.new(agent)
173
181
  if stream
174
182
  return run_and_stream(
@@ -178,7 +186,8 @@ module OpenAISwarm
178
186
  model_override: model_override,
179
187
  debug: debug,
180
188
  max_turns: max_turns,
181
- execute_tools: execute_tools
189
+ execute_tools: execute_tools,
190
+ metadata: metadata
182
191
  )
183
192
  end
184
193
 
@@ -197,7 +206,8 @@ module OpenAISwarm
197
206
  context_variables,
198
207
  model_override,
199
208
  stream,
200
- debug
209
+ debug,
210
+ metadata
201
211
  )
202
212
 
203
213
  message = completion.dig('choices', 0, 'message') || {}
@@ -237,7 +247,7 @@ module OpenAISwarm
237
247
  end
238
248
 
239
249
  # TODO(Grayson): a lot of copied code here that will be refactored
240
- def run_and_stream(agent:, messages:, context_variables: {}, model_override: nil, debug: false, max_turns: Float::INFINITY, execute_tools: true)
250
+ def run_and_stream(agent:, messages:, context_variables: {}, model_override: nil, debug: false, max_turns: Float::INFINITY, execute_tools: true, metadata: nil)
241
251
  agent_tracker = OpenAISwarm::Agents::ChangeTracker.new(agent)
242
252
  active_agent = agent
243
253
  context_variables = context_variables.dup
@@ -255,7 +265,8 @@ module OpenAISwarm
255
265
  context_variables,
256
266
  model_override,
257
267
  true, # stream
258
- debug
268
+ debug,
269
+ metadata
259
270
  )
260
271
 
261
272
  yield({ delim: "start" }) if block_given?
@@ -1,3 +1,3 @@
1
1
  module OpenAISwarm
2
- VERSION = "0.5.1"
2
+ VERSION = "0.5.3"
3
3
  end
@@ -15,7 +15,7 @@ require 'ruby-openai-swarm/memory'
15
15
  require 'ruby-openai-swarm/memories/entity_store'
16
16
  require 'ruby-openai-swarm/memories/core_memory_function'
17
17
  require 'ruby-openai-swarm/memories/field'
18
-
18
+ require 'active_support/core_ext/hash/deep_transform_values'
19
19
 
20
20
  module OpenAISwarm
21
21
  class Error < StandardError;
@@ -21,8 +21,9 @@ Gem::Specification.new do |spec|
21
21
  end
22
22
 
23
23
  spec.require_paths = ["lib"]
24
- spec.add_dependency "ruby-openai", "~> 7.3"
24
+ spec.add_dependency "ruby-openai", ">= 7.3", "< 9.0"
25
25
  spec.add_dependency "ostruct"
26
+ spec.add_dependency "activesupport"
26
27
  spec.add_development_dependency "rspec", "~> 3.0"
27
28
  spec.add_development_dependency "rake", "~> 13.0"
28
29
  spec.add_development_dependency "pry"
metadata CHANGED
@@ -1,29 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-openai-swarm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Grayson Chen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-03-03 00:00:00.000000000 Z
11
+ date: 2025-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-openai
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '7.3'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '9.0'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
25
28
  - !ruby/object:Gem::Version
26
29
  version: '7.3'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '9.0'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: ostruct
29
35
  requirement: !ruby/object:Gem::Requirement
@@ -38,6 +44,20 @@ dependencies:
38
44
  - - ">="
39
45
  - !ruby/object:Gem::Version
40
46
  version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: activesupport
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
41
61
  - !ruby/object:Gem::Dependency
42
62
  name: rspec
43
63
  requirement: !ruby/object:Gem::Requirement
@@ -159,7 +179,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
159
179
  - !ruby/object:Gem::Version
160
180
  version: '0'
161
181
  requirements: []
162
- rubygems_version: 3.5.3
182
+ rubygems_version: 3.1.4
163
183
  signing_key:
164
184
  specification_version: 4
165
185
  summary: A Ruby implementation of OpenAI function calling swarm