ruby_llm-agents 0.4.0 → 1.0.0.beta.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.
Files changed (208) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +225 -34
  3. data/app/controllers/ruby_llm/agents/agents_controller.rb +136 -16
  4. data/app/controllers/ruby_llm/agents/api_configurations_controller.rb +214 -0
  5. data/app/controllers/ruby_llm/agents/dashboard_controller.rb +29 -9
  6. data/app/controllers/ruby_llm/agents/{settings_controller.rb → system_config_controller.rb} +3 -3
  7. data/app/controllers/ruby_llm/agents/tenants_controller.rb +109 -0
  8. data/app/controllers/ruby_llm/agents/workflows_controller.rb +355 -0
  9. data/app/helpers/ruby_llm/agents/application_helper.rb +25 -0
  10. data/app/models/ruby_llm/agents/api_configuration.rb +386 -0
  11. data/app/models/ruby_llm/agents/execution.rb +3 -0
  12. data/app/models/ruby_llm/agents/tenant_budget.rb +112 -14
  13. data/app/services/ruby_llm/agents/agent_registry.rb +51 -12
  14. data/app/views/layouts/ruby_llm/agents/application.html.erb +5 -30
  15. data/app/views/ruby_llm/agents/agents/_agent.html.erb +13 -1
  16. data/app/views/ruby_llm/agents/agents/_config_agent.html.erb +235 -0
  17. data/app/views/ruby_llm/agents/agents/_config_embedder.html.erb +70 -0
  18. data/app/views/ruby_llm/agents/agents/_config_image_generator.html.erb +152 -0
  19. data/app/views/ruby_llm/agents/agents/_config_moderator.html.erb +63 -0
  20. data/app/views/ruby_llm/agents/agents/_config_speaker.html.erb +108 -0
  21. data/app/views/ruby_llm/agents/agents/_config_transcriber.html.erb +91 -0
  22. data/app/views/ruby_llm/agents/agents/_workflow.html.erb +1 -1
  23. data/app/views/ruby_llm/agents/agents/index.html.erb +74 -9
  24. data/app/views/ruby_llm/agents/agents/show.html.erb +18 -378
  25. data/app/views/ruby_llm/agents/api_configurations/_api_key_field.html.erb +34 -0
  26. data/app/views/ruby_llm/agents/api_configurations/_form.html.erb +288 -0
  27. data/app/views/ruby_llm/agents/api_configurations/edit.html.erb +95 -0
  28. data/app/views/ruby_llm/agents/api_configurations/edit_tenant.html.erb +97 -0
  29. data/app/views/ruby_llm/agents/api_configurations/show.html.erb +211 -0
  30. data/app/views/ruby_llm/agents/api_configurations/tenant.html.erb +179 -0
  31. data/app/views/ruby_llm/agents/dashboard/_action_center.html.erb +1 -1
  32. data/app/views/ruby_llm/agents/dashboard/_agent_comparison.html.erb +269 -15
  33. data/app/views/ruby_llm/agents/executions/show.html.erb +98 -0
  34. data/app/views/ruby_llm/agents/shared/_agent_type_badge.html.erb +93 -0
  35. data/app/views/ruby_llm/agents/{settings → system_config}/show.html.erb +1 -1
  36. data/app/views/ruby_llm/agents/tenants/_form.html.erb +150 -0
  37. data/app/views/ruby_llm/agents/tenants/edit.html.erb +13 -0
  38. data/app/views/ruby_llm/agents/tenants/index.html.erb +129 -0
  39. data/app/views/ruby_llm/agents/tenants/show.html.erb +374 -0
  40. data/app/views/ruby_llm/agents/workflows/_step_performance.html.erb +236 -0
  41. data/app/views/ruby_llm/agents/workflows/_structure_parallel.html.erb +76 -0
  42. data/app/views/ruby_llm/agents/workflows/_structure_pipeline.html.erb +74 -0
  43. data/app/views/ruby_llm/agents/workflows/_structure_router.html.erb +108 -0
  44. data/app/views/ruby_llm/agents/workflows/show.html.erb +442 -0
  45. data/config/routes.rb +13 -1
  46. data/lib/generators/ruby_llm_agents/agent_generator.rb +56 -7
  47. data/lib/generators/ruby_llm_agents/api_configuration_generator.rb +100 -0
  48. data/lib/generators/ruby_llm_agents/background_remover_generator.rb +110 -0
  49. data/lib/generators/ruby_llm_agents/embedder_generator.rb +107 -0
  50. data/lib/generators/ruby_llm_agents/image_analyzer_generator.rb +115 -0
  51. data/lib/generators/ruby_llm_agents/image_editor_generator.rb +108 -0
  52. data/lib/generators/ruby_llm_agents/image_generator_generator.rb +116 -0
  53. data/lib/generators/ruby_llm_agents/image_pipeline_generator.rb +178 -0
  54. data/lib/generators/ruby_llm_agents/image_transformer_generator.rb +109 -0
  55. data/lib/generators/ruby_llm_agents/image_upscaler_generator.rb +103 -0
  56. data/lib/generators/ruby_llm_agents/image_variator_generator.rb +102 -0
  57. data/lib/generators/ruby_llm_agents/install_generator.rb +76 -4
  58. data/lib/generators/ruby_llm_agents/restructure_generator.rb +292 -0
  59. data/lib/generators/ruby_llm_agents/speaker_generator.rb +121 -0
  60. data/lib/generators/ruby_llm_agents/templates/add_execution_type_migration.rb.tt +8 -0
  61. data/lib/generators/ruby_llm_agents/templates/agent.rb.tt +99 -84
  62. data/lib/generators/ruby_llm_agents/templates/application_agent.rb.tt +42 -40
  63. data/lib/generators/ruby_llm_agents/templates/application_background_remover.rb.tt +26 -0
  64. data/lib/generators/ruby_llm_agents/templates/application_embedder.rb.tt +50 -0
  65. data/lib/generators/ruby_llm_agents/templates/application_image_analyzer.rb.tt +26 -0
  66. data/lib/generators/ruby_llm_agents/templates/application_image_editor.rb.tt +20 -0
  67. data/lib/generators/ruby_llm_agents/templates/application_image_generator.rb.tt +38 -0
  68. data/lib/generators/ruby_llm_agents/templates/application_image_pipeline.rb.tt +139 -0
  69. data/lib/generators/ruby_llm_agents/templates/application_image_transformer.rb.tt +21 -0
  70. data/lib/generators/ruby_llm_agents/templates/application_image_upscaler.rb.tt +20 -0
  71. data/lib/generators/ruby_llm_agents/templates/application_image_variator.rb.tt +20 -0
  72. data/lib/generators/ruby_llm_agents/templates/application_speaker.rb.tt +49 -0
  73. data/lib/generators/ruby_llm_agents/templates/application_transcriber.rb.tt +53 -0
  74. data/lib/generators/ruby_llm_agents/templates/background_remover.rb.tt +44 -0
  75. data/lib/generators/ruby_llm_agents/templates/create_api_configurations_migration.rb.tt +90 -0
  76. data/lib/generators/ruby_llm_agents/templates/embedder.rb.tt +41 -0
  77. data/lib/generators/ruby_llm_agents/templates/image_analyzer.rb.tt +45 -0
  78. data/lib/generators/ruby_llm_agents/templates/image_editor.rb.tt +35 -0
  79. data/lib/generators/ruby_llm_agents/templates/image_generator.rb.tt +47 -0
  80. data/lib/generators/ruby_llm_agents/templates/image_pipeline.rb.tt +50 -0
  81. data/lib/generators/ruby_llm_agents/templates/image_transformer.rb.tt +44 -0
  82. data/lib/generators/ruby_llm_agents/templates/image_upscaler.rb.tt +38 -0
  83. data/lib/generators/ruby_llm_agents/templates/image_variator.rb.tt +33 -0
  84. data/lib/generators/ruby_llm_agents/templates/skills/AGENTS.md.tt +228 -0
  85. data/lib/generators/ruby_llm_agents/templates/skills/BACKGROUND_REMOVERS.md.tt +131 -0
  86. data/lib/generators/ruby_llm_agents/templates/skills/EMBEDDERS.md.tt +255 -0
  87. data/lib/generators/ruby_llm_agents/templates/skills/IMAGE_ANALYZERS.md.tt +120 -0
  88. data/lib/generators/ruby_llm_agents/templates/skills/IMAGE_EDITORS.md.tt +102 -0
  89. data/lib/generators/ruby_llm_agents/templates/skills/IMAGE_GENERATORS.md.tt +282 -0
  90. data/lib/generators/ruby_llm_agents/templates/skills/IMAGE_PIPELINES.md.tt +228 -0
  91. data/lib/generators/ruby_llm_agents/templates/skills/IMAGE_TRANSFORMERS.md.tt +120 -0
  92. data/lib/generators/ruby_llm_agents/templates/skills/IMAGE_UPSCALERS.md.tt +110 -0
  93. data/lib/generators/ruby_llm_agents/templates/skills/IMAGE_VARIATORS.md.tt +120 -0
  94. data/lib/generators/ruby_llm_agents/templates/skills/SPEAKERS.md.tt +212 -0
  95. data/lib/generators/ruby_llm_agents/templates/skills/TOOLS.md.tt +227 -0
  96. data/lib/generators/ruby_llm_agents/templates/skills/TRANSCRIBERS.md.tt +251 -0
  97. data/lib/generators/ruby_llm_agents/templates/skills/WORKFLOWS.md.tt +300 -0
  98. data/lib/generators/ruby_llm_agents/templates/speaker.rb.tt +56 -0
  99. data/lib/generators/ruby_llm_agents/templates/transcriber.rb.tt +51 -0
  100. data/lib/generators/ruby_llm_agents/transcriber_generator.rb +107 -0
  101. data/lib/generators/ruby_llm_agents/upgrade_generator.rb +152 -1
  102. data/lib/ruby_llm/agents/audio/speaker.rb +553 -0
  103. data/lib/ruby_llm/agents/audio/transcriber.rb +669 -0
  104. data/lib/ruby_llm/agents/base_agent.rb +675 -0
  105. data/lib/ruby_llm/agents/core/base/moderation_dsl.rb +181 -0
  106. data/lib/ruby_llm/agents/core/base/moderation_execution.rb +274 -0
  107. data/lib/ruby_llm/agents/core/base.rb +135 -0
  108. data/lib/ruby_llm/agents/core/configuration.rb +981 -0
  109. data/lib/ruby_llm/agents/core/errors.rb +150 -0
  110. data/lib/ruby_llm/agents/{instrumentation.rb → core/instrumentation.rb} +93 -4
  111. data/lib/ruby_llm/agents/core/llm_tenant.rb +358 -0
  112. data/lib/ruby_llm/agents/core/resolved_config.rb +348 -0
  113. data/lib/ruby_llm/agents/{version.rb → core/version.rb} +1 -1
  114. data/lib/ruby_llm/agents/dsl/base.rb +110 -0
  115. data/lib/ruby_llm/agents/dsl/caching.rb +142 -0
  116. data/lib/ruby_llm/agents/dsl/reliability.rb +307 -0
  117. data/lib/ruby_llm/agents/dsl.rb +41 -0
  118. data/lib/ruby_llm/agents/image/analyzer/dsl.rb +130 -0
  119. data/lib/ruby_llm/agents/image/analyzer/execution.rb +402 -0
  120. data/lib/ruby_llm/agents/image/analyzer.rb +90 -0
  121. data/lib/ruby_llm/agents/image/background_remover/dsl.rb +154 -0
  122. data/lib/ruby_llm/agents/image/background_remover/execution.rb +240 -0
  123. data/lib/ruby_llm/agents/image/background_remover.rb +89 -0
  124. data/lib/ruby_llm/agents/image/concerns/image_operation_dsl.rb +91 -0
  125. data/lib/ruby_llm/agents/image/concerns/image_operation_execution.rb +165 -0
  126. data/lib/ruby_llm/agents/image/editor/dsl.rb +56 -0
  127. data/lib/ruby_llm/agents/image/editor/execution.rb +207 -0
  128. data/lib/ruby_llm/agents/image/editor.rb +92 -0
  129. data/lib/ruby_llm/agents/image/generator/active_storage_support.rb +127 -0
  130. data/lib/ruby_llm/agents/image/generator/content_policy.rb +95 -0
  131. data/lib/ruby_llm/agents/image/generator/pricing.rb +353 -0
  132. data/lib/ruby_llm/agents/image/generator/templates.rb +124 -0
  133. data/lib/ruby_llm/agents/image/generator.rb +455 -0
  134. data/lib/ruby_llm/agents/image/pipeline/dsl.rb +213 -0
  135. data/lib/ruby_llm/agents/image/pipeline/execution.rb +382 -0
  136. data/lib/ruby_llm/agents/image/pipeline.rb +97 -0
  137. data/lib/ruby_llm/agents/image/transformer/dsl.rb +148 -0
  138. data/lib/ruby_llm/agents/image/transformer/execution.rb +223 -0
  139. data/lib/ruby_llm/agents/image/transformer.rb +95 -0
  140. data/lib/ruby_llm/agents/image/upscaler/dsl.rb +83 -0
  141. data/lib/ruby_llm/agents/image/upscaler/execution.rb +219 -0
  142. data/lib/ruby_llm/agents/image/upscaler.rb +81 -0
  143. data/lib/ruby_llm/agents/image/variator/dsl.rb +62 -0
  144. data/lib/ruby_llm/agents/image/variator/execution.rb +189 -0
  145. data/lib/ruby_llm/agents/image/variator.rb +80 -0
  146. data/lib/ruby_llm/agents/{alert_manager.rb → infrastructure/alert_manager.rb} +17 -22
  147. data/lib/ruby_llm/agents/infrastructure/budget/budget_query.rb +145 -0
  148. data/lib/ruby_llm/agents/infrastructure/budget/config_resolver.rb +149 -0
  149. data/lib/ruby_llm/agents/infrastructure/budget/forecaster.rb +68 -0
  150. data/lib/ruby_llm/agents/infrastructure/budget/spend_recorder.rb +279 -0
  151. data/lib/ruby_llm/agents/infrastructure/budget_tracker.rb +275 -0
  152. data/lib/ruby_llm/agents/{execution_logger_job.rb → infrastructure/execution_logger_job.rb} +17 -1
  153. data/lib/ruby_llm/agents/{reliability → infrastructure/reliability}/executor.rb +2 -1
  154. data/lib/ruby_llm/agents/{reliability → infrastructure/reliability}/retry_strategy.rb +9 -3
  155. data/lib/ruby_llm/agents/{reliability.rb → infrastructure/reliability.rb} +11 -21
  156. data/lib/ruby_llm/agents/pipeline/builder.rb +215 -0
  157. data/lib/ruby_llm/agents/pipeline/context.rb +255 -0
  158. data/lib/ruby_llm/agents/pipeline/executor.rb +86 -0
  159. data/lib/ruby_llm/agents/pipeline/middleware/base.rb +124 -0
  160. data/lib/ruby_llm/agents/pipeline/middleware/budget.rb +95 -0
  161. data/lib/ruby_llm/agents/pipeline/middleware/cache.rb +171 -0
  162. data/lib/ruby_llm/agents/pipeline/middleware/instrumentation.rb +415 -0
  163. data/lib/ruby_llm/agents/pipeline/middleware/reliability.rb +276 -0
  164. data/lib/ruby_llm/agents/pipeline/middleware/tenant.rb +196 -0
  165. data/lib/ruby_llm/agents/pipeline.rb +68 -0
  166. data/lib/ruby_llm/agents/{engine.rb → rails/engine.rb} +79 -10
  167. data/lib/ruby_llm/agents/results/background_removal_result.rb +286 -0
  168. data/lib/ruby_llm/agents/{result.rb → results/base.rb} +73 -1
  169. data/lib/ruby_llm/agents/results/embedding_result.rb +243 -0
  170. data/lib/ruby_llm/agents/results/image_analysis_result.rb +314 -0
  171. data/lib/ruby_llm/agents/results/image_edit_result.rb +250 -0
  172. data/lib/ruby_llm/agents/results/image_generation_result.rb +346 -0
  173. data/lib/ruby_llm/agents/results/image_pipeline_result.rb +399 -0
  174. data/lib/ruby_llm/agents/results/image_transform_result.rb +251 -0
  175. data/lib/ruby_llm/agents/results/image_upscale_result.rb +255 -0
  176. data/lib/ruby_llm/agents/results/image_variation_result.rb +237 -0
  177. data/lib/ruby_llm/agents/results/moderation_result.rb +158 -0
  178. data/lib/ruby_llm/agents/results/speech_result.rb +338 -0
  179. data/lib/ruby_llm/agents/results/transcription_result.rb +408 -0
  180. data/lib/ruby_llm/agents/text/embedder.rb +444 -0
  181. data/lib/ruby_llm/agents/text/moderator.rb +237 -0
  182. data/lib/ruby_llm/agents/workflow/async.rb +220 -0
  183. data/lib/ruby_llm/agents/workflow/async_executor.rb +156 -0
  184. data/lib/ruby_llm/agents/{workflow.rb → workflow/orchestrator.rb} +6 -5
  185. data/lib/ruby_llm/agents/workflow/parallel.rb +34 -17
  186. data/lib/ruby_llm/agents/workflow/thread_pool.rb +185 -0
  187. data/lib/ruby_llm/agents.rb +86 -20
  188. metadata +189 -35
  189. data/lib/ruby_llm/agents/base/caching.rb +0 -40
  190. data/lib/ruby_llm/agents/base/cost_calculation.rb +0 -105
  191. data/lib/ruby_llm/agents/base/dsl.rb +0 -324
  192. data/lib/ruby_llm/agents/base/execution.rb +0 -283
  193. data/lib/ruby_llm/agents/base/reliability_dsl.rb +0 -82
  194. data/lib/ruby_llm/agents/base/reliability_execution.rb +0 -136
  195. data/lib/ruby_llm/agents/base/response_building.rb +0 -86
  196. data/lib/ruby_llm/agents/base/tool_tracking.rb +0 -57
  197. data/lib/ruby_llm/agents/base.rb +0 -209
  198. data/lib/ruby_llm/agents/budget_tracker.rb +0 -471
  199. data/lib/ruby_llm/agents/configuration.rb +0 -357
  200. /data/lib/ruby_llm/agents/{deprecations.rb → core/deprecations.rb} +0 -0
  201. /data/lib/ruby_llm/agents/{inflections.rb → core/inflections.rb} +0 -0
  202. /data/lib/ruby_llm/agents/{attempt_tracker.rb → infrastructure/attempt_tracker.rb} +0 -0
  203. /data/lib/ruby_llm/agents/{cache_helper.rb → infrastructure/cache_helper.rb} +0 -0
  204. /data/lib/ruby_llm/agents/{circuit_breaker.rb → infrastructure/circuit_breaker.rb} +0 -0
  205. /data/lib/ruby_llm/agents/{redactor.rb → infrastructure/redactor.rb} +0 -0
  206. /data/lib/ruby_llm/agents/{reliability → infrastructure/reliability}/breaker_manager.rb +0 -0
  207. /data/lib/ruby_llm/agents/{reliability → infrastructure/reliability}/execution_constraints.rb +0 -0
  208. /data/lib/ruby_llm/agents/{reliability → infrastructure/reliability}/fallback_routing.rb +0 -0
