feat: setup ai agents

This commit is contained in:
Shivam Mishra
2025-07-02 20:33:23 +05:30
parent 19d8f6bac5
commit 802465f6d6
3 changed files with 40 additions and 0 deletions
+2
View File
@@ -180,6 +180,8 @@ gem 'ruby-openai'
gem 'shopify_api'
gem 'ai-agents'
### Gems required only in specific deployment environments ###
##############################################################
+12
View File
@@ -126,6 +126,8 @@ GEM
jbuilder (~> 2)
rails (>= 4.2, < 7.2)
selectize-rails (~> 0.6)
ai-agents (0.1.3)
ruby_llm (~> 1.3)
annotate (3.2.0)
activerecord (>= 3.2, < 8.0)
rake (>= 10.4, < 14.0)
@@ -717,6 +719,15 @@ GEM
ruby2ruby (2.5.0)
ruby_parser (~> 3.1)
sexp_processor (~> 4.6)
ruby_llm (1.3.1)
base64
event_stream_parser (~> 1)
faraday (>= 1.10.0)
faraday-multipart (>= 1)
faraday-net_http (>= 1)
faraday-retry (>= 1)
marcel (~> 1.0)
zeitwerk (~> 2)
ruby_parser (3.20.0)
sexp_processor (~> 4.16)
sass (3.7.4)
@@ -895,6 +906,7 @@ DEPENDENCIES
administrate (>= 0.20.1)
administrate-field-active_storage (>= 1.0.3)
administrate-field-belongs_to_search (>= 0.9.0)
ai-agents
annotate
attr_extras
audited (~> 5.4, >= 5.4.1)
+26
View File
@@ -0,0 +1,26 @@
# frozen_string_literal: true
# Load AI Agents SDK
begin
require 'agents'
rescue LoadError => e
Rails.logger.warn "AI Agents SDK not available: #{e.message}"
end
# Configure AI Agents SDK
if defined?(Agents)
Rails.application.config.after_initialize do
api_key = InstallationConfig.find_by(name: 'CAPTAIN_OPEN_AI_API_KEY')&.value
model = InstallationConfig.find_by(name: 'CAPTAIN_OPEN_AI_MODEL')&.value || 'gpt-4o-mini'
if api_key.present?
Agents.configure do |config|
config.openai_api_key = api_key
config.default_model = model
config.debug = true
end
end
rescue StandardError => e
Rails.logger.error "Failed to configure AI Agents SDK: #{e.message}"
end
end