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 +4 -4
- data/lib/helicone/agent.rb +17 -26
- data/lib/helicone/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3d7fc91958e3632fb91f474bfa20a5523bf2997ab33b2b0c5222977ff8a0b2e9
|
|
4
|
+
data.tar.gz: 967e53e49f3e2ddd480102ae5552ce3e3074c2a8f412c7bc35aa519f74e20bad
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 70cc843edb4833e83aaee85d0af7703610f98ebff7e679e04ce5dde54419eaac22027d9c97ddccd0df55f75ff9ce1891d03686509c925ce8d7ab3fc37a2032ae
|
|
7
|
+
data.tar.gz: '082978063ff56855409433acc6969bb0a244d5e1a34e2050824ad76534beeaff2f9051005fa83a698a932982712929547fc5801312486a9a12bb03c12c09b459'
|
data/lib/helicone/agent.rb
CHANGED
|
@@ -4,24 +4,23 @@ 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, :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
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
@
|
|
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
|
|
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 -
|
|
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: @
|
|
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
|
|
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
|
|
156
|
-
session_name: session
|
|
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
|
data/lib/helicone/version.rb
CHANGED