Class: LanguageOperator::Agent::PromptBuilder
- Inherits:
-
Object
- Object
- LanguageOperator::Agent::PromptBuilder
- Includes:
- Loggable
- Defined in:
- lib/language_operator/agent/prompt_builder.rb
Overview
Dynamic Prompt Builder
Generates persona-driven system prompts by combining static persona configuration with dynamic agent metadata and operational context.
Supports multiple template styles and configurable levels of context injection. Falls back to static prompts for backward compatibility.
Constant Summary collapse
- TEMPLATE_LEVELS =
Template levels for different amounts of context injection
{ minimal: :build_minimal_template, standard: :build_standard_template, detailed: :build_detailed_template, comprehensive: :build_comprehensive_template }.freeze
Instance Attribute Summary collapse
-
#agent ⇒ Object
readonly
Returns the value of attribute agent.
-
#chat_config ⇒ Object
readonly
Returns the value of attribute chat_config.
-
#metadata_collector ⇒ Object
readonly
Returns the value of attribute metadata_collector.
Instance Method Summary collapse
-
#build_conversation_context ⇒ String
Build prompt for conversation context (shorter version).
-
#build_system_prompt ⇒ String
Build complete system prompt with persona and context.
-
#initialize(agent, chat_config, **options) ⇒ PromptBuilder
constructor
Initialize prompt builder.
Methods included from Loggable
Constructor Details
#initialize(agent, chat_config, **options) ⇒ PromptBuilder
Initialize prompt builder
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/language_operator/agent/prompt_builder.rb', line 43 def initialize(agent, chat_config, **) @agent = agent @chat_config = chat_config @options = @metadata_collector = MetadataCollector.new(agent) # Configuration @template_level = [:template] || chat_config&.prompt_template_level || :standard @identity_awareness_enabled = if .key?(:enable_identity_awareness) [:enable_identity_awareness] elsif chat_config&.identity_awareness_enabled.nil? true else chat_config.identity_awareness_enabled end @static_prompt = chat_config&.system_prompt end |
Instance Attribute Details
#agent ⇒ Object (readonly)
Returns the value of attribute agent.
26 27 28 |
# File 'lib/language_operator/agent/prompt_builder.rb', line 26 def agent @agent end |
#chat_config ⇒ Object (readonly)
Returns the value of attribute chat_config.
26 27 28 |
# File 'lib/language_operator/agent/prompt_builder.rb', line 26 def chat_config @chat_config end |
#metadata_collector ⇒ Object (readonly)
Returns the value of attribute metadata_collector.
26 27 28 |
# File 'lib/language_operator/agent/prompt_builder.rb', line 26 def @metadata_collector end |
Instance Method Details
#build_conversation_context ⇒ String
Build prompt for conversation context (shorter version)
90 91 92 93 94 95 96 97 98 |
# File 'lib/language_operator/agent/prompt_builder.rb', line 90 def build_conversation_context return nil unless @identity_awareness_enabled = @metadata_collector.summary_for_prompt build_conversation_context_template() rescue StandardError => e logger.error('Failed to build conversation context', error: e.) nil end |
#build_system_prompt ⇒ String
Build complete system prompt with persona and context
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/language_operator/agent/prompt_builder.rb', line 64 def build_system_prompt # Return static prompt if identity awareness is disabled unless @identity_awareness_enabled return @static_prompt || build_fallback_prompt end # Collect metadata for context injection = @metadata_collector.summary_for_prompt # Build dynamic prompt based on template level if TEMPLATE_LEVELS.key?(@template_level) method_name = TEMPLATE_LEVELS[@template_level] send(method_name, ) else logger.warn("Unknown template level: #{@template_level}, falling back to standard") build_standard_template() end rescue StandardError => e logger.error('Failed to build dynamic system prompt, falling back to static', error: e.) @static_prompt || build_fallback_prompt end |