# Pull Request Template ## Description Tightens v2 prompt and config to match v1 ## Type of change Please delete options that are not relevant. - [x] Bug fix (non-breaking change which fixes an issue) ## How Has This Been Tested? Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration. locally ## Checklist: - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my code - [x] I have commented on my code, particularly in hard-to-understand areas - [] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [x] Any dependent changes have been merged and published in downstream modules
71 lines
1.8 KiB
Ruby
71 lines
1.8 KiB
Ruby
module Concerns::Agentable
|
|
extend ActiveSupport::Concern
|
|
|
|
def agent
|
|
Agents::Agent.new(
|
|
name: agent_name,
|
|
instructions: ->(context) { agent_instructions(context) },
|
|
tools: agent_tools,
|
|
model: agent_model,
|
|
temperature: temperature.to_f || 0.7,
|
|
response_schema: agent_response_schema
|
|
)
|
|
end
|
|
|
|
def agent_instructions(context = nil)
|
|
enhanced_context = prompt_context
|
|
|
|
if context
|
|
state = context.context[:state] || {}
|
|
config = state[:assistant_config] || {}
|
|
enhanced_context = enhanced_context.merge(
|
|
current_time: format_current_time(state[:timezone]),
|
|
conversation: state[:conversation] || {},
|
|
contact: config['feature_contact_attributes'].present? ? state[:contact] : nil,
|
|
campaign: state[:campaign] || {}
|
|
)
|
|
end
|
|
|
|
Captain::PromptRenderer.render(template_name, enhanced_context.with_indifferent_access)
|
|
end
|
|
|
|
private
|
|
|
|
def agent_name
|
|
raise NotImplementedError, "#{self.class} must implement agent_name"
|
|
end
|
|
|
|
def template_name
|
|
self.class.name.demodulize.underscore
|
|
end
|
|
|
|
def agent_tools
|
|
[] # Default implementation, override if needed
|
|
end
|
|
|
|
def agent_model
|
|
route = Llm::FeatureRouter.resolve(feature: 'assistant', account: account)
|
|
return route[:model] if route[:source] == :account_override
|
|
|
|
installation_model.presence || route[:model]
|
|
end
|
|
|
|
def installation_model
|
|
InstallationConfig.find_by(name: 'CAPTAIN_OPEN_AI_MODEL')&.value
|
|
end
|
|
|
|
def agent_response_schema
|
|
Captain::ResponseSchema
|
|
end
|
|
|
|
def format_current_time(timezone)
|
|
tz = ActiveSupport::TimeZone[timezone] if timezone.present?
|
|
time = tz ? Time.current.in_time_zone(tz) : Time.current
|
|
time.strftime('%A, %B %d, %Y %I:%M %p %Z')
|
|
end
|
|
|
|
def prompt_context
|
|
raise NotImplementedError, "#{self.class} must implement prompt_context"
|
|
end
|
|
end
|