Class: Agentic::Extension::DomainAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/agentic/extension/domain_adapter.rb

Overview

The DomainAdapter integrates domain-specific knowledge into the general agent framework. It provides mechanisms for adapting prompts, tasks, and verification strategies to specific domains like healthcare, finance, legal, etc.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(domain, options = {}) ⇒ DomainAdapter

Initialize a new DomainAdapter

Options Hash (options):

  • :logger (Logger)

    Custom logger instance

  • :domain_config (Hash)

    Domain-specific configuration



15
16
17
18
19
20
21
22
23
# File 'lib/agentic/extension/domain_adapter.rb', line 15

def initialize(domain, options = {})
  @domain = domain
  @logger = options[:logger] || Agentic.logger
  @domain_config = options[:domain_config] || {}
  @adapters = {}
  @domain_knowledge = {}

  initialize_default_adapters
end

Instance Attribute Details

#domainString (readonly)

Get the domain identifier



86
87
88
# File 'lib/agentic/extension/domain_adapter.rb', line 86

def domain
  @domain
end

Instance Method Details

#adapt(component, target, context = {}) ⇒ Object

Apply domain-specific adaptation to a component



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/agentic/extension/domain_adapter.rb', line 59

def adapt(component, target, context = {})
  return target unless @adapters.key?(component)

  adapter = @adapters[component]
  context = context.merge(domain: @domain, domain_knowledge: @domain_knowledge)

  begin
    result = adapter.call(target, context)
    @logger.debug("Applied #{@domain} domain adaptation to #{component}")
    result
  rescue => e
    @logger.error("Failed to apply #{@domain} domain adaptation to #{component}: #{e.message}")
    target # Return original if adaptation fails
  end
end

#add_knowledge(key, knowledge) ⇒ Object

Add domain-specific knowledge



41
42
43
# File 'lib/agentic/extension/domain_adapter.rb', line 41

def add_knowledge(key, knowledge)
  @domain_knowledge[key] = knowledge
end

#configurationHash

Get domain configuration



91
92
93
# File 'lib/agentic/extension/domain_adapter.rb', line 91

def configuration
  @domain_config
end

#get_knowledge(key) ⇒ Object?

Get domain-specific knowledge



49
50
51
# File 'lib/agentic/extension/domain_adapter.rb', line 49

def get_knowledge(key)
  @domain_knowledge[key]
end

#register_adapter(component, adapter) ⇒ Boolean

Register an adapter for a specific component



30
31
32
33
34
35
# File 'lib/agentic/extension/domain_adapter.rb', line 30

def register_adapter(component, adapter)
  return false unless adapter.respond_to?(:call)

  @adapters[component] = adapter
  true
end

#supports?(component) ⇒ Boolean

Check if the adapter supports a specific component



79
80
81
# File 'lib/agentic/extension/domain_adapter.rb', line 79

def supports?(component)
  @adapters.key?(component)
end