@@ -3,23 +3,92 @@
3
3
  require "csv"
4
4
  require "ruby_llm"
5
5
 
6
- require_relative "agents/version"
7
- require_relative "agents/configuration"
8
- require_relative "agents/deprecations"
9
- require_relative "agents/reliability"
10
- require_relative "agents/reliability/retry_strategy"
11
- require_relative "agents/reliability/fallback_routing"
12
- require_relative "agents/reliability/breaker_manager"
13
- require_relative "agents/reliability/execution_constraints"
14
- require_relative "agents/reliability/executor"
15
- require_relative "agents/redactor"
16
- require_relative "agents/circuit_breaker"
17
- require_relative "agents/budget_tracker"
18
- require_relative "agents/alert_manager"
19
- require_relative "agents/attempt_tracker"
20
- require_relative "agents/result"
21
- require_relative "agents/inflections" if defined?(Rails)
22
- require_relative "agents/engine" if defined?(Rails::Engine)
6
+ # Core
7
+ require_relative "agents/core/version"
8
+ require_relative "agents/core/configuration"
9
+ require_relative "agents/core/deprecations"
10
+ require_relative "agents/core/errors"
11
+ require_relative "agents/core/resolved_config"
12
+ require_relative "agents/core/llm_tenant"
13
+
14
+ # Infrastructure - Reliability
15
+ require_relative "agents/infrastructure/reliability"
16
+ require_relative "agents/infrastructure/reliability/retry_strategy"
17
+ require_relative "agents/infrastructure/reliability/fallback_routing"
18
+ require_relative "agents/infrastructure/reliability/breaker_manager"
19
+ require_relative "agents/infrastructure/reliability/execution_constraints"
20
+ require_relative "agents/infrastructure/reliability/executor"
21
+
22
+ # Pipeline infrastructure (middleware-based execution)
23
+ require_relative "agents/pipeline"
24
+
25
+ # DSL modules for agent configuration
26
+ require_relative "agents/dsl"
27
+
28
+ # BaseAgent - new middleware-based agent architecture
29
+ require_relative "agents/base_agent"
30
+
31
+ # Infrastructure - Budget & Utilities
32
+ require_relative "agents/infrastructure/redactor"
33
+ require_relative "agents/infrastructure/circuit_breaker"
34
+ require_relative "agents/infrastructure/budget_tracker"
35
+ require_relative "agents/infrastructure/alert_manager"
36
+ require_relative "agents/infrastructure/attempt_tracker"
37
+ require_relative "agents/infrastructure/cache_helper"
38
+ require_relative "agents/infrastructure/budget/budget_query"
39
+ require_relative "agents/infrastructure/budget/config_resolver"
40
+ require_relative "agents/infrastructure/budget/forecaster"
41
+ require_relative "agents/infrastructure/budget/spend_recorder"
42
+
43
+ # Results
44
+ require_relative "agents/results/base"
45
+ require_relative "agents/results/embedding_result"
46
+ require_relative "agents/results/moderation_result"
47
+ require_relative "agents/results/transcription_result"
48
+ require_relative "agents/results/speech_result"
49
+ require_relative "agents/results/image_generation_result"
50
+ require_relative "agents/results/image_variation_result"
51
+ require_relative "agents/results/image_edit_result"
52
+ require_relative "agents/results/image_transform_result"
53
+ require_relative "agents/results/image_upscale_result"
54
+ require_relative "agents/results/image_analysis_result"
55
+ require_relative "agents/results/background_removal_result"
56
+ require_relative "agents/results/image_pipeline_result"
57
+
58
+ # Image concerns (shared DSL/execution for image operations)
59
+ require_relative "agents/image/concerns/image_operation_dsl"
60
+ require_relative "agents/image/concerns/image_operation_execution"
61
+
62
+ # Text agents
63
+ require_relative "agents/text/embedder"
64
+ require_relative "agents/text/moderator"
65
+
66
+ # Audio agents
67
+ require_relative "agents/audio/transcriber"
68
+ require_relative "agents/audio/speaker"
69
+
70
+ # Image agents
71
+ require_relative "agents/image/generator"
72
+ require_relative "agents/image/variator"
73
+ require_relative "agents/image/editor"
74
+ require_relative "agents/image/transformer"
75
+ require_relative "agents/image/upscaler"
76
+ require_relative "agents/image/analyzer"
77
+ require_relative "agents/image/background_remover"
78
+ require_relative "agents/image/pipeline"
79
+
80
+ # Workflow
81
+ require_relative "agents/workflow/async"
82
+ require_relative "agents/workflow/orchestrator"
83
+ require_relative "agents/workflow/async_executor"
84
+
85
+ # Rails integration
86
+ if defined?(Rails)
87
+ require_relative "agents/core/inflections"
88
+ require_relative "agents/core/instrumentation"
89
+ require_relative "agents/infrastructure/execution_logger_job"
90
+ end
91
+ require_relative "agents/rails/engine" if defined?(Rails::Engine)
23
92
 
