activeagents-telemetry-ruby_llm 0.3.0 → 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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 255ca4c32e9f775c8b2e45ab431ae81ee410fa3002d66dce026ba06d948da4b6
|
|
4
|
+
data.tar.gz: 1afbdf608524f69045341e10cd7a6f722854cc49977e27ff511cafcc8368fa72
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5b316442b6a5bb9044df92b691d6d4dee824d12522c45f4367d252cf7041aeee2be2060ce3a604f9b0e36b814c04e78ef5280646ad67ae7f893c29f0a1799c2b
|
|
7
|
+
data.tar.gz: 2fe33cb43e2a35659c2112decb662199b461f756e8ef63560e4e7b63151fde0fdcfa1a4f042c6f0419bead7e41787ec43ba51fdbcee58bc4cd1550014a3f56b5
|
|
@@ -43,6 +43,9 @@ module ActiveAgents
|
|
|
43
43
|
|
|
44
44
|
DEFAULT_AGENT = { name: "RubyLLM::Chat", action: "chat" }.freeze
|
|
45
45
|
|
|
46
|
+
# Span token keys and the reader that answers each on a RubyLLM 2.x +Tokens+.
|
|
47
|
+
TOKEN_READERS = { "input" => :input, "output" => :output, "thinking" => :thinking }.freeze
|
|
48
|
+
|
|
46
49
|
State = Struct.new(:depth, :started_at, :tool_spans, :rounds, :tokens, :chat_key, :agent)
|
|
47
50
|
|
|
48
51
|
class << self
|
|
@@ -306,22 +309,39 @@ module ActiveAgents
|
|
|
306
309
|
text.to_s[0, CONTENT_LIMIT]
|
|
307
310
|
end
|
|
308
311
|
|
|
312
|
+
# Tokens for one round. RubyLLM 2.x puts the round's +Tokens+ on the
|
|
313
|
+
# payload and moves the per-message readers to +message.tokens+; 1.x
|
|
314
|
+
# has +input_tokens+ and friends on each assistant message and nothing
|
|
315
|
+
# on the payload. The payload is read first, then the messages the
|
|
316
|
+
# round added, with either generation's readers.
|
|
309
317
|
def token_totals(payload)
|
|
318
|
+
tokens = payload_tokens(payload[:tokens]) || message_tokens(payload)
|
|
319
|
+
tokens["total"] = tokens.values.sum
|
|
320
|
+
tokens
|
|
321
|
+
end
|
|
322
|
+
|
|
323
|
+
def payload_tokens(tokens)
|
|
324
|
+
return unless TOKEN_READERS.values.all? { |reader| tokens.respond_to?(reader) }
|
|
325
|
+
|
|
326
|
+
TOKEN_READERS.to_h { |key, reader| [ key, tokens.public_send(reader).to_i ] }
|
|
327
|
+
end
|
|
328
|
+
|
|
329
|
+
def message_tokens(payload)
|
|
310
330
|
initial_count = Array(payload[:input_messages]).size
|
|
311
331
|
new_messages = Array(payload[:messages_after])[initial_count..] || []
|
|
312
332
|
assistant_messages = new_messages.select { |message| message.respond_to?(:role) && message.role.to_s == "assistant" }
|
|
313
333
|
|
|
314
|
-
|
|
315
|
-
"input" => sum_tokens(assistant_messages, :input_tokens),
|
|
316
|
-
"output" => sum_tokens(assistant_messages, :output_tokens),
|
|
317
|
-
"thinking" => sum_tokens(assistant_messages, :thinking_tokens)
|
|
318
|
-
}
|
|
319
|
-
tokens["total"] = tokens.values.sum
|
|
320
|
-
tokens
|
|
334
|
+
TOKEN_READERS.to_h { |key, reader| [ key, assistant_messages.sum { |message| message_token_count(message, key, reader) } ] }
|
|
321
335
|
end
|
|
322
336
|
|
|
323
|
-
|
|
324
|
-
|
|
337
|
+
# A 1.x message answers +input_tokens+; a 2.x message answers
|
|
338
|
+
# +tokens.input+.
|
|
339
|
+
def message_token_count(message, key, reader)
|
|
340
|
+
legacy_reader = :"#{key}_tokens"
|
|
341
|
+
return message.public_send(legacy_reader).to_i if message.respond_to?(legacy_reader)
|
|
342
|
+
|
|
343
|
+
tokens = message.tokens if message.respond_to?(:tokens)
|
|
344
|
+
tokens.respond_to?(reader) ? tokens.public_send(reader).to_i : 0
|
|
325
345
|
end
|
|
326
346
|
end
|
|
327
347
|
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: activeagents-telemetry-ruby_llm
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
4
|
+
version: 0.3.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- ActiveAgents
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-09-
|
|
11
|
+
date: 2026-09-21 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activeagents-telemetry
|