Skip to content

FEAT: BuildableRegistry Creation#2057

Open
rlundeen2 wants to merge 9 commits into
microsoft:mainfrom
rlundeen2:rlundeen2/buildable-registry-phase-2
Open

FEAT: BuildableRegistry Creation#2057
rlundeen2 wants to merge 9 commits into
microsoft:mainfrom
rlundeen2:rlundeen2/buildable-registry-phase-2

Conversation

@rlundeen2

@rlundeen2 rlundeen2 commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

This PR hashes out Registry, making it the single source of truth for component contracts. This PR

  • Introduces declarative param markers for class attributes and references
  • Solidifies registry and identifier responsibilities
  • Updates resolution logic
  • Updates ConverterRegistry to the new paradigm

Phase 2 and 3: https://gist.github.com/rlundeen2/f7960f7e8973fbb705b1b4bb48d8cdb2

Note, I thought this PR was actually more readable combining 2 and 3 because you get a "fairly final" version of ConverterRegistry working end to end. Next steps are to move other registries

rlundeen2 and others added 9 commits June 19, 2026 10:25
Move the declarative Parameter contract to pyrit/models/parameter.py as the
canonical home, add ComponentRegistryKind / RegistryReference / ParameterDestination,
and re-key the registry resolver off registry kind instead of inline issubclass checks.
pyrit/common/parameter.py becomes a compatibility re-export.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Rename ComponentRegistryKind -> ComponentType and have identifiers own
their reference-derivation. Replace the fabricated class-level
ConverterIdentifier with a declarative Param.ClassAttr marker plus a
generic class-attribute reader; ClassRegistryEntry now carries
class_attributes. Rename the converter nested-converter slot
sub_converters -> sub_converter and model it as a proper buildable
reference. Promote three identifier structure/child-tree methods to
public contracts (get_reference_component_types,
get_class_attribute_values, plus internal child-eval-hash collection).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Make the universal registry base a standalone top-level class named `Registry`
(renamed from BuildableRegistry; buildable_registry.py -> registry.py). It no
longer inherits BaseClassRegistry: it owns its own singleton machinery, class
catalog (dict[str, type[T]]), lazy discovery, metadata cache, validation, and
build path.

- Single add path: _discover() -> register_class() -> _validate_class, so every
  class is validated at registration time (dropped public validate_all/
  validate_buildable and the ClassEntry/factory/default_kwargs wrapper).
- Migrate only ConverterRegistry onto Registry; scenarios/initializers/targets/
  scorers stay on the transitional BaseClassRegistry for now.
- Renames: reset_instance -> reset_registry_singleton, register ->
  register_class, get_names -> get_class_names, list_metadata ->
  get_all_registered_class_metadata, get_entry -> get_registered_class_metadata;
  add get_class_metadata(cls). create_instance keeps its name.
- Remove issubclass fallback in resolution.py; update converter_service and
  docstrings; update tests for the new surface and add-time validation.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Reverts incidental removal of find_dependents_of_tag (and its tests) from the
legacy instance stack; it is unrelated to the standalone Registry migration and
will be shared by the not-yet-migrated target/scorer registries.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Encapsulate the low-level 'reference points at this component family' check
as Parameter.is_reference_to(component_type), the single source of truth.
ConverterMetadata.is_llm_based and the converter tests now read through it
instead of re-deriving reference.component_type inline.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Make Registry._build_metadata concrete: it assembles the shared
ClassRegistryEntry fields and constructs whatever metadata type the
subclass declares via the new abstract _metadata_class() hook. Adds
_derive_parameters/_class_attributes/_describe helpers; _derive_parameters
is now reused by _validate_class, removing the double parameter derivation.

ConverterRegistry drops its hand-rolled _build_metadata in favor of a
one-line _metadata_class() returning ConverterMetadata.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
_registry_getter_for_component_type returns a deferred getter to a
name->instance registry and reaches through .instances for converters but
not for target/scorer (whose legacy singletons are themselves the instance
registry). It wants to be a flat ComponentType -> registry class mapping,
but that requires target/scorer to migrate onto Registry + .instances
first (Phase 4). Add code notes marking the deferral on both that function
and the is_component_type_resolvable gate that wraps it.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Add tests/unit/registry/test_registry.py covering the Registry base
  directly (default snake_case naming, no-identifier path, eager vs lazy
  discovery, the metadata getters, and the filter-path wiring).
- Move first-paragraph description extraction onto ClassRegistryEntry
  (summary_from_docstring); _build_metadata delegates to the metadata
  class and the bespoke Registry._describe is removed.
- Inline _matches_filters/_get_metadata_value into registry.py (base.py
  is slated for deletion except ClassRegistryEntry) and drop the
  function-local import.
- Simplify __iter__ to reuse get_class_names().
- ConverterRegistry._discover keys off the class (drop redundant name=)
  and logs cls.__name__; annotate _get_registry_name as type[PromptConverter].
- Comment the deliberate double-derivation of parameters in _validate_class.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant