Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

pyrit.registry

Registry module for PyRIT class and object registries.

Functions

discover_in_directory

discover_in_directory(directory: Path, base_class: type[T], recursive: bool = True) → Iterator[tuple[str, Path, type[T]]]

Discover all subclasses of base_class in a directory by loading Python files.

This function walks a directory, loads Python files dynamically, and yields any classes that are subclasses of the specified base_class.

ParameterTypeDescription
directoryPathThe directory to search for Python files.
base_classtype[T]The base class to filter subclasses of.
recursiveboolWhether to recursively search subdirectories. Defaults to True. Defaults to True.

discover_in_package

discover_in_package(package_path: Path, package_name: str, base_class: type[T], recursive: bool = True, name_builder: Callable[[str, str], str] | None = None, _prefix: str = '') → Iterator[tuple[str, type[T]]]

Discover all subclasses using pkgutil.iter_modules on a package.

This function uses Python’s package infrastructure to discover modules, making it suitable for discovering classes in installed packages.

ParameterTypeDescription
package_pathPathThe filesystem path to the package directory.
package_namestrThe dotted module name of the package (e.g., “pyrit.scenario.scenarios”).
base_classtype[T]The base class to filter subclasses of.
recursiveboolWhether to recursively search subpackages. Defaults to True. Defaults to True.
name_builder`Callable[[str, str], str]None`
_prefixstrInternal parameter to track the current subdirectory prefix. Defaults to ''.

discover_subclasses_in_loaded_modules

discover_subclasses_in_loaded_modules(base_class: type[T], exclude_module_prefixes: tuple[str, ...] | None = None) → Iterator[tuple[str, type[T]]]

Discover subclasses of a base class from already-loaded modules.

This is useful for discovering user-defined classes that were loaded via initialization scripts or dynamic imports.

ParameterTypeDescription
base_classtype[T]The base class to filter subclasses of.
exclude_module_prefixes`tuple[str, ...]None`

AttackTechniqueRegistry

Bases: BaseInstanceRegistry['AttackTechniqueFactory']

Singleton registry of reusable attack technique factories.

Scenarios and initializers register self-describing AttackTechniqueFactory instances. Scenarios retrieve factories via get_factories() and call factory.create() with the scenario’s objective target and scorer.

Methods:

build_strategy_class_from_factories

build_strategy_class_from_factories(class_name: str, factories: list[AttackTechniqueFactory], aggregate_tags: dict[str, TagQuery]) → type

Build a ScenarioStrategy enum subclass dynamically from technique factories.

Creates an enum class with:

Each aggregate maps to a TagQuery that determines which technique factories belong to it.

ParameterTypeDescription
class_namestrName for the generated enum class.
factorieslist[AttackTechniqueFactory]Technique factories to include as enum members.
aggregate_tagsdict[str, TagQuery]Maps aggregate member names to a TagQuery that selects which techniques belong to the aggregate. An ALL aggregate (expanding to all techniques) is always added.

Returns:

get_factories

get_factories() → dict[str, AttackTechniqueFactory]

Return all registered factories as a name→factory dict.

Callers filter the result in-place using factory properties (e.g. factory.uses_adversarial or factory.strategy_tags).

Returns:

get_factories_or_raise

get_factories_or_raise() → dict[str, AttackTechniqueFactory]

Return all registered factories, raising if the registry is empty.

Use this from any code path that needs the registry to be populated (scenario strategy builders, scenario initialization) so an empty registry surfaces a single, descriptive error instead of silently producing empty strategy enums or empty attack lists.

Returns:

Raises:

register_from_factories

register_from_factories(factories: list[AttackTechniqueFactory]) → None

Register a list of factories under their name.

Per-name idempotent: existing entries are not overwritten.

ParameterTypeDescription
factorieslist[AttackTechniqueFactory]Self-describing factories to register. Each factory’s name and strategy_tags properties are used directly.

