Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/ruby-openai-swarm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
require 'ruby-openai-swarm/memories/entity_store'
require 'ruby-openai-swarm/memories/core_memory_function'
require 'ruby-openai-swarm/memories/field'

require 'active_support/core_ext/hash/deep_transform_values'

module OpenAISwarm
class Error < StandardError;
Expand Down
7 changes: 5 additions & 2 deletions lib/ruby-openai-swarm/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,11 @@ def get_chat_completion(agent_tracker, history, context_variables, model_overrid

# Add metadata if provided
# Add support for LiteLLM observability with Langfuse
# See: https://docs.litellm.ai/docs/observability/langfuse_integration
create_params[:metadata] = metadata if metadata
# See: https://docs.litellm.ai/docs/observability/langfuse_integration
if metadata && metadata.is_a?(Hash)
metadata_hash = metadata.deep_transform_values { |val| val.to_s.to_sym == :agent_name ? agent&.name : val }
create_params[:metadata] = metadata_hash
end

# TODO: https://platform.openai.com/docs/guides/function-calling/how-do-functions-differ-from-tools
# create_params[:functions] = tools unless tools.empty?
Expand Down
2 changes: 1 addition & 1 deletion lib/ruby-openai-swarm/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module OpenAISwarm
VERSION = "0.5.2"
VERSION = "0.5.3"
end
1 change: 1 addition & 0 deletions ruby-openai-swarm.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
spec.require_paths = ["lib"]
spec.add_dependency "ruby-openai", ">= 7.3", "< 9.0"
spec.add_dependency "ostruct"
spec.add_dependency "activesupport"
spec.add_development_dependency "rspec", "~> 3.0"
spec.add_development_dependency "rake", "~> 13.0"
spec.add_development_dependency "pry"
Expand Down
19 changes: 19 additions & 0 deletions spec/lib/ruby-openai-swarm/core_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,25 @@
)
end

it 'transforms var_agent_name in metadata to actual agent name' do
core = described_class.new(client)
metadata_with_var = { user_id: 123, agent_name: :agent_name }

expect(client).to receive(:chat) do |params|
expect(params[:parameters][:metadata]).to eq({
user_id: 123,
agent_name: "TestAgent"
})
chat_response
end

core.run(
agent: agent,
messages: messages,
metadata: metadata_with_var
)
end

it 'works without metadata' do
core = described_class.new(client)

Expand Down