ruby_llm-agents 0.3.3 → 0.3.4

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.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/ruby_llm/agents/dashboard_controller.rb +68 -4
  3. data/app/models/ruby_llm/agents/execution/analytics.rb +114 -13
  4. data/app/models/ruby_llm/agents/execution.rb +19 -58
  5. data/app/views/layouts/rubyllm/agents/application.html.erb +92 -350
  6. data/app/views/rubyllm/agents/agents/show.html.erb +331 -385
  7. data/app/views/rubyllm/agents/dashboard/_agent_comparison.html.erb +46 -0
  8. data/app/views/rubyllm/agents/dashboard/_budgets_bar.html.erb +0 -90
  9. data/app/views/rubyllm/agents/dashboard/_now_strip.html.erb +79 -5
  10. data/app/views/rubyllm/agents/dashboard/_top_errors.html.erb +49 -0
  11. data/app/views/rubyllm/agents/dashboard/index.html.erb +76 -121
  12. data/app/views/rubyllm/agents/executions/show.html.erb +134 -85
  13. data/app/views/rubyllm/agents/settings/show.html.erb +1 -1
  14. data/app/views/rubyllm/agents/shared/_breadcrumbs.html.erb +48 -0
  15. data/app/views/rubyllm/agents/shared/_nav_link.html.erb +27 -0
  16. data/config/routes.rb +2 -0
  17. data/lib/ruby_llm/agents/base/caching.rb +43 -0
  18. data/lib/ruby_llm/agents/base/cost_calculation.rb +103 -0
  19. data/lib/ruby_llm/agents/base/dsl.rb +261 -0
  20. data/lib/ruby_llm/agents/base/execution.rb +206 -0
  21. data/lib/ruby_llm/agents/base/reliability_execution.rb +131 -0
  22. data/lib/ruby_llm/agents/base/response_building.rb +86 -0
  23. data/lib/ruby_llm/agents/base/tool_tracking.rb +57 -0
  24. data/lib/ruby_llm/agents/base.rb +15 -805
  25. data/lib/ruby_llm/agents/version.rb +1 -1
  26. metadata +12 -20
  27. data/app/channels/ruby_llm/agents/executions_channel.rb +0 -46
  28. data/app/javascript/ruby_llm/agents/controllers/filter_controller.js +0 -56
  29. data/app/javascript/ruby_llm/agents/controllers/index.js +0 -12
  30. data/app/javascript/ruby_llm/agents/controllers/refresh_controller.js +0 -83
  31. data/app/views/rubyllm/agents/dashboard/_now_strip_values.html.erb +0 -71
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyLLM
4
+ module Agents
5
+ class Base
6
+ # Tool call tracking for agent executions
7
+ #
8
+ # Handles accumulating and serializing tool calls made during
9
+ # an agent's execution cycle.
10
+ module ToolTracking
11
+ # Resets accumulated tool calls for a new execution
12
+ #
13
+ # @return [void]
14
+ def reset_accumulated_tool_calls!
15
+ @accumulated_tool_calls = []
16
+ end
17
+
18
+ # Extracts tool calls from all assistant messages in the conversation
19
+ #
20
+ # RubyLLM handles tool call loops internally. After ask() completes,
21
+ # the conversation history contains all intermediate assistant messages
22
+ # that had tool_calls. This method extracts those tool calls.
23
+ #
24
+ # @param client [RubyLLM::Chat] The chat client with conversation history
25
+ # @return [void]
26
+ def extract_tool_calls_from_client(client)
27
+ return unless client.respond_to?(:messages)
28
+
29
+ client.messages.each do |message|
30
+ next unless message.role == :assistant
31
+ next unless message.respond_to?(:tool_calls) && message.tool_calls.present?
32
+
33
+ message.tool_calls.each_value do |tool_call|
34
+ @accumulated_tool_calls << serialize_tool_call(tool_call)
35
+ end
36
+ end
37
+ end
38
+
39
+ # Serializes a single tool call to a hash
40
+ #
41
+ # @param tool_call [Object] The tool call object
42
+ # @return [Hash] Serialized tool call
43
+ def serialize_tool_call(tool_call)
44
+ if tool_call.respond_to?(:to_h)
45
+ tool_call.to_h.transform_keys(&:to_s)
46
+ else
47
+ {
48
+ "id" => tool_call.id,
49
+ "name" => tool_call.name,
50
+ "arguments" => tool_call.arguments
51
+ }
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end