24
93
  module RubyLLM
25
94
  # Agent framework for building LLM-powered agents with observability
@@ -49,9 +118,6 @@ module RubyLLM
49
118
  # @see RubyLLM::Agents::Base
50
119
  # @see RubyLLM::Agents::Configuration
51
120
  module Agents
52
- # Base error class for agent-related exceptions
53
- class Error < StandardError; end
54
-
55
121
  class << self
56
122
  # Returns the global configuration instance
57
123
  #
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_llm-agents
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 1.0.0.beta.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - adham90
@@ -29,14 +29,14 @@ dependencies:
29
29
  requirements:
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: '1.0'
32
+ version: 1.11.0
33
33
  type: :runtime
34
34
  prerelease: false
35
35
  version_requirements: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
- version: '1.0'
39
+ version: 1.11.0
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: csv
42
42
  requirement: !ruby/object:Gem::Requirement
@@ -51,6 +51,20 @@ dependencies:
51
51
  - - ">="
52
52
  - !ruby/object:Gem::Version
53
53
  version: '0'
54
+ - !ruby/object:Gem::Dependency
55
+ name: ostruct
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ type: :runtime
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
54
68
  description: A Rails engine for creating, managing, and monitoring LLM-powered agents.
55
69
  Includes a DSL for agent configuration, execution tracking, cost analytics, and