register_technique

register_technique(name: str, factory: AttackTechniqueFactory, tags: dict[str, str] | list[str] | None = None) → None

Register an attack technique factory.

ParameterTypeDescription
namestrThe registry name for this technique.
factoryAttackTechniqueFactoryThe factory that produces attack techniques.
tags`dict[str, str]list[str]

BaseClassRegistry

Bases: ABC, RegistryProtocol[MetadataT], Generic[T, MetadataT]

Abstract base class for registries that store classes (type[T]).

This class implements RegistryProtocol and provides the common infrastructure for class registries including:

Subclasses must implement:

Constructor Parameters:

ParameterTypeDescription
lazy_discoveryboolIf True, discovery is deferred until first access. If False, discovery runs immediately in constructor. Defaults to True.

Methods:

create_instance

create_instance(name: str, kwargs: object = {}) → T

Create an instance of a registered class.

ParameterTypeDescription
namestrThe registry name of the class.
**kwargsobjectKeyword arguments to pass to the factory or constructor. Defaults to {}.

Returns:

Raises:

get_class

get_class(name: str) → type[T]

Get a registered class by name.

ParameterTypeDescription
namestrThe registry name (snake_case identifier).

Returns:

Raises:

get_entry

get_entry(name: str) → ClassEntry[T] | None

Get the full ClassEntry for a registered class.

This is useful when you need access to factory or default_kwargs.

ParameterTypeDescription
namestrThe registry name.

Returns:

get_names

get_names() → list[str]

Get a sorted list of all registered names.

These are the snake_case registry keys (e.g., “encoding”, “self_ask_refusal”), not the actual class names (e.g., “EncodingScenario”, “SelfAskRefusalScorer”).

Returns:

get_registry_singleton

get_registry_singleton() → Self

Get the singleton instance of this registry.

Creates the instance on first call with default parameters.

Returns:

list_metadata

list_metadata(include_filters: dict[str, object] | None = None, exclude_filters: dict[str, object] | None = None) → list[MetadataT]

List metadata for all registered classes, optionally filtered.

Supports filtering on any metadata property:

ParameterTypeDescription
include_filters`dict[str, object]None`
exclude_filters`dict[str, object]None`

Returns:

register

register(name: str | None = None, factory: Callable[..., T] | None = None, default_kwargs: dict[str, object] | None = None) → None

Register a class with the registry.

ParameterTypeDescription
clstype[T]The class to register (type[T], not an instance).
name`strNone`
factory`Callable[..., T]None`
default_kwargs`dict[str, object]None`

reset_instance

reset_instance() → None

Reset the singleton instance.

Useful for testing or when re-discovery is needed.

unregister

unregister(name: str) → None

Remove a registered class from the registry.

ParameterTypeDescription
namestrThe registry name of the class to remove.

Raises:

BaseInstanceRegistry

Bases: ABC, RegistryProtocol[ComponentIdentifier], Generic[T]

Abstract base class providing shared registry infrastructure.

.. note::

**Legacy — do not subclass for new registries.** New component
registries subclass [``BuildableRegistry``](#api-pyrit_registry-BuildableRegistry) and expose retained instances
via the ``.instances`` property ([``DefaultInstanceRegistry``](#api-pyrit_registry-DefaultInstanceRegistry)), which
carries this same surface ([``register``](#api-pyrit_registry-BaseInstanceRegistry-register)/``get``/[``get_by_tag``](#api-pyrit_registry-BaseInstanceRegistry-get_by_tag)/
[``add_tags``](#api-pyrit_registry-BaseInstanceRegistry-add_tags)/[``find_dependents_of_tag``](#api-pyrit_registry-BaseInstanceRegistry-find_dependents_of_tag)/[``list_metadata``](#api-pyrit_registry-BaseInstanceRegistry-list_metadata)). This class
survives only for the not-yet-migrated [``TargetRegistry``](#api-pyrit_registry-TargetRegistry),
[``ScorerRegistry``](#api-pyrit_registry-ScorerRegistry), and [``AttackTechniqueRegistry``](#api-pyrit_registry-AttackTechniqueRegistry) and is removed once
they move to ``.instances``.

Provides singleton lifecycle, registration, tag-based lookup, metadata filtering, and the standard container protocol (__contains__, __len__, __iter__).

Subclass directly when stored items should not be retrievable via get() (e.g., factory registries). For registries that expose direct item retrieval, subclass RetrievableInstanceRegistry instead.

All stored items must implement Identifiable, which provides get_identifier() for metadata generation.

Methods:

add_tags

add_tags(name: str, tags: dict[str, str] | list[str]) → None

Add tags to an existing registry entry.

ParameterTypeDescription
namestrThe registry name of the entry to tag.
tags`dict[str, str]list[str]`

Raises:

find_dependents_of_tag

find_dependents_of_tag(tag: str) → list[RegistryEntry[T]]

Find entries whose children depend on entries with the given tag.

Scans each registry entry’s ComponentIdentifier tree and checks whether any child’s eval_hash matches the eval_hash of an entry that carries tag. Entries that themselves carry tag are excluded from the results.

This enables automatic dependency detection: for example, tagging base refusal scorers with "refusal" lets you discover all wrapper scorers (inverters, composites) that embed a refusal scorer without any explicit depends_on declaration.

ParameterTypeDescription
tagstrThe tag key that identifies the “base” entries.

Returns:

get_by_tag

get_by_tag(tag: str, value: str | None = None) → list[RegistryEntry[T]]

Get all entries that have a given tag, optionally matching a specific value.

ParameterTypeDescription
tagstrThe tag key to match.
value`strNone`

Returns:

get_names

get_names() → list[str]

Get a sorted list of all registered names.

Returns:

get_registry_singleton

get_registry_singleton() → Self

Get the singleton instance of this registry.

Creates the instance on first call with default parameters.

Returns:

list_metadata

list_metadata(include_filters: dict[str, object] | None = None, exclude_filters: dict[str, object] | None = None) → list[ComponentIdentifier]

List metadata for all registered items, optionally filtered.

Supports filtering on any metadata property:

ParameterTypeDescription
include_filters`dict[str, object]None`
exclude_filters`dict[str, object]None`

Returns:

register

register(instance: T, name: str, tags: dict[str, str] | list[str] | None = None, metadata: dict[str, Any] | None = None) → None

Register an item.

ParameterTypeDescription
instanceTThe item to register.
namestrThe registry name for this item.
tags`dict[str, str]list[str]
metadata`dict[str, Any]None`

