Merged
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a Prompt Factory system to Cortex, enabling developers to manage and retrieve prompts from external services like Langfuse. The system provides a centralized way to store, version, and manage prompts outside the codebase while maintaining full integration with Cortex's existing functionality.
Key changes include:
- Prompt Factory Architecture: Manager-based system using Laravel's Manager pattern with pluggable factory implementations
- Langfuse Integration: Complete API integration for prompt retrieval with support for chat/text prompts, versioning, and metadata parsing
- Enhanced API: Extended
Cortex::prompt()method to support factory access and flexible prompt creation patterns
Reviewed Changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
tests/Unit/Prompts/Factories/LangfusePromptFactoryTest.php |
Comprehensive test suite for Langfuse prompt factory functionality |
src/Support/Utils.php |
Updated PHPDoc to include MessagePlaceholder support |
src/Support/Traits/DiscoversPsrImplementations.php |
Added nullable discovery methods and fail-safe variants |
src/Prompts/Templates/ChatPromptTemplate.php |
Updated PHPDoc to remove non-empty-array constraint |
src/Prompts/PromptFactoryManager.php |
Laravel Manager implementation for prompt factory drivers |
src/Prompts/Prompt.php |
Static helper class for prompt builder and factory access |
src/Prompts/Factories/McpPromptFactory.php |
Placeholder MCP implementation |
src/Prompts/Factories/LangfusePromptFactory.php |
Complete Langfuse prompt factory with caching and metadata support |
src/Prompts/Enums/PromptType.php |
Type-safe prompt type enumeration with builder factories |
src/Prompts/Contracts/PromptFactory.php |
Interface for prompt factory implementations |
src/Prompts/Contracts/PromptBuilder.php |
Enhanced contract with metadata and LLM convenience methods |
src/Prompts/Builders/Concerns/BuildsPrompts.php |
Added setMetadata method for prompt builders |
src/Prompts/Builders/ChatPromptBuilder.php |
Updated PHPDoc for MessagePlaceholder support |
src/LLM/LLMManager.php |
Improved PHPDoc type annotations |
src/Facades/PromptFactory.php |
Facade for convenient prompt factory access |
src/CortexServiceProvider.php |
Service provider registration for prompt factory services |
src/Cortex.php |
Enhanced prompt method to support factory access patterns |
scratchpad.php |
Usage examples for new prompt factory features |
config/cortex.php |
Configuration section for prompt factory settings |
Comments suppressed due to low confidence (1)
tests/Unit/Prompts/Factories/LangfusePromptFactoryTest.php:25
- [nitpick] Global functions in test files should have more specific names to avoid potential naming conflicts. Consider renaming to 'createTestLangfuseFactory' or using a class-based approach.
function createLangfuseFactory(
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🚀 Overview
This PR introduces Prompt Factories to Cortex, enabling developers to manage and retrieve prompts from external services like Langfuse. This feature provides a centralized way to store, version, and manage prompts outside of your codebase while maintaining full integration with Cortex's existing functionality.
✨ Key Features
🏭 Prompt Factory System
PromptFactoryManagerconfig/cortex.php🦜 Langfuse Integration (Complete)
🔌 MCP Support (Foundation)
🛠 Enhanced Developer Experience
Flexible Prompt Creation
The
Cortex::prompt()method now supports multiple patterns:Metadata Support
Enhanced metadata handling for prompts:
🏗 Architecture Changes
New Components
PromptFactoryManager- Central manager for prompt factory driversPromptFactoryContract - Interface for prompt factory implementationsPromptTypeEnum - Type-safe prompt type definitions with builder factoriesPromptFactoryFacade - Convenient facade accessPromptBuilderContract - Addedmetadata()andllm()convenience methodsConfiguration
New configuration section in
config/cortex.php:🔄 Backward Compatibility
✅ Fully backward compatible - All existing
Cortex::prompt()usage continues to work unchanged.🧪 Technical Details
Langfuse Implementation Highlights
Service Provider Integration
PromptFactoryManager📋 What's Next