56
70
  a mountable dashboard UI.
@@ -65,10 +79,14 @@ files:
65
79
  - app/controllers/concerns/ruby_llm/agents/filterable.rb
66
80
  - app/controllers/concerns/ruby_llm/agents/paginatable.rb
67
81
  - app/controllers/ruby_llm/agents/agents_controller.rb
82
+ - app/controllers/ruby_llm/agents/api_configurations_controller.rb
68
83
  - app/controllers/ruby_llm/agents/dashboard_controller.rb
69
84
  - app/controllers/ruby_llm/agents/executions_controller.rb
70
- - app/controllers/ruby_llm/agents/settings_controller.rb
85
+ - app/controllers/ruby_llm/agents/system_config_controller.rb
86
+ - app/controllers/ruby_llm/agents/tenants_controller.rb
87
+ - app/controllers/ruby_llm/agents/workflows_controller.rb
71
88
  - app/helpers/ruby_llm/agents/application_helper.rb
89
+ - app/models/ruby_llm/agents/api_configuration.rb
72
90
  - app/models/ruby_llm/agents/execution.rb
73
91
  - app/models/ruby_llm/agents/execution/analytics.rb
74
92
  - app/models/ruby_llm/agents/execution/metrics.rb
@@ -78,11 +96,23 @@ files:
78
96
  - app/services/ruby_llm/agents/agent_registry.rb