reset_instance

reset_instance() → None

Reset the singleton instance.

Useful for testing or reinitializing the registry.

BuildableRegistry

Bases: BaseClassRegistry[T, MetadataT]

Registry base that can build instances from a type name and arguments.

Extends the class-table infrastructure of BaseClassRegistry with a construction path that routes through resolve_constructor_args: string values are coerced to their annotated scalar types and registry-reference parameters are resolved by name from the owning domain’s registry. A registered factory, when present, is used as-is (its arguments are not resolved, since a factory owns its own construction semantics).

Methods:

create_instance

create_instance(name: str, kwargs: object = {}) → T

Build a configured instance by class name.

Arguments are resolved via resolve_constructor_args (coerce simple strings, resolve registry references by name, raise on unknown params). When the class is registered with a factory, the factory is invoked directly with the given arguments instead.

ParameterTypeDescription
namestrThe class-catalog name to build.
**kwargsobjectConstructor arguments (simple values or registry names for reference parameters). Defaults to {}.

Returns:

Raises:

get_class_names

get_class_names() → list[str]

Get a sorted list of all registered class names.

Always reflects the class catalog, even on registries that also hold instances (where the protocol surface get_names refers to instances on the instances property, not here).

Returns:

list_class_metadata

list_class_metadata(include_filters: dict[str, object] | None = None, exclude_filters: dict[str, object] | None = None) → list[MetadataT]

List metadata for all registered classes, optionally filtered.

This is the class-catalog metadata (one entry per registered class), distinct from any instance-level metadata a container registry exposes. It always reflects the class catalog, even on container registries where list_metadata refers to instances.

ParameterTypeDescription
include_filters`dict[str, object]None`
exclude_filters`dict[str, object]None`

Returns:

ClassEntry

Bases: Generic[T]

Internal wrapper for a registered class.

This holds the class itself (type[T]) along with optional factory and default parameters for creating instances.

Note: This is an internal implementation detail. Users interact with registries via get_class(), create_instance(), and list_metadata().

Constructor Parameters:

ParameterTypeDescription
registered_classtype[T]The actual Python class (type[T]).
factory`Callable[..., T]None`
default_kwargs`dict[str, object]None`

Methods:

create_instance

create_instance(kwargs: object = {}) → T

Create an instance of the registered class.

ParameterTypeDescription
**kwargsobjectAdditional keyword arguments. These override default_kwargs. Defaults to {}.

Returns:

get_description

get_description(fallback: str = '') → str

Resolve description from docstring, falling back to provided default.

Returns:

ConverterMetadata

Bases: ClassRegistryEntry

Metadata describing a registered PromptConverter class.

Use ConverterRegistry.get_class() to get the actual class or create_instance() to build a configured instance.

ConverterRegistry

Bases: BuildableRegistry['PromptConverter', ConverterMetadata]

Registry that discovers, builds, and holds PromptConverter instances.

Discovers all concrete PromptConverter subclasses exported from pyrit.prompt_converter (keyed by their exact class name, e.g. "Base64Converter") for the buildable catalog. Pre-configured instances registered via initializers or the backend are held under the instances property.

Building a converter resolves its arguments through the shared resolver, so LLM converters can be constructed by passing a converter_target that names a target in the TargetRegistry.

Constructor Parameters:

ParameterTypeDescription
lazy_discoveryboolIf True, class discovery is deferred until first access. If False, discovery runs immediately. Defaults to True.

DefaultInstanceRegistry

Bases: Generic[T]

Concrete InstanceRegistry implementation assigned to .instances.

Holds named, pre-configured instances with tags and derived metadata. It owns no singleton lifecycle — the registry that exposes it via .instances owns that.

Constructor Parameters:

ParameterTypeDescription
instance_type`type[T]Callable[[], type[T]]

Methods:

add_tags

add_tags(name: str, tags: dict[str, str] | list[str]) → None

Add tags to an existing entry.

ParameterTypeDescription
namestrThe registry name of the entry to tag.
tags`dict[str, str]list[str]`

Raises:

find_dependents_of_tag

find_dependents_of_tag(tag: str) → list[RegistryEntry[T]]

Find entries whose children depend on entries with the given tag.

Scans each entry’s ComponentIdentifier tree and checks whether any child’s eval_hash matches the eval_hash of an entry that carries tag. Entries that themselves carry tag are excluded.

This enables automatic dependency detection: for example, tagging base refusal scorers with "refusal" lets you discover all wrapper scorers (inverters, composites) that embed a refusal scorer without any explicit depends_on declaration.

ParameterTypeDescription
tagstrThe tag key that identifies the “base” entries.

Returns:

get

get(name: str) → T | None

Get a registered instance by name.

ParameterTypeDescription
namestrThe registry name of the instance.

Returns:

get_all_instances

get_all_instances() → list[RegistryEntry[T]]

Get all registered entries sorted by name.

Returns:

get_by_tag

get_by_tag(tag: str, value: str | None = None) → list[RegistryEntry[T]]

Get entries that carry a given tag, optionally matching a value.

ParameterTypeDescription
tagstrThe tag key to match.
value`strNone`

Returns:

get_entry

get_entry(name: str) → RegistryEntry[T] | None

Get the full entry (including tags) by name.

ParameterTypeDescription
namestrThe registry name of the entry.

Returns:

get_names

get_names() → list[str]

Get a sorted list of all registered instance names.

Returns:

list_metadata

list_metadata(include_filters: dict[str, object] | None = None, exclude_filters: dict[str, object] | None = None) → list[ComponentIdentifier]

List metadata for all registered instances, optionally filtered.

ParameterTypeDescription
include_filters`dict[str, object]None`
exclude_filters`dict[str, object]None`

Returns:

register

register(instance: T, name: str | None = None, tags: dict[str, str] | list[str] | None = None, metadata: dict[str, Any] | None = None) → None

Register a pre-configured instance.

ParameterTypeDescription
instanceTThe instance to register.
name`strNone`
tags`dict[str, str]list[str]
metadata`dict[str, Any]None`

Raises:

InitializerMetadata

Bases: ClassRegistryEntry

Metadata describing a registered PyRITInitializer class.

Use get_class() to get the actual class.

InitializerRegistry

Bases: BaseClassRegistry['PyRITInitializer', InitializerMetadata]

Registry for discovering and managing available initializers.

This class discovers all PyRITInitializer subclasses from the pyrit/setup/initializers directory structure.

Initializers are identified by their filename (e.g., “objective_target”, “simple”). The directory structure is used for organization but not exposed to users.

Constructor Parameters:

ParameterTypeDescription
discovery_path`PathNone`
lazy_discoveryboolIf True, discovery is deferred until first access. Defaults to False for backwards compatibility. Defaults to False.

Methods:

is_builtin

is_builtin(name: str) → bool

Return True if name was registered during built-in discovery.

register_from_content

register_from_content(name: str, script_content: str) → str

Register an initializer from uploaded Python source code.

Writes script_content to a managed directory, loads it as a module, discovers the first concrete PyRITInitializer subclass, and registers it under name.

ParameterTypeDescription
namestrRegistry name for the new initializer.
script_contentstrPython source code that defines a PyRITInitializer subclass.

Returns:

Raises:

resolve_script_paths

resolve_script_paths(script_paths: list[str]) → list[Path]

Resolve and validate custom script paths.

ParameterTypeDescription
script_pathslist[str]List of script path strings to resolve.

Returns:

Raises:

unregister_and_cleanup

unregister_and_cleanup(name: str) → None

Unregister a custom initializer and clean up its script file.

Built-in initializers cannot be removed. For custom initializers added via register_from_content, the saved script file is also deleted.

ParameterTypeDescription
namestrThe registry name to remove.

Raises:

InstanceRegistry

Bases: Protocol[T]

Typed instance-container capability a registry exposes as .instances.

Holds named, pre-configured instances that callers register and retrieve by name, list, tag, and filter. Stored items must implement Identifiable. DefaultInstanceRegistry is the concrete default implementation; expressing the surface as a protocol lets callers depend on the capability rather than a concrete class.

Methods:

add_tags

add_tags(name: str, tags: dict[str, str] | list[str]) → None

Add tags to an existing entry.

find_dependents_of_tag

find_dependents_of_tag(tag: str) → list[RegistryEntry[T]]

Return entries whose identifier tree references a tagged entry’s eval_hash.

get

get(name: str) → T | None

Return the instance registered under name, or None.

get_all_instances

get_all_instances() → list[RegistryEntry[T]]

Return all entries sorted by name.

get_by_tag

get_by_tag(tag: str, value: str | None = None) → list[RegistryEntry[T]]

Return entries carrying tag (optionally matching value), sorted by name.

get_entry

get_entry(name: str) → RegistryEntry[T] | None

Return the full entry (including tags) for name, or None.

get_names

get_names() → list[str]

Return the sorted names of registered instances.

list_metadata

