helicone-rb 0.2.1 → 0.3.1

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: ac034e0153e6ec01bbe008066b48c58c754a103b56461fdc24c4e0d1bc05d4d4
4
- data.tar.gz: c95390c56a649b16fde96f7be81a1ef537671a19a129039d23d272ea391cfdaf
3
+ metadata.gz: 3d7fc91958e3632fb91f474bfa20a5523bf2997ab33b2b0c5222977ff8a0b2e9
4
+ data.tar.gz: 967e53e49f3e2ddd480102ae5552ce3e3074c2a8f412c7bc35aa519f74e20bad
5
5
  SHA512:
6
- metadata.gz: a4726d935f0db71a01ece1db9f29d758f2c4f47e04b79cb62ed986f1180abf6415576ccfa94e1de6e6d73671d21448c8067b1c74b6b55052195548c67533f64b
7
- data.tar.gz: 1b1b93d6cffe0e19a41dbbefec03ab019bda992c4eb7a0dfc7770c60852f7dfde8d879d634aeeec10ca75837e799919be2ecc14f9f601efbb4b63636922b43ec
6
+ metadata.gz: 70cc843edb4833e83aaee85d0af7703610f98ebff7e679e04ce5dde54419eaac22027d9c97ddccd0df55f75ff9ce1891d03686509c925ce8d7ab3fc37a2032ae
7
+ data.tar.gz: '082978063ff56855409433acc6969bb0a244d5e1a34e2050824ad76534beeaff2f9051005fa83a698a932982712929547fc5801312486a9a12bb03c12c09b459'
@@ -4,24 +4,23 @@ module Helicone
4
4
  class Agent
5
5
  MAX_ITERATIONS = 10
6
6
 
7
- attr_reader :client, :tools, :messages, :context, :turn_model, :response_model
7
+ attr_reader :client, :tools, :messages, :context, :model
8
8
 
9
9
  # Create an agent with tools and optional context
10
10
  #
11
11
  # @param client [Helicone::Client] Optional client (creates new one if not provided)
12
12
  # @param session [Hash] Session config for Helicone tracking (id:, name:) - creates client if no client provided
13
+ # @param user [Hash] User config for Helicone tracking (id:, name:) - sets Helicone-User-Id header
13
14
  # @param tools [Array<Class>] Array of Tool subclasses
14
15
  # @param context [Object] Context object passed to tool#initialize
15
16
  # @param system_prompt [String] System prompt
16
17
  # @param messages [Array<Helicone::Message>] Initial messages (for continuing conversations)
17
- # @param turn_model [String] Model for tool-calling turns (defaults to Helicone.configuration.default_model)
18
- # @param response_model [String] Model for final response (defaults to turn_model)
19
- def initialize(client: nil, session: nil, tools: [], context: nil, system_prompt: nil, messages: [], turn_model: nil, response_model: nil)
20
- @client = client || build_client(session: session)
18
+ # @param model [String] Model to use (defaults to Helicone.configuration.default_model)
19
+ def initialize(client: nil, session: nil, user: nil, tools: [], context: nil, system_prompt: nil, messages: [], model: nil)
20
+ @client = client || build_client(session: session, user: user)
21
21
  @tools = tools
22
22
  @context = context
23
- @turn_model = turn_model
24
- @response_model = response_model || turn_model
23
+ @model = model
25
24
  @messages = messages.dup
26
25
 
27
26
  # Add system message at the start if provided and not already present
@@ -40,7 +39,7 @@ module Helicone
40
39
 
41
40
  iterations = 0
42
41
  while iterations < max_iterations
43
- response = call_llm(model: @turn_model)
42
+ response = call_llm
44
43
 
45
44
  tool_calls = response.tool_calls
46
45
  if tool_calls && !tool_calls.empty?
@@ -59,17 +58,7 @@ module Helicone
59
58
 
60
59
  iterations += 1
61
60
  else
62
- # No tool calls - if response_model differs, make final call with it
63
- if @response_model && @response_model != @turn_model
64
- final_response = @client.chat(messages: @messages, model: @response_model)
65
- return AgentResult.new(
66
- content: final_response.content,
67
- messages: @messages,
68
- iterations: iterations,
69
- response: final_response
70
- )
71
- end
72
-
61
+ # No tool calls - we're done
73
62
  return AgentResult.new(
74
63
  content: response.content,
75
64
  messages: @messages,
@@ -80,7 +69,7 @@ module Helicone
80
69
  end
81
70
 
82
71
  # Max iterations reached - make one final call without tools to get a response
83
- final_response = @client.chat(messages: @messages, model: @response_model)
72
+ final_response = @client.chat(messages: @messages, model: @model)
84
73
 
85
74
  AgentResult.new(
86
75
  content: final_response.content,
@@ -106,10 +95,10 @@ module Helicone
106
95
  Helicone.configuration.logger
107
96
  end
108
97
 
109
- def call_llm(model: nil)
98
+ def call_llm
110
99
  @client.chat(
111
100
  messages: @messages,
112
- model: model,
101
+ model: @model,
113
102
  tools: tools_for_api,
114
103
  tool_choice: "auto"
115
104
  )
@@ -148,12 +137,14 @@ module Helicone
148
137
  @tools.find { |t| t.function_name == name }
149
138
  end
150
139
 
151
- def build_client(session:)
152
- return Client.new unless session
140
+ def build_client(session:, user:)
141
+ return Client.new unless session || user
153
142
 
154
143
  Client.new(
155
- session_id: session[:id],
156
- session_name: session[:name]
144
+ session_id: session&.dig(:id),
145
+ session_name: session&.dig(:name),
146
+ account_id: user&.dig(:id),
147
+ account_name: user&.dig(:name)
157
148
  )
158
149
  end
159
150
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Helicone
4
- VERSION = "0.2.1"
4
+ VERSION = "0.3.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: helicone-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Genevere