79
97
  - app/views/layouts/ruby_llm/agents/application.html.erb
80
98
  - app/views/ruby_llm/agents/agents/_agent.html.erb
99
+ - app/views/ruby_llm/agents/agents/_config_agent.html.erb
100
+ - app/views/ruby_llm/agents/agents/_config_embedder.html.erb
101
+ - app/views/ruby_llm/agents/agents/_config_image_generator.html.erb
102
+ - app/views/ruby_llm/agents/agents/_config_moderator.html.erb
103
+ - app/views/ruby_llm/agents/agents/_config_speaker.html.erb
104
+ - app/views/ruby_llm/agents/agents/_config_transcriber.html.erb
81
105
  - app/views/ruby_llm/agents/agents/_empty_state.html.erb
82
106
  - app/views/ruby_llm/agents/agents/_version_comparison.html.erb
83
107
  - app/views/ruby_llm/agents/agents/_workflow.html.erb
84
108
  - app/views/ruby_llm/agents/agents/index.html.erb
85
109
  - app/views/ruby_llm/agents/agents/show.html.erb
110
+ - app/views/ruby_llm/agents/api_configurations/_api_key_field.html.erb
111
+ - app/views/ruby_llm/agents/api_configurations/_form.html.erb
112
+ - app/views/ruby_llm/agents/api_configurations/edit.html.erb
113
+ - app/views/ruby_llm/agents/api_configurations/edit_tenant.html.erb
114
+ - app/views/ruby_llm/agents/api_configurations/show.html.erb
115
+ - app/views/ruby_llm/agents/api_configurations/tenant.html.erb
86
116
  - app/views/ruby_llm/agents/dashboard/_action_center.html.erb
87
117
  - app/views/ruby_llm/agents/dashboard/_agent_comparison.html.erb
88
118
  - app/views/ruby_llm/agents/dashboard/_alerts_feed.html.erb
@@ -100,7 +130,7 @@ files:
100
130
  - app/views/ruby_llm/agents/executions/dry_run.html.erb
101
131
  - app/views/ruby_llm/agents/executions/index.html.erb
102
132
  - app/views/ruby_llm/agents/executions/show.html.erb
103
- - app/views/ruby_llm/agents/settings/show.html.erb
133
+ - app/views/ruby_llm/agents/shared/_agent_type_badge.html.erb
104
134
  - app/views/ruby_llm/agents/shared/_breadcrumbs.html.erb
105
135
  - app/views/ruby_llm/agents/shared/_executions_table.html.erb
106
136
  - app/views/ruby_llm/agents/shared/_filter_dropdown.html.erb
@@ -111,12 +141,35 @@ files:
111
141
  - app/views/ruby_llm/agents/shared/_status_dot.html.erb
112
142
  - app/views/ruby_llm/agents/shared/_tenant_filter.html.erb
113
143
  - app/views/ruby_llm/agents/shared/_workflow_type_badge.html.erb
144
+ - app/views/ruby_llm/agents/system_config/show.html.erb
145
+ - app/views/ruby_llm/agents/tenants/_form.html.erb
146
+ - app/views/ruby_llm/agents/tenants/edit.html.erb
147
+ - app/views/ruby_llm/agents/tenants/index.html.erb
148
+ - app/views/ruby_llm/agents/tenants/show.html.erb
149
+ - app/views/ruby_llm/agents/workflows/_step_performance.html.erb
150
+ - app/views/ruby_llm/agents/workflows/_structure_parallel.html.erb
151
+ - app/views/ruby_llm/agents/workflows/_structure_pipeline.html.erb
152
+ - app/views/ruby_llm/agents/workflows/_structure_router.html.erb
153
+ - app/views/ruby_llm/agents/workflows/show.html.erb
114
154
  - config/routes.rb
115
155
  - lib/generators/ruby_llm_agents/agent_generator.rb
156
+ - lib/generators/ruby_llm_agents/api_configuration_generator.rb
157
+ - lib/generators/ruby_llm_agents/background_remover_generator.rb
158
+ - lib/generators/ruby_llm_agents/embedder_generator.rb
159
+ - lib/generators/ruby_llm_agents/image_analyzer_generator.rb
160
+ - lib/generators/ruby_llm_agents/image_editor_generator.rb
161
+ - lib/generators/ruby_llm_agents/image_generator_generator.rb
162
+ - lib/generators/ruby_llm_agents/image_pipeline_generator.rb
163
+ - lib/generators/ruby_llm_agents/image_transformer_generator.rb
164
+ - lib/generators/ruby_llm_agents/image_upscaler_generator.rb
165
+ - lib/generators/ruby_llm_agents/image_variator_generator.rb
116
166
  - lib/generators/ruby_llm_agents/install_generator.rb
117
167
  - lib/generators/ruby_llm_agents/multi_tenancy_generator.rb
168
+ - lib/generators/ruby_llm_agents/restructure_generator.rb
169
+ - lib/generators/ruby_llm_agents/speaker_generator.rb
118
170
  - lib/generators/ruby_llm_agents/templates/add_attempts_migration.rb.tt
119
171
  - lib/generators/ruby_llm_agents/templates/add_caching_migration.rb.tt
172
+ - lib/generators/ruby_llm_agents/templates/add_execution_type_migration.rb.tt
120
173
  - lib/generators/ruby_llm_agents/templates/add_finish_reason_migration.rb.tt
121
174
  - lib/generators/ruby_llm_agents/templates/add_prompts_migration.rb.tt