list_metadata(include_filters: dict[str, object] | None = None, exclude_filters: dict[str, object] | None = None) → list[ComponentIdentifier]

List per-instance identifier metadata, optionally filtered.

register

register(instance: T, name: str | None = None, tags: dict[str, str] | list[str] | None = None, metadata: dict[str, Any] | None = None) → None

Register a pre-configured instance, defaulting its name to the identifier’s unique_name.

RegistryEntry

Bases: Generic[T]

A wrapper around a registered item, holding its name, tags, and the item itself.

Tags are always stored as dict[str, str]. When callers pass a plain list[str], each string is normalized to a key with an empty-string value.

RegistryProtocol

Bases: Protocol[MetadataT]

Protocol defining the common interface for all registries.

Both class registries (BaseClassRegistry) and object registries (BaseInstanceRegistry) implement this interface, enabling code that works with either registry type.

Methods:

get_names

get_names() → list[str]

Get a sorted list of all registered names.

get_registry_singleton

get_registry_singleton() → Self

Get the singleton instance of this registry.

list_metadata

list_metadata(include_filters: dict[str, Any] | None = None, exclude_filters: dict[str, Any] | None = None) → list[MetadataT]

List metadata for all registered items, optionally filtered.

ParameterTypeDescription
include_filters`dict[str, Any]None`
exclude_filters`dict[str, Any]None`

Returns:

reset_instance

reset_instance() → None

Reset the singleton instance.

RetrievableInstanceRegistry

Bases: BaseInstanceRegistry[T]

Base class for registries that store directly-retrievable instances.

.. note::

