Skip to content

MAINT: Refactor converter construction into ConverterClassRegistry#1963

Open
rlundeen2 wants to merge 7 commits into
microsoft:mainfrom
rlundeen2:rlundeen2/converter-registry-refactor
Open

MAINT: Refactor converter construction into ConverterClassRegistry#1963
rlundeen2 wants to merge 7 commits into
microsoft:mainfrom
rlundeen2:rlundeen2/converter-registry-refactor

Conversation

@rlundeen2

@rlundeen2 rlundeen2 commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Construction logic previously lived in the backend service, so attack strategies and on-the-fly agents couldn't build a converter without reaching into backend code. Making "build by name" a registry capability is the keystone for agent/config-driven component assembly — including LLM converters, whose converter_target is resolved by name from the TargetRegistry.

This PR converter construction out of the backend service and into the registry layer, so building a converter by name is a reusable, backend-free capability.

  • New shared construction primitive (resolution.py): coerces simple string args to their annotated types and resolves registry-reference params (e.g. a PromptTarget) by name — one mechanism for every domain.
  • New registry layering: BuildableRegistry (discover classes + create_instance) → ContainerRegistry (adds a named-instance container). Every registry is buildable; those that also hold instances extend the container.
  • Merged ConverterClassRegistry into a single ConverterRegistry that both holds pre-configured instances and builds new ones from a name + args. The separate class registry is removed.
  • ConverterService is now a thin consumer: creation routes through registry.create_instance(...); it retains only presentation (type/param rendering for the catalog DTO), preview, and data-URI persistence.

Phase 1 of this plan to unify the registry: https://gist.github.com/rlundeen2/f7960f7e8973fbb705b1b4bb48d8cdb2

rlundeen2 and others added 3 commits June 9, 2026 12:27
Move converter class discovery, parameter introspection, string->typed param coercion, and instantiation out of the backend ConverterService into a new core ConverterClassRegistry so agents/attack strategies can build converters on the fly without depending on pyrit.backend.

- Add ConverterClassRegistry with ConverterMetadata / ConverterParameterMetadata (requires_llm on params, derived is_llm_based) and a coercing create_instance.
- ConverterService now delegates construction to the registry and keeps only presentation/transport concerns (DTO mapping, data-URI persistence, API-ref resolution).
- Move catalog-visibility (hiding base/helper converters like SelectiveTextConverter) to the frontend, since it is purely a display decision.
- Route scenario construction through ScenarioRegistry.create_instance.
- Retarget tests so registry behavior is covered in the registry test module.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
ScenarioResult.completion_time is datetime | None (None while a run is in progress), but ScenarioRunSummary.updated_at requires datetime. Fall back to creation_time so an in-progress run reports its creation as the last status-change time.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment thread frontend/src/components/Chat/ConverterPanel/ConverterPanel.tsx
@rlundeen2 rlundeen2 marked this pull request as draft June 11, 2026 21:29
self._ensure_discovered()
entry = self._class_entries.get(name)
if entry is None:
raise ValueError(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: KeyError to match base class registry

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rich approved fix: Done. The not-registered path now raises KeyError to match BaseClassRegistry.get_class. Both BuildableRegistry.create_instance and a new get_class override raise KeyError for an unknown name; resolution failures (unknown param, bad coercion, unresolvable registry reference) stay ValueError. The converter route translates the KeyError into a 400 at the service boundary so the API behavior is unchanged.

Comment thread pyrit/registry/class_registries/converter_class_registry.py Outdated
Comment thread pyrit/registry/class_registries/converter_class_registry.py Outdated
Move converter construction out of the backend service into the registry
layer. Introduce a shared construction primitive (resolution.py) and a
BuildableRegistry -> ContainerRegistry layering, then merge the separate
ConverterClassRegistry into a single ConverterRegistry that both holds
pre-configured instances and builds new ones from a name plus arguments.
The backend ConverterService becomes a thin consumer that routes creation
through the registry and retains only presentation/preview concerns.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@rlundeen2 rlundeen2 marked this pull request as ready for review June 12, 2026 00:58
rlundeen2 and others added 3 commits June 11, 2026 19:01
- Raise KeyError (not ValueError) for unknown names in BuildableRegistry to
  match BaseClassRegistry; resolution failures stay ValueError. Converter route
  translates the KeyError to a 400 at the service boundary.
- Remove redundant get_converter_class; callers use the inherited get_class.
  Override get_class in BuildableRegistry so the "not found" message lists the
  class catalog rather than the instance container.
- Validate Literal values in coerce_string_to_annotation (raise on a value
  outside the allowed members) and return the matching member in its real type.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace the interim ContainerRegistry subclass with a typed .instances property
backed by DefaultInstanceRegistry, move ConverterRegistry under registry.components,
and add optional runtime instance-type enforcement so a non-converter cannot be
registered in the converter instance container. Annotate the legacy
base/retrievable instance registries as do-not-extend.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Underscore ConverterParameterMetadata to _ConverterParameterMetadata, drop it
from the registry public exports, and add a transitional note pointing to the
unified Parameter contract that replaces it in Phase 3. The backend converter
service imports it directly from the submodule.

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.

2 participants