122
175
  - lib/generators/ruby_llm_agents/templates/add_routing_migration.rb.tt
@@ -127,47 +180,148 @@ files:
127
180
  - lib/generators/ruby_llm_agents/templates/add_workflow_migration.rb.tt
128
181
  - lib/generators/ruby_llm_agents/templates/agent.rb.tt
129
182
  - lib/generators/ruby_llm_agents/templates/application_agent.rb.tt
183
+ - lib/generators/ruby_llm_agents/templates/application_background_remover.rb.tt
184
+ - lib/generators/ruby_llm_agents/templates/application_embedder.rb.tt
185
+ - lib/generators/ruby_llm_agents/templates/application_image_analyzer.rb.tt
186
+ - lib/generators/ruby_llm_agents/templates/application_image_editor.rb.tt
187
+ - lib/generators/ruby_llm_agents/templates/application_image_generator.rb.tt
188
+ - lib/generators/ruby_llm_agents/templates/application_image_pipeline.rb.tt
189
+ - lib/generators/ruby_llm_agents/templates/application_image_transformer.rb.tt
190
+ - lib/generators/ruby_llm_agents/templates/application_image_upscaler.rb.tt
191
+ - lib/generators/ruby_llm_agents/templates/application_image_variator.rb.tt
192
+ - lib/generators/ruby_llm_agents/templates/application_speaker.rb.tt
193
+ - lib/generators/ruby_llm_agents/templates/application_transcriber.rb.tt
194
+ - lib/generators/ruby_llm_agents/templates/background_remover.rb.tt
195
+ - lib/generators/ruby_llm_agents/templates/create_api_configurations_migration.rb.tt
130
196
  - lib/generators/ruby_llm_agents/templates/create_tenant_budgets_migration.rb.tt
197
+ - lib/generators/ruby_llm_agents/templates/embedder.rb.tt
198
+ - lib/generators/ruby_llm_agents/templates/image_analyzer.rb.tt
199
+ - lib/generators/ruby_llm_agents/templates/image_editor.rb.tt
200
+ - lib/generators/ruby_llm_agents/templates/image_generator.rb.tt
201
+ - lib/generators/ruby_llm_agents/templates/image_pipeline.rb.tt
202
+ - lib/generators/ruby_llm_agents/templates/image_transformer.rb.tt
203
+ - lib/generators/ruby_llm_agents/templates/image_upscaler.rb.tt
204
+ - lib/generators/ruby_llm_agents/templates/image_variator.rb.tt
131
205
  - lib/generators/ruby_llm_agents/templates/initializer.rb.tt
132
206
  - lib/generators/ruby_llm_agents/templates/migration.rb.tt
207
+ - lib/generators/ruby_llm_agents/templates/skills/AGENTS.md.tt
208
+ - lib/generators/ruby_llm_agents/templates/skills/BACKGROUND_REMOVERS.md.tt
209
+ - lib/generators/ruby_llm_agents/templates/skills/EMBEDDERS.md.tt
210
+ - lib/generators/ruby_llm_agents/templates/skills/IMAGE_ANALYZERS.md.tt
211
+ - lib/generators/ruby_llm_agents/templates/skills/IMAGE_EDITORS.md.tt
212
+ - lib/generators/ruby_llm_agents/templates/skills/IMAGE_GENERATORS.md.tt
213
+ - lib/generators/ruby_llm_agents/templates/skills/IMAGE_PIPELINES.md.tt
214
+ - lib/generators/ruby_llm_agents/templates/skills/IMAGE_TRANSFORMERS.md.tt
215
+ - lib/generators/ruby_llm_agents/templates/skills/IMAGE_UPSCALERS.md.tt
216
+ - lib/generators/ruby_llm_agents/templates/skills/IMAGE_VARIATORS.md.tt
217
+ - lib/generators/ruby_llm_agents/templates/skills/SPEAKERS.md.tt
218
+ - lib/generators/ruby_llm_agents/templates/skills/TOOLS.md.tt
219
+ - lib/generators/ruby_llm_agents/templates/skills/TRANSCRIBERS.md.tt
220
+ - lib/generators/ruby_llm_agents/templates/skills/WORKFLOWS.md.tt
221
+ - lib/generators/ruby_llm_agents/templates/speaker.rb.tt
222
+ - lib/generators/ruby_llm_agents/templates/transcriber.rb.tt
223
+ - lib/generators/ruby_llm_agents/transcriber_generator.rb
133
224
  - lib/generators/ruby_llm_agents/upgrade_generator.rb
134
225
  - lib/ruby_llm-agents.rb
135
226
  - lib/ruby_llm/agents.rb
