Variants & Registry
As your prompt library grows, you’ll want to swap implementations without changing the code that uses them. ThePromptRegistry 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 byget():
Creating Variants
A variant is just a subclass. Override what you need — template, model hint, body logic — and register it under the same name:'reviewer.analyze' and gets whichever variant is configured.
The AsPrompt Attribute
Instead of callingregister() manually, annotate your class with #[AsPrompt]:
registerClass():
Auto-Discovery
PromptDiscovery scans Composer’s classmap and registers all prompt classes automatically:
#[AsPrompt("name")]attribute$promptNamepublic property- Derived from FQCN —
App\Prompts\Reviewer\AnalyzeDocumentbecomesreviewer.analyze_document
Listing Prompts
Next Steps
- Configuration — configure template paths and engine settings
- Getting Started — revisit the basics