Class: Ace::LLM::Molecules::RoleResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/llm/molecules/role_resolver.rb

Overview

RoleResolver maps role names to an available concrete selector.

Constant Summary collapse

THINKING_LEVELS =
%w[low medium high xhigh].freeze

Instance Method Summary collapse

Constructor Details

#initialize(registry: nil, configuration: nil) ⇒ RoleResolver

Returns a new instance of RoleResolver.



13
14
15
16
# File 'lib/ace/llm/molecules/role_resolver.rb', line 13

def initialize(registry: nil, configuration: nil)
  @registry = registry || ClientRegistry.new
  @configuration = configuration || Ace::LLM.configuration
end

Instance Method Details

#resolve(role_name) ⇒ String

Resolve role name to first available candidate selector string.

Parameters:

  • role_name (String)

Returns:

  • (String)


21
22
23
24
# File 'lib/ace/llm/molecules/role_resolver.rb', line 21

def resolve(role_name)
  selector, _remaining = resolve_with_candidates(role_name)
  selector
end

#resolve_with_candidates(role_name) ⇒ Array(String, Array<String>)

Resolve role name and return both the selected candidate and remaining candidates. Remaining candidates can be used as a fallback chain at query time.

Parameters:

  • role_name (String)

Returns:

  • (Array(String, Array<String>))
    resolved_selector, remaining_candidates

Raises:



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/ace/llm/molecules/role_resolver.rb', line 30

def resolve_with_candidates(role_name)
  normalized_role_name = role_name.to_s.strip
  if normalized_role_name.empty?
    raise Ace::LLM::ConfigurationError, "Invalid target: role name cannot be empty"
  end

  role_config = Models::RoleConfig.from_hash(@configuration.get("llm.roles"))
  candidates = role_config.candidates_for(normalized_role_name)
  unless candidates
    available = role_config.role_names
    available_display = available.empty? ? "(none)" : available.join(", ")
    raise Ace::LLM::ConfigurationError,
      "Unknown role: #{normalized_role_name}. Defined roles: #{available_display}"
  end

  candidates.each_with_index do |candidate, index|
    if candidate_available?(candidate)
      remaining = candidates[(index + 1)..]
      return [candidate, remaining]
    end
  end

  raise Ace::LLM::ConfigurationError,
    "No available models for role '#{normalized_role_name}'. Tried: #{candidates.join(", ")}"
end