ruby_llm-agents 1.3.4 → 2.1.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.
Files changed (191) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +112 -336
  3. data/app/controllers/concerns/ruby_llm/agents/sortable.rb +0 -1
  4. data/app/controllers/ruby_llm/agents/agents_controller.rb +5 -56
  5. data/app/controllers/ruby_llm/agents/dashboard_controller.rb +22 -106
  6. data/app/controllers/ruby_llm/agents/executions_controller.rb +4 -114
  7. data/app/controllers/ruby_llm/agents/tenants_controller.rb +30 -2
  8. data/app/helpers/ruby_llm/agents/application_helper.rb +19 -53
  9. data/app/models/ruby_llm/agents/execution/analytics.rb +13 -54
  10. data/app/models/ruby_llm/agents/execution/scopes.rb +61 -14
  11. data/app/models/ruby_llm/agents/execution.rb +52 -12
  12. data/app/models/ruby_llm/agents/execution_detail.rb +18 -0
  13. data/app/models/ruby_llm/agents/tenant/budgetable.rb +132 -24
  14. data/app/models/ruby_llm/agents/tenant/incrementable.rb +117 -0
  15. data/app/models/ruby_llm/agents/tenant/resettable.rb +128 -0
  16. data/app/models/ruby_llm/agents/tenant/trackable.rb +46 -12
  17. data/app/models/ruby_llm/agents/tenant.rb +2 -3
  18. data/app/models/ruby_llm/agents/tenant_budget.rb +6 -3
  19. data/app/services/ruby_llm/agents/agent_registry.rb +6 -112
  20. data/app/views/layouts/ruby_llm/agents/application.html.erb +89 -252
  21. data/app/views/ruby_llm/agents/agents/_config_agent.html.erb +71 -218
  22. data/app/views/ruby_llm/agents/agents/_config_embedder.html.erb +20 -63
  23. data/app/views/ruby_llm/agents/agents/_config_image_generator.html.erb +44 -131
  24. data/app/views/ruby_llm/agents/agents/_config_moderator.html.erb +16 -57
  25. data/app/views/ruby_llm/agents/agents/_config_speaker.html.erb +39 -104
  26. data/app/views/ruby_llm/agents/agents/_config_transcriber.html.erb +29 -82
  27. data/app/views/ruby_llm/agents/agents/_empty_state.html.erb +4 -14
  28. data/app/views/ruby_llm/agents/agents/index.html.erb +105 -274
  29. data/app/views/ruby_llm/agents/agents/show.html.erb +248 -378
  30. data/app/views/ruby_llm/agents/dashboard/_action_center.html.erb +29 -52
  31. data/app/views/ruby_llm/agents/dashboard/_tenant_budget.html.erb +73 -99
  32. data/app/views/ruby_llm/agents/dashboard/index.html.erb +228 -433
  33. data/app/views/ruby_llm/agents/executions/_execution.html.erb +1 -1
  34. data/app/views/ruby_llm/agents/executions/_filters.html.erb +4 -25
  35. data/app/views/ruby_llm/agents/executions/_list.html.erb +111 -152
  36. data/app/views/ruby_llm/agents/executions/index.html.erb +5 -7
  37. data/app/views/ruby_llm/agents/executions/show.html.erb +526 -1037
  38. data/app/views/ruby_llm/agents/shared/_agent_type_badge.html.erb +5 -21
  39. data/app/views/ruby_llm/agents/shared/_executions_table.html.erb +70 -191
  40. data/app/views/ruby_llm/agents/shared/_filter_dropdown.html.erb +16 -44
  41. data/app/views/ruby_llm/agents/shared/_select_dropdown.html.erb +12 -41
  42. data/app/views/ruby_llm/agents/shared/_status_badge.html.erb +11 -65
  43. data/app/views/ruby_llm/agents/shared/_tenant_filter.html.erb +6 -5
  44. data/app/views/ruby_llm/agents/system_config/show.html.erb +240 -351
  45. data/app/views/ruby_llm/agents/tenants/_form.html.erb +67 -77
  46. data/app/views/ruby_llm/agents/tenants/edit.html.erb +7 -9
  47. data/app/views/ruby_llm/agents/tenants/index.html.erb +100 -122
  48. data/app/views/ruby_llm/agents/tenants/show.html.erb +146 -336
  49. data/config/routes.rb +0 -13
  50. data/lib/generators/ruby_llm_agents/install_generator.rb +13 -17
  51. data/lib/generators/ruby_llm_agents/migrate_structure_generator.rb +2 -12
  52. data/lib/generators/ruby_llm_agents/restructure_generator.rb +0 -2
  53. data/lib/generators/ruby_llm_agents/templates/add_usage_counters_to_tenants_migration.rb.tt +37 -0
  54. data/lib/generators/ruby_llm_agents/templates/agent.rb.tt +1 -2
  55. data/lib/generators/ruby_llm_agents/templates/application_agent.rb.tt +1 -1
  56. data/lib/generators/ruby_llm_agents/templates/application_image_pipeline.rb.tt +0 -1
  57. data/lib/generators/ruby_llm_agents/templates/create_execution_details_migration.rb.tt +27 -0
  58. data/lib/generators/ruby_llm_agents/templates/create_tenants_migration.rb.tt +25 -0
  59. data/lib/generators/ruby_llm_agents/templates/image_pipeline.rb.tt +0 -1
  60. data/lib/generators/ruby_llm_agents/templates/initializer.rb.tt +33 -12
  61. data/lib/generators/ruby_llm_agents/templates/migration.rb.tt +40 -71
  62. data/lib/generators/ruby_llm_agents/templates/remove_agent_version_migration.rb.tt +13 -0
  63. data/lib/generators/ruby_llm_agents/templates/remove_workflow_columns_migration.rb.tt +19 -0
  64. data/lib/generators/ruby_llm_agents/templates/skills/AGENTS.md.tt +2 -4
  65. data/lib/generators/ruby_llm_agents/templates/skills/IMAGE_PIPELINES.md.tt +0 -1
  66. data/lib/generators/ruby_llm_agents/templates/split_execution_details_migration.rb.tt +232 -0
  67. data/lib/generators/ruby_llm_agents/upgrade_generator.rb +77 -259
  68. data/lib/ruby_llm/agents/audio/speaker.rb +0 -1
  69. data/lib/ruby_llm/agents/audio/transcriber.rb +0 -1
  70. data/lib/ruby_llm/agents/base_agent.rb +54 -23
  71. data/lib/ruby_llm/agents/core/base/callbacks.rb +142 -0
  72. data/lib/ruby_llm/agents/core/base.rb +23 -55
  73. data/lib/ruby_llm/agents/core/configuration.rb +97 -117
  74. data/lib/ruby_llm/agents/core/errors.rb +0 -58
  75. data/lib/ruby_llm/agents/core/instrumentation.rb +157 -110
  76. data/lib/ruby_llm/agents/core/llm_tenant.rb +8 -7
  77. data/lib/ruby_llm/agents/core/version.rb +1 -1
  78. data/lib/ruby_llm/agents/dsl/base.rb +157 -17
  79. data/lib/ruby_llm/agents/dsl/caching.rb +33 -2
  80. data/lib/ruby_llm/agents/dsl/reliability.rb +148 -0
  81. data/lib/ruby_llm/agents/dsl.rb +1 -2
  82. data/lib/ruby_llm/agents/image/analyzer/execution.rb +1 -2
  83. data/lib/ruby_llm/agents/image/background_remover/execution.rb +1 -2
  84. data/lib/ruby_llm/agents/image/concerns/image_operation_dsl.rb +1 -13
  85. data/lib/ruby_llm/agents/image/concerns/image_operation_execution.rb +2 -2
  86. data/lib/ruby_llm/agents/image/editor/dsl.rb +0 -14
  87. data/lib/ruby_llm/agents/image/editor/execution.rb +1 -10
  88. data/lib/ruby_llm/agents/image/editor.rb +0 -1
  89. data/lib/ruby_llm/agents/image/generator.rb +0 -21
  90. data/lib/ruby_llm/agents/image/pipeline/dsl.rb +0 -13
  91. data/lib/ruby_llm/agents/image/pipeline/execution.rb +0 -1
  92. data/lib/ruby_llm/agents/image/transformer/dsl.rb +0 -13
  93. data/lib/ruby_llm/agents/image/transformer/execution.rb +1 -10
  94. data/lib/ruby_llm/agents/image/transformer.rb +0 -1
  95. data/lib/ruby_llm/agents/image/upscaler/execution.rb +1 -2
  96. data/lib/ruby_llm/agents/image/variator/execution.rb +1 -2
  97. data/lib/ruby_llm/agents/infrastructure/alert_manager.rb +78 -173
  98. data/lib/ruby_llm/agents/infrastructure/budget/budget_query.rb +66 -2
  99. data/lib/ruby_llm/agents/infrastructure/budget/spend_recorder.rb +0 -12
  100. data/lib/ruby_llm/agents/infrastructure/circuit_breaker.rb +10 -13
  101. data/lib/ruby_llm/agents/infrastructure/execution_logger_job.rb +8 -0
  102. data/lib/ruby_llm/agents/pipeline/context.rb +0 -1
  103. data/lib/ruby_llm/agents/pipeline/middleware/budget.rb +28 -4
  104. data/lib/ruby_llm/agents/pipeline/middleware/cache.rb +3 -10
  105. data/lib/ruby_llm/agents/pipeline/middleware/instrumentation.rb +88 -55
  106. data/lib/ruby_llm/agents/pipeline/middleware/tenant.rb +5 -41
  107. data/lib/ruby_llm/agents/rails/engine.rb +6 -6
  108. data/lib/ruby_llm/agents/results/base.rb +1 -49
  109. data/lib/ruby_llm/agents/text/embedder.rb +0 -1
  110. data/lib/ruby_llm/agents.rb +1 -9
  111. data/lib/tasks/ruby_llm_agents.rake +34 -0
  112. metadata +14 -83
  113. data/app/controllers/ruby_llm/agents/api_configurations_controller.rb +0 -214
  114. data/app/controllers/ruby_llm/agents/workflows_controller.rb +0 -544
  115. data/app/mailers/ruby_llm/agents/alert_mailer.rb +0 -84
  116. data/app/mailers/ruby_llm/agents/application_mailer.rb +0 -28
  117. data/app/models/ruby_llm/agents/api_configuration.rb +0 -386
  118. data/app/models/ruby_llm/agents/execution/workflow.rb +0 -170
  119. data/app/models/ruby_llm/agents/tenant/configurable.rb +0 -135
  120. data/app/views/ruby_llm/agents/agents/_agent.html.erb +0 -98
  121. data/app/views/ruby_llm/agents/agents/_version_comparison.html.erb +0 -186
  122. data/app/views/ruby_llm/agents/agents/_workflow.html.erb +0 -126
  123. data/app/views/ruby_llm/agents/alert_mailer/alert_notification.html.erb +0 -107
  124. data/app/views/ruby_llm/agents/alert_mailer/alert_notification.text.erb +0 -18
  125. data/app/views/ruby_llm/agents/api_configurations/_api_key_field.html.erb +0 -34
  126. data/app/views/ruby_llm/agents/api_configurations/_form.html.erb +0 -288
  127. data/app/views/ruby_llm/agents/api_configurations/edit.html.erb +0 -95
  128. data/app/views/ruby_llm/agents/api_configurations/edit_tenant.html.erb +0 -97
  129. data/app/views/ruby_llm/agents/api_configurations/show.html.erb +0 -214
  130. data/app/views/ruby_llm/agents/api_configurations/tenant.html.erb +0 -179
  131. data/app/views/ruby_llm/agents/dashboard/_agent_comparison.html.erb +0 -73
  132. data/app/views/ruby_llm/agents/dashboard/_alerts_feed.html.erb +0 -62
  133. data/app/views/ruby_llm/agents/dashboard/_breaker_strip.html.erb +0 -47
  134. data/app/views/ruby_llm/agents/dashboard/_budgets_bar.html.erb +0 -75
  135. data/app/views/ruby_llm/agents/dashboard/_model_comparison.html.erb +0 -56
  136. data/app/views/ruby_llm/agents/dashboard/_model_cost_breakdown.html.erb +0 -115
  137. data/app/views/ruby_llm/agents/dashboard/_now_strip.html.erb +0 -59
  138. data/app/views/ruby_llm/agents/dashboard/_top_errors.html.erb +0 -60
  139. data/app/views/ruby_llm/agents/executions/_workflow_summary.html.erb +0 -86
  140. data/app/views/ruby_llm/agents/executions/dry_run.html.erb +0 -149
  141. data/app/views/ruby_llm/agents/shared/_breadcrumbs.html.erb +0 -48
  142. data/app/views/ruby_llm/agents/shared/_nav_link.html.erb +0 -27
  143. data/app/views/ruby_llm/agents/shared/_stat_card.html.erb +0 -14
  144. data/app/views/ruby_llm/agents/shared/_workflow_type_badge.html.erb +0 -35
  145. data/app/views/ruby_llm/agents/workflows/_empty_state.html.erb +0 -22
  146. data/app/views/ruby_llm/agents/workflows/_step_performance.html.erb +0 -228
  147. data/app/views/ruby_llm/agents/workflows/_structure_dsl.html.erb +0 -539
  148. data/app/views/ruby_llm/agents/workflows/_structure_parallel.html.erb +0 -76
  149. data/app/views/ruby_llm/agents/workflows/_structure_pipeline.html.erb +0 -74
  150. data/app/views/ruby_llm/agents/workflows/_structure_router.html.erb +0 -108
  151. data/app/views/ruby_llm/agents/workflows/_workflow_diagram.html.erb +0 -920
  152. data/app/views/ruby_llm/agents/workflows/index.html.erb +0 -179
  153. data/app/views/ruby_llm/agents/workflows/show.html.erb +0 -467
  154. data/lib/generators/ruby_llm_agents/api_configuration_generator.rb +0 -100
  155. data/lib/generators/ruby_llm_agents/templates/add_workflow_migration.rb.tt +0 -38
  156. data/lib/generators/ruby_llm_agents/templates/application_workflow.rb.tt +0 -48
  157. data/lib/generators/ruby_llm_agents/templates/create_api_configurations_migration.rb.tt +0 -90
  158. data/lib/generators/ruby_llm_agents/templates/skills/WORKFLOWS.md.tt +0 -551
  159. data/lib/ruby_llm/agents/core/base/moderation_dsl.rb +0 -181
  160. data/lib/ruby_llm/agents/core/base/moderation_execution.rb +0 -274
  161. data/lib/ruby_llm/agents/core/resolved_config.rb +0 -348
  162. data/lib/ruby_llm/agents/image/generator/content_policy.rb +0 -95
  163. data/lib/ruby_llm/agents/infrastructure/redactor.rb +0 -130
  164. data/lib/ruby_llm/agents/results/moderation_result.rb +0 -158
  165. data/lib/ruby_llm/agents/text/moderator.rb +0 -237
  166. data/lib/ruby_llm/agents/workflow/approval.rb +0 -205
  167. data/lib/ruby_llm/agents/workflow/approval_store.rb +0 -179
  168. data/lib/ruby_llm/agents/workflow/async.rb +0 -220
  169. data/lib/ruby_llm/agents/workflow/async_executor.rb +0 -156
  170. data/lib/ruby_llm/agents/workflow/dsl/executor.rb +0 -467
  171. data/lib/ruby_llm/agents/workflow/dsl/input_schema.rb +0 -244
  172. data/lib/ruby_llm/agents/workflow/dsl/iteration_executor.rb +0 -289
  173. data/lib/ruby_llm/agents/workflow/dsl/parallel_group.rb +0 -107
  174. data/lib/ruby_llm/agents/workflow/dsl/route_builder.rb +0 -150
  175. data/lib/ruby_llm/agents/workflow/dsl/schedule_helpers.rb +0 -187
  176. data/lib/ruby_llm/agents/workflow/dsl/step_config.rb +0 -352
  177. data/lib/ruby_llm/agents/workflow/dsl/step_executor.rb +0 -415
  178. data/lib/ruby_llm/agents/workflow/dsl/wait_config.rb +0 -257
  179. data/lib/ruby_llm/agents/workflow/dsl/wait_executor.rb +0 -317
  180. data/lib/ruby_llm/agents/workflow/dsl.rb +0 -576
  181. data/lib/ruby_llm/agents/workflow/instrumentation.rb +0 -249
  182. data/lib/ruby_llm/agents/workflow/notifiers/base.rb +0 -117
  183. data/lib/ruby_llm/agents/workflow/notifiers/email.rb +0 -117
  184. data/lib/ruby_llm/agents/workflow/notifiers/slack.rb +0 -180
  185. data/lib/ruby_llm/agents/workflow/notifiers/webhook.rb +0 -121
  186. data/lib/ruby_llm/agents/workflow/notifiers.rb +0 -70
  187. data/lib/ruby_llm/agents/workflow/orchestrator.rb +0 -416
  188. data/lib/ruby_llm/agents/workflow/result.rb +0 -592
  189. data/lib/ruby_llm/agents/workflow/thread_pool.rb +0 -185
  190. data/lib/ruby_llm/agents/workflow/throttle_manager.rb +0 -206
  191. data/lib/ruby_llm/agents/workflow/wait_result.rb +0 -213