**Legacy — do not subclass for new registries.** Use
[``BuildableRegistry``](#api-pyrit_registry-BuildableRegistry) + the ``.instances`` property
([``DefaultInstanceRegistry``](#api-pyrit_registry-DefaultInstanceRegistry)), which already exposes
[``get``](#api-pyrit_registry-RetrievableInstanceRegistry-get)/[``get_entry``](#api-pyrit_registry-RetrievableInstanceRegistry-get_entry)/[``get_all_instances``](#api-pyrit_registry-RetrievableInstanceRegistry-get_all_instances). Retained only for the
not-yet-migrated [``ScorerRegistry``](#api-pyrit_registry-ScorerRegistry) and [``TargetRegistry``](#api-pyrit_registry-TargetRegistry).

Extends BaseInstanceRegistry with get(), get_entry(), and get_all_instances() for registries where callers retrieve the stored objects directly (e.g., scorers, converters, targets).

For registries that store factories or other non-retrievable items, subclass BaseInstanceRegistry directly instead.

Methods:

get

get(name: str) → T | None

Get a registered instance by name.

ParameterTypeDescription
namestrThe registry name of the instance.

Returns:

get_all_instances

get_all_instances() → list[RegistryEntry[T]]

Get all registered entries sorted by name.

Returns:

get_entry

get_entry(name: str) → RegistryEntry[T] | None

Get a full registry entry by name, including tags.

ParameterTypeDescription
namestrThe registry name of the entry.

Returns:

ScenarioMetadata

Bases: ClassRegistryEntry

Metadata describing a registered Scenario class.

Use get_class() to get the actual class.

ScenarioParameterMetadata

Bases: NamedTuple

A scenario-declared parameter rendered for user-facing display.

NamedTuple so existing positional construction (e.g. in tests) keeps working while consumers can read fields by name.

ScenarioRegistry

Bases: BaseClassRegistry['Scenario', ScenarioMetadata]

Registry for discovering and managing available scenario classes.

This class discovers all Scenario subclasses from:

  1. Built-in scenarios in pyrit.scenario.scenarios module

  2. User-defined scenarios from initialization scripts (set via globals)

Scenarios are identified by their dotted name (e.g., “garak.encoding”, “foundry.red_team_agent”).

Constructor Parameters:

ParameterTypeDescription
lazy_discoveryboolIf True, discovery is deferred until first access. Defaults to True for performance. Defaults to True.

Methods:

discover_user_scenarios

discover_user_scenarios() → None

Discover user-defined scenarios from global variables.

After initialization scripts are executed, they may define Scenario subclasses and store them in globals. This method searches for such classes.

User scenarios will override built-in scenarios with the same name.

ScorerRegistry

Bases: RetrievableInstanceRegistry['Scorer']

Registry for managing available scorer instances.

This registry stores pre-configured Scorer instances (not classes). Scorers are registered explicitly via initializers after being instantiated with their required parameters (e.g., chat_target).

Scorers are identified by their snake_case name derived from the class name, or a custom name provided during registration.

Methods:

get_instance_by_name

get_instance_by_name(name: str) → Scorer | None

Get a registered scorer instance by name.

Note: This returns an already-instantiated scorer, not a class.

ParameterTypeDescription
namestrThe registry name of the scorer.

Returns:

register_instance

register_instance(scorer: Scorer, name: str | None = None, tags: dict[str, str] | list[str] | None = None) → None

Register a scorer instance.

Note: Unlike ScenarioRegistry and InitializerRegistry which register classes, ScorerRegistry registers pre-configured instances.

ParameterTypeDescription
scorerScorerThe pre-configured scorer instance (not a class).
name`strNone`
tags`dict[str, str]list[str]

SupportsInstances

Bases: Protocol[T]

Structural marker for a registry that holds instances.

Lets callers and type-checkers express “a registry that holds instances” without naming a concrete class, so a registry’s capabilities are legible from its type.

.. note:: Introduced with the Phase 1 foundation but not yet consumed in the codebase. Its first real callers arrive when the target and scorer registries migrate onto .instances (Phase 4) and functions begin accepting “any registry that holds instances” structurally. It ships now so the typed capability is part of the foundation rather than a later additive change.

TagQuery

Boolean predicate over string tag sets.

Leaf fields (include_all, include_any, exclude) are evaluated against a tag set directly. Composite queries are produced by the & and | operators and stored in _op / _children.

Prefer the classmethod shortcuts all, any_of, and exclude for single-field leaves.

Methods:

all

all(tags: str = ()) → TagQuery

Leaf query: every tag must be present.

Returns:

any_of

any_of(tags: str = ()) → TagQuery

Leaf query: at least one tag must be present.

Returns:

filter

filter(items: list[_T]) → list[_T]

Return items whose tags satisfy this query.

ParameterTypeDescription
itemslist[_T]Objects with a tags attribute.

Returns:

matches

matches(tags: set[str] | frozenset[str]) → bool

Return True if tags satisfies this query.

ParameterTypeDescription
tags`set[str]frozenset[str]`

Returns:

none_of

none_of(tags: str = ()) → TagQuery

Leaf query: none of the given tags may be present.

Returns:

TargetRegistry

Bases: RetrievableInstanceRegistry['PromptTarget']

Registry for managing available prompt target instances.

This registry stores pre-configured PromptTarget instances (not classes). Targets are registered explicitly via initializers after being instantiated with their required parameters (e.g., endpoint, API keys).

Targets are identified by their snake_case name derived from the class name, or a custom name provided during registration.

Methods:

get_instance_by_name

get_instance_by_name(name: str) → PromptTarget | None

Get a registered target instance by name.

Note: This returns an already-instantiated target, not a class.

ParameterTypeDescription
namestrThe registry name of the target.

Returns:

register_instance

register_instance(target: PromptTarget, name: str | None = None, tags: dict[str, str] | list[str] | None = None) → None

Register a target instance.

Note: Unlike ScenarioRegistry and InitializerRegistry which register classes, TargetRegistry registers pre-configured instances.

ParameterTypeDescription
targetPromptTargetThe pre-configured target instance (not a class).
name`strNone`
tags`dict[str, str]list[str]