From 802465f6d615c97d337a2bba0068831adec3f053 Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Wed, 2 Jul 2025 20:32:44 +0530 Subject: [PATCH] feat: setup ai agents --- Gemfile | 2 ++ Gemfile.lock | 12 ++++++++++++ config/initializers/ai_agents.rb | 26 ++++++++++++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 config/initializers/ai_agents.rb diff --git a/Gemfile b/Gemfile index b4752c745..415be2b56 100644 --- a/Gemfile +++ b/Gemfile @@ -180,6 +180,8 @@ gem 'ruby-openai' gem 'shopify_api' +gem 'ai-agents' + ### Gems required only in specific deployment environments ### ############################################################## diff --git a/Gemfile.lock b/Gemfile.lock index 8315a5374..5961a771f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) diff --git a/config/initializers/ai_agents.rb b/config/initializers/ai_agents.rb new file mode 100644 index 000000000..0b39c701d --- /dev/null +++ b/config/initializers/ai_agents.rb @@ -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