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.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user