136
- - lib/ruby_llm/agents/alert_manager.rb
137
- - lib/ruby_llm/agents/attempt_tracker.rb
138
- - lib/ruby_llm/agents/base.rb
139
- - lib/ruby_llm/agents/base/caching.rb
140
- - lib/ruby_llm/agents/base/cost_calculation.rb
141
- - lib/ruby_llm/agents/base/dsl.rb
142
- - lib/ruby_llm/agents/base/execution.rb
143
- - lib/ruby_llm/agents/base/reliability_dsl.rb
144
- - lib/ruby_llm/agents/base/reliability_execution.rb
145
- - lib/ruby_llm/agents/base/response_building.rb
146
- - lib/ruby_llm/agents/base/tool_tracking.rb
147
- - lib/ruby_llm/agents/budget_tracker.rb
148
- - lib/ruby_llm/agents/cache_helper.rb
149
- - lib/ruby_llm/agents/circuit_breaker.rb
150
- - lib/ruby_llm/agents/configuration.rb
151
- - lib/ruby_llm/agents/deprecations.rb
152
- - lib/ruby_llm/agents/engine.rb
153
- - lib/ruby_llm/agents/execution_logger_job.rb
154
- - lib/ruby_llm/agents/inflections.rb
155
- - lib/ruby_llm/agents/instrumentation.rb
156
- - lib/ruby_llm/agents/redactor.rb
157
- - lib/ruby_llm/agents/reliability.rb
158
- - lib/ruby_llm/agents/reliability/breaker_manager.rb
159
- - lib/ruby_llm/agents/reliability/execution_constraints.rb
160
- - lib/ruby_llm/agents/reliability/executor.rb
161
- - lib/ruby_llm/agents/reliability/fallback_routing.rb
162
- - lib/ruby_llm/agents/reliability/retry_strategy.rb
163
- - lib/ruby_llm/agents/result.rb
164
- - lib/ruby_llm/agents/version.rb
165
- - lib/ruby_llm/agents/workflow.rb
227
+ - lib/ruby_llm/agents/audio/speaker.rb
228
+ - lib/ruby_llm/agents/audio/transcriber.rb
229
+ - lib/ruby_llm/agents/base_agent.rb
230
+ - lib/ruby_llm/agents/core/base.rb
231
+ - lib/ruby_llm/agents/core/base/moderation_dsl.rb
232
+ - lib/ruby_llm/agents/core/base/moderation_execution.rb
233
+ - lib/ruby_llm/agents/core/configuration.rb
234
+ - lib/ruby_llm/agents/core/deprecations.rb
235
+ - lib/ruby_llm/agents/core/errors.rb
236
+ - lib/ruby_llm/agents/core/inflections.rb
237
+ - lib/ruby_llm/agents/core/instrumentation.rb
238
+ - lib/ruby_llm/agents/core/llm_tenant.rb
239
+ - lib/ruby_llm/agents/core/resolved_config.rb
240
+ - lib/ruby_llm/agents/core/version.rb
241
+ - lib/ruby_llm/agents/dsl.rb
242
+ - lib/ruby_llm/agents/dsl/base.rb
243
+ - lib/ruby_llm/agents/dsl/caching.rb
244
+ - lib/ruby_llm/agents/dsl/reliability.rb
245
+ - lib/ruby_llm/agents/image/analyzer.rb
246
+ - lib/ruby_llm/agents/image/analyzer/dsl.rb
247
+ - lib/ruby_llm/agents/image/analyzer/execution.rb
248
+ - lib/ruby_llm/agents/image/background_remover.rb
249
+ - lib/ruby_llm/agents/image/background_remover/dsl.rb
250
+ - lib/ruby_llm/agents/image/background_remover/execution.rb
251
+ - lib/ruby_llm/agents/image/concerns/image_operation_dsl.rb
252
+ - lib/ruby_llm/agents/image/concerns/image_operation_execution.rb
253
+ - lib/ruby_llm/agents/image/editor.rb
254
+ - lib/ruby_llm/agents/image/editor/dsl.rb
255
+ - lib/ruby_llm/agents/image/editor/execution.rb
256
+ - lib/ruby_llm/agents/image/generator.rb
257
+ - lib/ruby_llm/agents/image/generator/active_storage_support.rb
258
+ - lib/ruby_llm/agents/image/generator/content_policy.rb
259
+ - lib/ruby_llm/agents/image/generator/pricing.rb
260
+ - lib/ruby_llm/agents/image/generator/templates.rb
261
+ - lib/ruby_llm/agents/image/pipeline.rb
262
+ - lib/ruby_llm/agents/image/pipeline/dsl.rb
263
+ - lib/ruby_llm/agents/image/pipeline/execution.rb
264
+ - lib/ruby_llm/agents/image/transformer.rb
265
+ - lib/ruby_llm/agents/image/transformer/dsl.rb
266
+ - lib/ruby_llm/agents/image/transformer/execution.rb
267
+ - lib/ruby_llm/agents/image/upscaler.rb
268
+ - lib/ruby_llm/agents/image/upscaler/dsl.rb
269
+ - lib/ruby_llm/agents/image/upscaler/execution.rb
270
+ - lib/ruby_llm/agents/image/variator.rb
271
+ - lib/ruby_llm/agents/image/variator/dsl.rb
272
+ - lib/ruby_llm/agents/image/variator/execution.rb
273
+ - lib/ruby_llm/agents/infrastructure/alert_manager.rb
274
+ - lib/ruby_llm/agents/infrastructure/attempt_tracker.rb
275
+ - lib/ruby_llm/agents/infrastructure/budget/budget_query.rb
276
+ - lib/ruby_llm/agents/infrastructure/budget/config_resolver.rb
277
+ - lib/ruby_llm/agents/infrastructure/budget/forecaster.rb
278
+ - lib/ruby_llm/agents/infrastructure/budget/spend_recorder.rb
279
+ - lib/ruby_llm/agents/infrastructure/budget_tracker.rb
280
+ - lib/ruby_llm/agents/infrastructure/cache_helper.rb
281
+ - lib/ruby_llm/agents/infrastructure/circuit_breaker.rb
282
+ - lib/ruby_llm/agents/infrastructure/execution_logger_job.rb
283
+ - lib/ruby_llm/agents/infrastructure/redactor.rb
284
+ - lib/ruby_llm/agents/infrastructure/reliability.rb
285
+ - lib/ruby_llm/agents/infrastructure/reliability/breaker_manager.rb
286
+ - lib/ruby_llm/agents/infrastructure/reliability/execution_constraints.rb
287
+ - lib/ruby_llm/agents/infrastructure/reliability/executor.rb
288
+ - lib/ruby_llm/agents/infrastructure/reliability/fallback_routing.rb
289
+ - lib/ruby_llm/agents/infrastructure/reliability/retry_strategy.rb
290
+ - lib/ruby_llm/agents/pipeline.rb
291
+ - lib/ruby_llm/agents/pipeline/builder.rb
292
+ - lib/ruby_llm/agents/pipeline/context.rb
293
+ - lib/ruby_llm/agents/pipeline/executor.rb
294
+ - lib/ruby_llm/agents/pipeline/middleware/base.rb
295
+ - lib/ruby_llm/agents/pipeline/middleware/budget.rb
296
+ - lib/ruby_llm/agents/pipeline/middleware/cache.rb
297
+ - lib/ruby_llm/agents/pipeline/middleware/instrumentation.rb
298
+ - lib/ruby_llm/agents/pipeline/middleware/reliability.rb
299
+ - lib/ruby_llm/agents/pipeline/middleware/tenant.rb
300
+ - lib/ruby_llm/agents/rails/engine.rb
301
+ - lib/ruby_llm/agents/results/background_removal_result.rb
302
+ - lib/ruby_llm/agents/results/base.rb
303
+ - lib/ruby_llm/agents/results/embedding_result.rb
304
+ - lib/ruby_llm/agents/results/image_analysis_result.rb
305
+ - lib/ruby_llm/agents/results/image_edit_result.rb
306
+ - lib/ruby_llm/agents/results/image_generation_result.rb
307
+ - lib/ruby_llm/agents/results/image_pipeline_result.rb
308
+ - lib/ruby_llm/agents/results/image_transform_result.rb
309
+ - lib/ruby_llm/agents/results/image_upscale_result.rb
310
+ - lib/ruby_llm/agents/results/image_variation_result.rb
311
+ - lib/ruby_llm/agents/results/moderation_result.rb
312
+ - lib/ruby_llm/agents/results/speech_result.rb
313
+ - lib/ruby_llm/agents/results/transcription_result.rb
314
+ - lib/ruby_llm/agents/text/embedder.rb
315
+ - lib/ruby_llm/agents/text/moderator.rb
316
+ - lib/ruby_llm/agents/workflow/async.rb
317
+ - lib/ruby_llm/agents/workflow/async_executor.rb
166
318
  - lib/ruby_llm/agents/workflow/instrumentation.rb