@@ -1,100 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "rails/generators"
4
- require "rails/generators/active_record"
5
-
6
- module RubyLlmAgents
7
- # API Configuration generator for ruby_llm-agents
8
- #
9
- # Usage:
10
- # rails generate ruby_llm_agents:api_configuration
11
- #
12
- # This will create migrations for:
13
- # - ruby_llm_agents_api_configurations table for storing API keys and settings
14
- #
15
- # API keys are encrypted at rest using Rails encrypted attributes.
16
- # Supports both global configuration and per-tenant overrides.
17
- #
18
- class ApiConfigurationGenerator < ::Rails::Generators::Base
19
- include ::ActiveRecord::Generators::Migration
20
-
21
- source_root File.expand_path("templates", __dir__)
22
-
23
- desc "Adds database-backed API configuration support to RubyLLM::Agents"
24
-
25
- def create_api_configurations_migration
26
- if table_exists?(:ruby_llm_agents_api_configurations)
27
- say_status :skip, "ruby_llm_agents_api_configurations table already exists", :yellow
28
- return
29
- end
30
-
31
- migration_template(
32
- "create_api_configurations_migration.rb.tt",
33
- File.join(db_migrate_path, "create_ruby_llm_agents_api_configurations.rb")
34
- )
35
- end
36
-
37
- def show_post_install_message
38
- say ""
39
- say "API Configuration migration created!", :green
40
- say ""
41
- say "Next steps:"
42
- say " 1. Ensure Rails encryption is configured (if not already):"
43
- say ""
44
- say " bin/rails db:encryption:init"
45
- say ""
46
- say " Then add the generated keys to your credentials or environment."
47
- say ""
48
- say " 2. Run the migration:"
49
- say ""
50
- say " rails db:migrate"
51
- say ""
52
- say " 3. Access the API Configuration UI:"
53
- say ""
54
- say " Navigate to /agents/api_configuration in your browser"
55
- say ""
56
- say " 4. (Optional) Configure API keys programmatically:"
57
- say ""
58
- say " # Set global configuration"
59
- say " config = RubyLLM::Agents::ApiConfiguration.global"
60
- say " config.update!("
61
- say " openai_api_key: 'sk-...',"
62
- say " anthropic_api_key: 'sk-ant-...'"
63
- say " )"
64
- say ""
65
- say " # Set tenant-specific configuration"
66
- say " tenant_config = RubyLLM::Agents::ApiConfiguration.for_tenant!('acme_corp')"
67
- say " tenant_config.update!("
68
- say " openai_api_key: 'sk-tenant-specific-key',"
69
- say " inherit_global_defaults: true"
70
- say " )"
71
- say ""
72
- say "Configuration Resolution Priority:"
73
- say " 1. Per-tenant database configuration (if multi-tenancy enabled)"
74
- say " 2. Global database configuration"
75
- say " 3. RubyLLM.configure block settings"
76
- say ""
77
- say "Security Notes:"
78
- say " - API keys are encrypted at rest using Rails encrypted attributes"
79
- say " - Keys are masked in the UI (e.g., sk-ab****wxyz)"
80
- say " - Dashboard authentication inherits from your authenticate_dashboard! method"
81
- say ""
82
- end
83
-
84
- private
85
-
86
- def migration_version
87
- "[#{::ActiveRecord::VERSION::STRING.to_f}]"
88
- end
89
-
90
- def db_migrate_path
91
- "db/migrate"
92
- end
93
-
94
- def table_exists?(table)
95
- ActiveRecord::Base.connection.table_exists?(table)
96
- rescue StandardError
97
- false
98
- end
99
- end
100
- end
@@ -1,38 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Migration to add workflow orchestration columns to executions
4
- #
5
- # This migration adds columns for tracking workflow executions (Pipeline,
6
- # Parallel, Router patterns) and linking child executions to their
7
- # parent workflow.
8
- #
9
- # Workflow patterns supported:
10
- # - Pipeline: Sequential execution with data flowing between steps
11
- # - Parallel: Concurrent execution with result aggregation
12
- # - Router: Conditional dispatch based on classification
13
- #
14
- # Run with: rails db:migrate
15
- class AddWorkflowToRubyLLMAgentsExecutions < ActiveRecord::Migration<%= migration_version %>
16
- def change
17
- # Unique identifier for the workflow execution
18
- # All steps/branches share the same workflow_id
19
- add_column :ruby_llm_agents_executions, :workflow_id, :string
20
-
21
- # Type of workflow: "pipeline", "parallel", "router", or nil for regular agents
22
- add_column :ruby_llm_agents_executions, :workflow_type, :string
23
-
24
- # Name of the step/branch within the workflow
25
- add_column :ruby_llm_agents_executions, :workflow_step, :string
26
-
27
- # For routers: the route that was selected
28
- add_column :ruby_llm_agents_executions, :routed_to, :string
29
-
30
- # For routers: classification details (route, method, time)
31
- add_column :ruby_llm_agents_executions, :classification_result, :json
32
-
33
- # Add indexes for efficient querying
34
- add_index :ruby_llm_agents_executions, :workflow_id
35
- add_index :ruby_llm_agents_executions, :workflow_type
36
- add_index :ruby_llm_agents_executions, [:workflow_id, :workflow_step]
37
- end
38
- end
@@ -1,48 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # ApplicationWorkflow - Base class for all workflows in this application
4
- #
5
- # All workflows inherit from this class. Configure shared settings here
6
- # that apply to all workflows, or override them per-workflow as needed.
7
- #
8
- # Workflows compose multiple agents into pipelines, parallel executions,
9
- # or conditional routing flows.
10
- #
11
- # Example:
12
- # class ContentPipelineWorkflow < ApplicationWorkflow
13
- # description "Process and publish content"
14
- #
15
- # step :moderate, agent: Moderators::ContentModerator
16
- # step :generate_image, agent: Images::ProductGenerator
17
- # step :embed, agent: Embedders::SemanticEmbedder
18
- # end
19
- #
20
- # Usage:
21
- # ContentPipelineWorkflow.call(content: "...")
22
- #
23
- class ApplicationWorkflow < RubyLLM::Agents::Workflow::Orchestrator
24
- # ============================================
25
- # Shared Workflow Configuration
26
- # ============================================
27
-
28
- # Default timeout for entire workflow
29
- # total_timeout 120
30
-
31
- # Budget tracking
32
- # budget_limit 1.0 # Maximum spend in dollars
33
-
34
- # ============================================
35
- # Shared Helper Methods
36
- # ============================================
37
-
38
- # Example: Common error handling
39
- # def on_step_error(step_name, error)
40
- # Rails.logger.error "Workflow step #{step_name} failed: #{error.message}"
41
- # # Optionally notify monitoring
42
- # end
43
-
44
- # Example: Common success callback
45
- # def on_complete(result)
46
- # Rails.logger.info "Workflow completed successfully"
47
- # end
48
- end
@@ -1,90 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Migration to create the api_configurations table
4
- #
5
- # This table stores API key configurations that can be managed via the dashboard.
6
- # Supports both global settings and per-tenant overrides.
7
- #
8
- # Resolution priority: per-tenant DB > global DB > config file (RubyLLM.configure)
9
- #
10
- # Features:
11
- # - Encrypted storage for all API keys (using Rails encrypted attributes)
12
- # - Support for all major LLM providers
13
- # - Custom endpoint configuration
14
- # - Connection settings
15
- # - Default model configuration
16
- #
17
- # Run with: rails db:migrate
18
- class CreateRubyLLMAgentsApiConfigurations < ActiveRecord::Migration<%= migration_version %>
19
- def change
20
- create_table :ruby_llm_agents_api_configurations do |t|
21
- # Scope type: 'global' or 'tenant'
22
- t.string :scope_type, null: false, default: 'global'
23
- # Tenant ID when scope_type='tenant'
24
- t.string :scope_id
25
-
26
- # === Encrypted API Keys ===
27
- # Rails encrypts stores encrypted data in the same-named column
28
- # Primary providers
29
- t.text :openai_api_key
30
- t.text :anthropic_api_key
31
- t.text :gemini_api_key
32
-
33
- # Additional providers
34
- t.text :deepseek_api_key
35
- t.text :mistral_api_key
36
- t.text :perplexity_api_key
37
- t.text :openrouter_api_key
38
- t.text :gpustack_api_key
39
- t.text :xai_api_key
40
- t.text :ollama_api_key
41
-
42
- # AWS Bedrock
43
- t.text :bedrock_api_key
44
- t.text :bedrock_secret_key
45
- t.text :bedrock_session_token
46
- t.string :bedrock_region
47
-
48
- # Google Vertex AI
49
- t.text :vertexai_credentials
50
- t.string :vertexai_project_id
51
- t.string :vertexai_location
52
-
53
- # === Custom Endpoints ===
54
- t.string :openai_api_base
55
- t.string :gemini_api_base
56
- t.string :ollama_api_base
57
- t.string :gpustack_api_base
58
- t.string :xai_api_base
59
-
60
- # === OpenAI Options ===
61
- t.string :openai_organization_id
62
- t.string :openai_project_id
63
-
64
- # === Default Models ===
65
- t.string :default_model
66
- t.string :default_embedding_model
67
- t.string :default_image_model
68
- t.string :default_moderation_model
69
-
70
- # === Connection Settings ===
71
- t.integer :request_timeout
72
- t.integer :max_retries
73
- t.decimal :retry_interval, precision: 5, scale: 2
74
- t.decimal :retry_backoff_factor, precision: 5, scale: 2
75
- t.decimal :retry_interval_randomness, precision: 5, scale: 2
76
- t.string :http_proxy
77
-
78
- # Whether to inherit from global config for unset values
79
- t.boolean :inherit_global_defaults, default: true
80
-
81
- t.timestamps
82
- end
83
-
84
- # Ensure unique scope_type + scope_id combinations
85
- add_index :ruby_llm_agents_api_configurations, [:scope_type, :scope_id], unique: true, name: 'idx_api_configs_scope'
86
-
87
- # Index for faster tenant lookups
88
- add_index :ruby_llm_agents_api_configurations, :scope_id, name: 'idx_api_configs_scope_id'
89
- end
90
- end