Master your AI’s voice with dynamic prompts. Track improvements over time with versions, test different personalities with variants, and evolve your agents without touching code.
Remember changing code just to tweak your AI’s personality? Those days are OVER! With dynamic prompts, you can experiment, test, and perfect your agent’s responses without deploying a single line of code.
// Use latest version, default variantSupportAgent::run('Help')->go();// Use specific variantSupportAgent::run('Help') ->withPromptVersion('formal') ->go();// Use specific version & variantSupportAgent::run('Help') ->withPromptVersion('v1/casual') ->go();
When you create an agent using the vizra:make:agent command, it automatically creates a prompt blade file for you in /resources/prompts/YourAgent. This gives you instant access to dynamic prompts without any additional setup!
Quick Example
Copy
// Use a variantMyAgent::run('Hello') ->withPromptVersion('brief') ->go();// Use a specific version/variantMyAgent::run('Hello') ->withPromptVersion('v2/formal') ->go();
Let’s see how versions and variants work together in practice. Imagine evolving a customer support agent over time while maintaining different tones for different customers.
Usage in Production
Copy
// A/B test new version with specific users$version = $user->isInTestGroup() ? 'v3' : 'v2';$variant = $user->preferredTone ?? 'default';$response = CustomerSupportAgent::run($query) ->withPromptVersion("$version/$variant") ->forUser($user) ->go();// Or use smart routing based on context$promptVersion = match(true) { $isAngryCustomer => 'v3/empathetic', $isTechnicalIssue => 'v3/technical', $isVipCustomer => 'v3/formal', default => 'v3/default'};$response = CustomerSupportAgent::run($query) ->withPromptVersion($promptVersion) ->go();
You are {{ $agent['name'] }}, a helpful assistant.@if(isset($user_name))Hello {{ $user_name }}! How can I help you today?@elseHello! How can I assist you?@endif@if($tools->isNotEmpty())Available capabilities:@foreach($tools as $tool)- {{ $tool['description'] }}@endforeach@endif
You can define a default prompt version directly in your agent class:
Agent with Default Prompt Version
Copy
class WeatherReporterAgent extends BaseLlmAgent{ protected string $name = 'weather_reporter'; // Set default prompt version for this agent protected ?string $promptVersion = 'professional'; // This will be overridden by the professional.md file protected string $instructions = 'You are a weather reporter.';}// Now all calls use 'professional' by default$response = WeatherReporterAgent::run('What\'s the weather?')->go();// Override the default when needed$response = WeatherReporterAgent::run('Current temperature?') ->withPromptVersion('concise') ->go();
Blade templates work seamlessly with the existing prompt versioning system:
Using Blade Templates with Runtime API
Copy
// Blade templates work just like markdown versions$response = WeatherReporter::run('What\'s the weather?') ->withPromptVersion('detailed') // Can be detailed.blade.php ->go();// Mix and match - the system automatically detects the file type// Version 'friendly' could be friendly.md or friendly.blade.php$response = CustomerSupport::run($query) ->withPromptVersion('friendly') ->go();// Pass additional context for Blade templates$response = SalesAgent::run('Show me pricing') ->withContext([ 'premium_user' => true, 'account_age_days' => 365, 'preferred_language' => 'es', ]) ->withPromptVersion('personalized') // Uses personalized.blade.php ->go();// Works with async operations too$job = ReportGenerator::run($data) ->withPromptVersion('executive') // executive.blade.php with dynamic formatting ->async() ->go();
class PromptComparisonEval extends BaseEvaluation{ public string $agentName = 'weather_reporter'; // CSV column that specifies prompt version public ?string $promptVersionColumn = 'prompt_version'; // Or set a default for all tests public array $agentConfig = [ 'prompt_version' => 'detailed', 'temperature' => 0.7, ]; public function evaluateRow(array $csvRow, string $response): array { // Your evaluation logic here // The correct prompt version is automatically used! }}
With dynamic prompts, your AI agents can evolve and improve without touching code. Test freely, roll back instantly, and find the perfect voice for every agent. The future of AI development is here!