Class: Aidp::Harness::ModelRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/aidp/harness/model_registry.rb

Overview

ModelRegistry manages the static registry of known model families and their tier classifications

The registry uses model families (e.g., “claude-3-5-sonnet”) rather than specific versioned model IDs (e.g., “claude-3-5-sonnet-20241022”). This design provides:

- No version tracking burden - registry tracks families, not every dated version
- Future-proofing - new model versions automatically inherit family tier
- Provider autonomy - each provider handles version-specific naming

Usage:

registry = ModelRegistry.new
registry.get_model_info("claude-3-5-sonnet")
# => { name: "Claude 3.5 Sonnet", tier: "standard", ... }

registry.models_for_tier("standard")
# => ["claude-3-5-sonnet", "gpt-4-turbo", ...]

registry.match_to_family("claude-3-5-sonnet-20241022")
# => "claude-3-5-sonnet"

Defined Under Namespace

Classes: InvalidRegistrySchema, ModelNotFound, RegistryError

Constant Summary collapse

VALID_TIERS =
%w[mini standard advanced].freeze
VALID_CAPABILITIES =
%w[chat code vision tool_use streaming json_mode].freeze
VALID_SPEEDS =
%w[very_fast fast medium slow].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(registry_path: nil) ⇒ ModelRegistry

Returns a new instance of ModelRegistry.



37
38
39
40
41
42
# File 'lib/aidp/harness/model_registry.rb', line 37

def initialize(registry_path: nil)
  @registry_path = registry_path || default_registry_path
  @registry_data = load_static_registry
  validate_registry_schema
  Aidp.log_debug("model_registry", "initialized", models: @registry_data["model_families"].keys.size)
end

Instance Attribute Details

#registry_dataObject (readonly)

Returns the value of attribute registry_data.



35
36
37
# File 'lib/aidp/harness/model_registry.rb', line 35

def registry_data
  @registry_data
end

Instance Method Details

#all_familiesArray<String>

Get all registered model families

Returns:

  • (Array<String>)

    List of all model family names



121
122
123
# File 'lib/aidp/harness/model_registry.rb', line 121

def all_families
  @registry_data["model_families"].keys
end

#available_tiersArray<String>

Get all tiers that have at least one model

Returns:

  • (Array<String>)

    List of tier names



136
137
138
# File 'lib/aidp/harness/model_registry.rb', line 136

def available_tiers
  @registry_data["model_families"].values.map { |info| info["tier"] }.uniq.sort
end

#classify_model_tier(family_name) ⇒ String?

Classify a model family’s tier

Parameters:

  • family_name (String)

    The model family name

Returns:

  • (String, nil)

    The tier name or nil if not found



78
79
80
81
82
83
# File 'lib/aidp/harness/model_registry.rb', line 78

def classify_model_tier(family_name)
  info = get_model_info(family_name)
  tier = info&.fetch("tier", nil)
  Aidp.log_debug("model_registry", "classified tier", family: family_name, tier: tier)
  tier
end

#family_exists?(family_name) ⇒ Boolean

Check if a model family exists in the registry

Parameters:

  • family_name (String)

    The model family name

Returns:

  • (Boolean)

    True if the family exists



129
130
131
# File 'lib/aidp/harness/model_registry.rb', line 129

def family_exists?(family_name)
  @registry_data["model_families"].key?(family_name)
end

#get_model_info(family_name) ⇒ Hash?

Get complete model information for a family

Parameters:

  • family_name (String)

    The model family name (e.g., “claude-3-5-sonnet”)

Returns:

  • (Hash, nil)

    Model metadata hash or nil if not found



48
49
50
51
52
53
# File 'lib/aidp/harness/model_registry.rb', line 48

def get_model_info(family_name)
  info = @registry_data["model_families"][family_name]
  return nil unless info

  info.merge("family" => family_name)
end

#match_to_family(versioned_name) ⇒ String?

Match a versioned model name to its family using pattern matching

This method attempts to normalize versioned model names (e.g., “claude-3-5-sonnet-20241022”) to their family name (e.g., “claude-3-5-sonnet”) by testing against version_pattern regexes.

Parameters:

  • versioned_name (String)

    The versioned model name

Returns:

  • (String, nil)

    The family name if matched, nil otherwise



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/aidp/harness/model_registry.rb', line 92

def match_to_family(versioned_name)
  @registry_data["model_families"].each do |family, info|
    pattern = info["version_pattern"]
    next unless pattern

    begin
      regex = Regexp.new("^#{pattern}$")
      if regex.match?(versioned_name)
        Aidp.log_debug("model_registry", "matched to family", versioned: versioned_name, family: family)
        return family
      end
    rescue RegexpError => e
      Aidp.log_error("model_registry", "invalid pattern", family: family, pattern: pattern, error: e.message)
    end
  end

  # If no pattern matches, check if the versioned_name is itself a family
  if @registry_data["model_families"].key?(versioned_name)
    Aidp.log_debug("model_registry", "exact family match", name: versioned_name)
    return versioned_name
  end

  Aidp.log_debug("model_registry", "no family match", versioned: versioned_name)
  nil
end

#models_for_tier(tier) ⇒ Array<String>

Get all model families for a specific tier

Parameters:

  • tier (String, Symbol)

    The tier name (mini, standard, advanced)

Returns:

  • (Array<String>)

    List of model family names for the tier



59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/aidp/harness/model_registry.rb', line 59

def models_for_tier(tier)
  tier_str = tier.to_s
  unless VALID_TIERS.include?(tier_str)
    Aidp.log_warn("model_registry", "invalid tier requested", tier: tier_str, valid: VALID_TIERS)
    return []
  end

  families = @registry_data["model_families"].select { |_family, info|
    info["tier"] == tier_str
  }.keys

  Aidp.log_debug("model_registry", "found models for tier", tier: tier_str, count: families.size)
  families
end