319
+ - lib/ruby_llm/agents/workflow/orchestrator.rb
167
320
  - lib/ruby_llm/agents/workflow/parallel.rb
168
321
  - lib/ruby_llm/agents/workflow/pipeline.rb
169
322
  - lib/ruby_llm/agents/workflow/result.rb
170
323
  - lib/ruby_llm/agents/workflow/router.rb
324
+ - lib/ruby_llm/agents/workflow/thread_pool.rb
171
325
  homepage: https://github.com/adham90/ruby_llm-agents
172
326
  licenses:
173
327
  - MIT
@@ -1,40 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "../cache_helper"
4
-
5
- module RubyLLM
6
- module Agents
7
- class Base
8
- # Cache management for agent responses
9
- #
10
- # Handles cache key generation and store access for
11
- # caching agent execution results.
12
- module Caching
13
- include CacheHelper
14
-
15
- # Generates the full cache key for this agent invocation
16
- #
17
- # @return [String] Cache key in format "ruby_llm_agent/ClassName/version/hash"
18
- def agent_cache_key
19
- ["ruby_llm_agent", self.class.name, self.class.version, cache_key_hash].join("/")
20
- end
21
-
22
- # Generates a hash of the cache key data
23
- #
24
- # @return [String] SHA256 hex digest of the cache key data
25
- def cache_key_hash
26
- Digest::SHA256.hexdigest(cache_key_data.to_json)
27
- end
28
-
29
- # Returns data to include in cache key generation
30
- #
31
- # Override to customize what parameters affect cache invalidation.
32
- #
33
- # @return [Hash] Data to hash for cache key
34
- def cache_key_data
35
- @options.except(:skip_cache, :dry_run, :with)
36
- end
37
- end
38
- end
39
- end
40
- end
@@ -1,105 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RubyLLM
4
- module Agents
5
- class Base
6
- # Cost calculation methods for token and pricing calculations
7
- #
8
- # Handles input/output cost calculations, model info resolution,
9
- # and budget tracking for agent executions.
10
- module CostCalculation
11
- # Calculates input cost from tokens
12
- #
13
- # @param input_tokens [Integer, nil] Number of input tokens
14
- # @param response_model_id [String, nil] Model that responded
15
- # @return [Float, nil] Input cost in USD
16
- def result_input_cost(input_tokens, response_model_id)
17
- return nil unless input_tokens
18
- model_info = result_model_info(response_model_id)
19
- return nil unless model_info&.pricing
20
- price = model_info.pricing.text_tokens&.input || 0
21
- (input_tokens / 1_000_000.0 * price).round(6)
22
- end
23
-
24
- # Calculates output cost from tokens
25
- #
26
- # @param output_tokens [Integer, nil] Number of output tokens
27
- # @param response_model_id [String, nil] Model that responded
28
- # @return [Float, nil] Output cost in USD
29
- def result_output_cost(output_tokens, response_model_id)
30
- return nil unless output_tokens
31
- model_info = result_model_info(response_model_id)
32
- return nil unless model_info&.pricing
33
- price = model_info.pricing.text_tokens&.output || 0
34
- (output_tokens / 1_000_000.0 * price).round(6)
35
- end
36
-
37
- # Calculates total cost from tokens
38
- #
39
- # @param input_tokens [Integer, nil] Number of input tokens
40
- # @param output_tokens [Integer, nil] Number of output tokens
41
- # @param response_model_id [String, nil] Model that responded
42
- # @return [Float, nil] Total cost in USD
43
- def result_total_cost(input_tokens, output_tokens, response_model_id)
44
- input_cost = result_input_cost(input_tokens, response_model_id)
45
- output_cost = result_output_cost(output_tokens, response_model_id)
46
- return nil unless input_cost || output_cost
47
- ((input_cost || 0) + (output_cost || 0)).round(6)
48
- end
49
-
50
- # Resolves model info for cost calculation
51
- #
52
- # @param response_model_id [String, nil] Model ID from response
53
- # @return [Object, nil] Model info or nil
54
- def result_model_info(response_model_id)
55
- lookup_id = response_model_id || model
56
- return nil unless lookup_id
57
- model_obj, _provider = RubyLLM::Models.resolve(lookup_id)
58
- model_obj
59
- rescue StandardError
60
- nil
61
- end
62
-
63
- # Resolves model info for cost calculation (alternate method)
64
- #
65
- # @param model_id [String] The model identifier
66
- # @return [Object, nil] Model info or nil
67
- def resolve_model_info(model_id)
68
- model_obj, _provider = RubyLLM::Models.resolve(model_id)
69
- model_obj
70
- rescue StandardError
71
- nil
72
- end
73
-
74
- # Records cost from an attempt to the budget tracker
75
- #
76
- # @param attempt_tracker [AttemptTracker] The attempt tracker
77
- # @param tenant_id [String, nil] Optional tenant identifier for multi-tenant tracking
78
- # @return [void]
79
- def record_attempt_cost(attempt_tracker, tenant_id: nil)
80
- successful = attempt_tracker.successful_attempt
81
- return unless successful
82
-
83
- # Calculate cost for this execution
84
- # Note: Full cost calculation happens in instrumentation, but we
85
- # record the spend here for budget tracking
86
- model_info = resolve_model_info(successful[:model_id])
87
- return unless model_info&.pricing
88
-
89
- input_tokens = successful[:input_tokens] || 0
90
- output_tokens = successful[:output_tokens] || 0
91
-
92
- input_price = model_info.pricing.text_tokens&.input || 0
93
- output_price = model_info.pricing.text_tokens&.output || 0
94
-
95
- total_cost = (input_tokens / 1_000_000.0 * input_price) +
96
- (output_tokens / 1_000_000.0 * output_price)
97
-
98
- BudgetTracker.record_spend!(self.class.name, total_cost, tenant_id: tenant_id)
99
- rescue StandardError => e
100
- Rails.logger.warn("[RubyLLM::Agents] Failed to record budget spend: #{e.message}")
101
- end
102
- end
103
- end
104
- end
105
- end