helicone-rb 0.1.2 → 0.2.0

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: 22d855f83be3572fa91710cb1a63483ac70e07717b9a77103ca752d71931ad09
4
- data.tar.gz: 26a6eca90b9d1c9ff1cee79ae8a774da5a65fec8088c30bae1956c493242e336
3
+ metadata.gz: 5102ee7eb685c57698bb42b3a1818b1690b634a1f04fe1a2d5689c7d8b24c423
4
+ data.tar.gz: 0a37bb68ba76a4b51c8472d96d01cde87fd98df5e35d21b1d6519cb6b3991a9d
5
5
  SHA512:
6
- metadata.gz: de7718c83e259ded888212a02c63f2cac6f02eb457ded45361efa1d903a2490a0774425dccab4861da8dd40d48888ab3a156ab769dac1c8f64d42e59b427aa41
7
- data.tar.gz: 60bc8baed47ae2599f8a7f7f5ecfeca1e791b9b1ddf1123a61e99d7e2f1368254dfeef3a29d0d3941f27c1b1215fe1ac28220ce5ec74c292e610ea9c132d6763
6
+ metadata.gz: 8a801ebeb724ee8428a7c6ab73900a7dddabf1ad7524efe19391e431fc2bdb4bffe91bc9053c08c31f1e7e6398371cdcdd97437994cd4c9fec1532982e2d2f13
7
+ data.tar.gz: 2abcda0fcc478de60f6192967f9465f815d68476495b6c5988145bcbc7361b0f4dfcf8ef97a3924e09302c48c058f556bd848111eda8e8fe977ffec01dfee9f9
@@ -4,19 +4,24 @@ module Helicone
4
4
  class Agent
5
5
  MAX_ITERATIONS = 10
6
6
 
7
- attr_reader :client, :tools, :messages, :context
7
+ attr_reader :client, :tools, :messages, :context, :turn_model, :response_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
+ # @param session [Hash] Session config for Helicone tracking (id:, name:) - creates client if no client provided
12
13
  # @param tools [Array<Class>] Array of Tool subclasses
13
14
  # @param context [Object] Context object passed to tool#initialize
14
15
  # @param system_prompt [String] System prompt
15
16
  # @param messages [Array<Helicone::Message>] Initial messages (for continuing conversations)
16
- def initialize(client: nil, tools: [], context: nil, system_prompt: nil, messages: [])
17
- @client = client || Client.new
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
21
  @tools = tools
19
22
  @context = context
23
+ @turn_model = turn_model
24
+ @response_model = response_model || turn_model
20
25
  @messages = messages.dup
21
26
 
22
27
  # Add system message at the start if provided and not already present
@@ -35,7 +40,7 @@ module Helicone
35
40
 
36
41
  iterations = 0
37
42
  while iterations < max_iterations
38
- response = call_llm
43
+ response = call_llm(model: @turn_model)
39
44
 
40
45
  tool_calls = response.tool_calls
41
46
  if tool_calls && !tool_calls.empty?
@@ -54,7 +59,17 @@ module Helicone
54
59
 
55
60
  iterations += 1
56
61
  else
57
- # No tool calls - we're done
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
+
58
73
  return AgentResult.new(
59
74
  content: response.content,
60
75
  messages: @messages,
@@ -65,7 +80,7 @@ module Helicone
65
80
  end
66
81
 
67
82
  # Max iterations reached - make one final call without tools to get a response
68
- final_response = @client.chat(messages: @messages)
83
+ final_response = @client.chat(messages: @messages, model: @response_model)
69
84
 
70
85
  AgentResult.new(
71
86
  content: final_response.content,
@@ -91,9 +106,10 @@ module Helicone
91
106
  Helicone.configuration.logger
92
107
  end
93
108
 
94
- def call_llm
109
+ def call_llm(model: nil)
95
110
  @client.chat(
96
111
  messages: @messages,
112
+ model: model,
97
113
  tools: tools_for_api,
98
114
  tool_choice: "auto"
99
115
  )
@@ -130,5 +146,14 @@ module Helicone
130
146
  def find_tool_class(name)
131
147
  @tools.find { |t| t.function_name == name }
132
148
  end
149
+
150
+ def build_client(session:)
151
+ return Client.new unless session
152
+
153
+ Client.new(
154
+ session_id: session[:id],
155
+ session_name: session[:name]
156
+ )
157
+ end
133
158
  end
134
159
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Helicone
4
- VERSION = "0.1.2"
4
+ VERSION = "0.2.0"
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.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Genevere