From aca28ce8cad7e4245035d06f0faa275d0a6d399b Mon Sep 17 00:00:00 2001 From: aakashb95 Date: Thu, 19 Mar 2026 16:29:38 +0530 Subject: [PATCH] Feat(captain): Auto-migrate v1 instructions Migrate legacy config['instructions'] into description on first use and set the v2_migrated flag. Also mark assistants as v2_migrated when the description is changed while the v2 feature flag is enabled. --- enterprise/app/models/captain/assistant.rb | 19 ++++++++++++++++++- .../captain/assistant/agent_runner_service.rb | 1 + 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/enterprise/app/models/captain/assistant.rb b/enterprise/app/models/captain/assistant.rb index 08bff5ef3..41ce70f4a 100644 --- a/enterprise/app/models/captain/assistant.rb +++ b/enterprise/app/models/captain/assistant.rb @@ -36,12 +36,14 @@ class Captain::Assistant < ApplicationRecord has_many :copilot_threads, dependent: :destroy_async has_many :scenarios, class_name: 'Captain::Scenario', dependent: :destroy_async - store_accessor :config, :temperature, :feature_faq, :feature_memory, :product_name + store_accessor :config, :temperature, :feature_faq, :feature_memory, :product_name, :v2_migrated validates :name, presence: true validates :description, presence: true validates :account_id, presence: true + before_save :mark_v2_migrated_on_v2_description_change + scope :ordered, -> { order(created_at: :desc) } scope :for_account, ->(account_id) { where(account_id: account_id) } @@ -85,8 +87,23 @@ class Captain::Assistant < ApplicationRecord } end + def migrate_v1_instructions_if_needed! + return if v2_migrated + return if config['instructions'].blank? + + update!(description: config['instructions'], v2_migrated: true) + end + private + def mark_v2_migrated_on_v2_description_change + return unless persisted? + return unless will_save_change_to_description? + return unless account&.feature_enabled?('captain_integration_v2') + + self.v2_migrated = true + end + def agent_name name.parameterize(separator: '_') end diff --git a/enterprise/app/services/captain/assistant/agent_runner_service.rb b/enterprise/app/services/captain/assistant/agent_runner_service.rb index 1875a9953..d7a128adb 100644 --- a/enterprise/app/services/captain/assistant/agent_runner_service.rb +++ b/enterprise/app/services/captain/assistant/agent_runner_service.rb @@ -27,6 +27,7 @@ class Captain::Assistant::AgentRunnerService end def generate_response(message_history: []) + @assistant.migrate_v1_instructions_if_needed! message_to_process, context = run_payload(message_history) result = runner.run(message_to_process, context: context, max_turns: 100)