-
-
Notifications
You must be signed in to change notification settings - Fork 134
[PromptTemplate] Add new component with extensible renderer architecture #1017
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[PromptTemplate] Add new component with extensible renderer architecture #1017
Conversation
Introduces a new prompt-template component providing simple yet extensible
prompt templating with pluggable rendering strategies.
Features:
- Zero core dependencies (only PHP 8.2+)
- StringRenderer for simple {variable} replacement (default)
- ExpressionRenderer for advanced expressions (optional, requires symfony/expression-language)
- Factory pattern for exceptions with typed error methods
- Comprehensive test coverage (42 tests, 52 assertions)
- PHPStan level 6 compliant
- Follows Symfony coding standards
Architecture:
- Strategy pattern for extensible rendering
- Immutable readonly classes throughout
- Interface-first design (PromptTemplateInterface, RendererInterface)
- Component-specific exception hierarchy
The component allows users to create prompt templates with variable substitution
using either simple string replacement or advanced expression evaluation, with
the ability to implement custom renderers for specific use cases.
c290706 to
00b4af3
Compare
|
Thanks for this @wachterjohannes - would really love to get this in 🙏 two things that we need to sort here:
we could have something like: $template = new Symfony\AI\Platform\Message\Template::expression('Total: {price * quantity}');
$message = Message::forSystem($template);
$messages = new MessageBag($message);
$result = $platform->invoke('gpt-4o-mini', $messages, [
'template_vars' => ['price' => 10, 'quantity' => 5],
]);and later - while serializing - take care of the rendering - potentially throw an error on unsupported types. with type being only a string instead of a renderer instance + named construct for promoted use: class Template
{
public function __construct(
private string $template,
private string $type,
) { }
public static function string(string $template): self;
public static function expression(string $template): self;
public static function twig(string $template): self
{
return new self($template, 'twig');
}
}WDYT? |
|
@chr-hertel in my opinion an own component makes sense as it is totally independent to the other component and as you mentioned we could integrate it into the agent and platform. @OskarStark what do you think. Regarding the renaming - makes totally sense and i will do that when the decission over the component is final :) |
|
My thinking always is: API first, then implementation, then slicing. That's why i would delay that component discussion. Templates alone are not valuable, they need an integration into the Message I'd say |
|
@chr-hertel both are absolutly thru statements :) so let us wait for feedback from @OskarStark |
Summary
Adds a new prompt-template component to the Symfony AI monorepo, filling a gap we identified in our (Christopher Hertel and me) recent discussion about missing core functionality for prompt management.
Background
This implementation merges and adapts code from both sulu.ai and modelflow-ai projects, bringing battle-tested prompt templating into the Symfony AI ecosystem with a more extensible architecture.
Architecture
The component uses a strategy pattern for rendering, allowing different template processors to be plugged in:
{variable}replacement with zero dependenciesKey Features
Usage Examples
Simple variable replacement:
This provides a solid foundation for prompt template management across the Symfony AI ecosystem while maintaining the flexibility to adapt to different rendering needs.