Skip to main content

Variants & Registry

As your prompt library grows, you’ll want to swap implementations without changing the code that uses them. The PromptRegistry maps logical names to prompt classes and lets you override which class is used at runtime.

Registering Prompts

Variants

Register multiple classes under the same name. The first registration becomes the default; subsequent ones are stored as variants:

Overrides

Pass overrides to the constructor to swap which variant is returned by get():
Overrides are resolved by short class name or fully-qualified class name. This makes it easy to drive prompt selection from configuration files without changing calling code.

Creating Variants

A variant is just a subclass. Override what you need — template, model hint, body logic — and register it under the same name:
The calling code doesn’t change. It asks the registry for 'reviewer.analyze' and gets whichever variant is configured.

The AsPrompt Attribute

Instead of calling register() manually, annotate your class with #[AsPrompt]:
Then register via registerClass():

Auto-Discovery

PromptDiscovery scans Composer’s classmap and registers all prompt classes automatically:
Name resolution priority:
  1. #[AsPrompt("name")] attribute
  2. $promptName public property
  3. Derived from FQCN — App\Prompts\Reviewer\AnalyzeDocument becomes reviewer.analyze_document

Listing Prompts

Next Steps