PHPackages                             yannelli/prompt-manager-laravel - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. yannelli/prompt-manager-laravel

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

yannelli/prompt-manager-laravel
===============================

A Laravel package for managing prompt templates with versioning, component toggling, chaining, and customizable type handlers

v0.1.0(5mo ago)00MITPHPPHP ^8.2CI passing

Since Nov 30Pushed 5mo agoCompare

[ Source](https://github.com/yannelli/prompt-manager-laravel)[ Packagist](https://packagist.org/packages/yannelli/prompt-manager-laravel)[ Docs](https://github.com/yannelli/prompt-manager-laravel)[ RSS](/packages/yannelli-prompt-manager-laravel/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (14)Versions (2)Used By (0)

[![Tests](https://github.com/yannelli/prompt-manager-laravel/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/yannelli/prompt-manager-laravel/actions/workflows/tests.yml)

Prompt Manager for Laravel
==========================

[](#prompt-manager-for-laravel)

A powerful Laravel package for managing prompt templates with versioning, component toggling, chaining, and customizable type handlers.

Features
--------

[](#features)

- **Template Management** - Create, update, and organize prompt templates with slugs and metadata
- **Version Control** - Full versioning support with custom mapping logic for backward compatibility
- **Component System** - Toggleable template components (prepend, append, replace) with conditional display
- **Type System** - Extensible prompt types (system, user, assistant, tool, custom) with invokable handlers
- **Pipeline/Chaining** - Chain multiple templates together, passing results through each step
- **Multiple Renderers** - Simple variable substitution or full Blade template support
- **Execution Tracking** - Optional logging of prompt executions with performance metrics

Requirements
------------

[](#requirements)

- PHP 8.2+
- Laravel 11.0 or 12.0

Installation
------------

[](#installation)

```
composer require yannelli/prompt-manager
```

Publish the configuration file:

```
php artisan vendor:publish --tag="prompt-manager-config"
```

Run the migrations:

```
php artisan migrate
```

Quick Start
-----------

[](#quick-start)

### Creating a Template

[](#creating-a-template)

```
use Yannelli\PromptManager\Facades\PromptManager;

$template = PromptManager::create([
    'slug' => 'greeting',
    'name' => 'Greeting Prompt',
    'type' => 'user',
    'content' => 'Hello, {{ name }}! Welcome to {{ app_name }}.',
]);
```

### Rendering a Template

[](#rendering-a-template)

```
$result = PromptManager::render('greeting', [
    'variables' => [
        'name' => 'John',
        'app_name' => 'My Application',
    ],
]);

echo $result->content; // "Hello, John! Welcome to My Application."
echo $result->role;    // "user"
```

### Using the Pipeline for Chaining

[](#using-the-pipeline-for-chaining)

```
use Yannelli\PromptManager\DTOs\PromptContext;

$messages = PromptManager::chain()
    ->template('system-prompt')
    ->template('user-query', ['query' => 'What is Laravel?'])
    ->template('format-instructions')
    ->toMessages(PromptContext::make([
        'variables' => ['language' => 'English'],
    ]));

// Result:
// [
//     ['role' => 'system', 'content' => '...'],
//     ['role' => 'user', 'content' => '...'],
//     ['role' => 'user', 'content' => '...'],
// ]
```

Template Versions
-----------------

[](#template-versions)

### Creating New Versions

[](#creating-new-versions)

```
$template = PromptManager::template('greeting');

$template->createVersion('Updated greeting: Hello {{ name }}!', [
    'change_summary' => 'Simplified greeting message',
    'variables' => ['name'],
]);
```

### Requesting Specific Versions

[](#requesting-specific-versions)

```
$result = PromptManager::render('greeting', [
    'version' => 1, // Use version 1 instead of current
]);
```

### Version Mapping

[](#version-mapping)

Map client versions to template versions for backward compatibility:

```
$result = PromptManager::render('api-prompt', [
    'variables' => ['query' => 'test'],
    'metadata' => [
        'version_mapping' => [
            'client_version' => '1.5.0',
            'rules' => [
                ['client_version' => '>=2.0', 'template_version' => 3],
                ['client_version' => '>=1.0', 'template_version' => 2],
                ['client_version' => '*', 'template_version' => 1],
            ],
        ],
    ],
]);
```

Components
----------

[](#components)

Components are reusable template parts that can be toggled on/off.

### Creating Templates with Components

[](#creating-templates-with-components)

```
$template = PromptManager::create([
    'slug' => 'assistant',
    'name' => 'AI Assistant',
    'content' => 'You are a helpful assistant.',
    'components' => [
        [
            'key' => 'code_guidelines',
            'name' => 'Code Guidelines',
            'content' => 'When writing code, follow best practices...',
            'position' => 'append',
            'is_default_enabled' => true,
        ],
        [
            'key' => 'verbose_mode',
            'name' => 'Verbose Mode',
            'content' => 'Provide detailed explanations...',
            'position' => 'append',
            'is_default_enabled' => false,
        ],
    ],
]);
```

### Toggling Components

[](#toggling-components)

```
// Enable specific components
$result = PromptManager::render('assistant', [
    'enabled_components' => ['verbose_mode'],
]);

// Disable specific components
$result = PromptManager::render('assistant', [
    'disabled_components' => ['code_guidelines'],
]);
```

### Conditional Components

[](#conditional-components)

Components can be shown/hidden based on context:

```
$template->addComponent([
    'key' => 'admin_tools',
    'content' => 'Admin-only instructions...',
    'conditions' => [
        ['field' => 'user_role', 'operator' => '=', 'value' => 'admin'],
    ],
]);

// Component only shows if user_role is 'admin'
$result = PromptManager::render('assistant', [
    'variables' => ['user_role' => 'admin'],
]);
```

Custom Prompt Types
-------------------

[](#custom-prompt-types)

### Registering a Custom Type

[](#registering-a-custom-type)

```
use Yannelli\PromptManager\Types\BasePromptType;

class ToolPromptType extends BasePromptType
{
    public function getRole(): string
    {
        return 'tool';
    }

    public function prepareContext(PromptContext $context): PromptContext
    {
        return $context->withVariables([
            'tool_version' => config('app.tool_version'),
        ]);
    }

    public function postProcess(RenderResult $result): RenderResult
    {
        return $result->withMetadata(['is_tool_call' => true]);
    }
}

// Register the type
PromptManager::registerType('tool', ToolPromptType::class);
```

Or add to config:

```
// config/prompt-manager.php
'types' => [
    'system' => \Yannelli\PromptManager\Types\SystemPromptType::class,
    'user' => \Yannelli\PromptManager\Types\UserPromptType::class,
    'assistant' => \Yannelli\PromptManager\Types\AssistantPromptType::class,
    'tool' => \App\PromptTypes\ToolPromptType::class,
],
```

Pipeline Pipes
--------------

[](#pipeline-pipes)

Add custom processing to the pipeline:

```
use Yannelli\PromptManager\Pipelines\Pipes\SanitizeVariablesPipe;
use Yannelli\PromptManager\Pipelines\Pipes\ValidateVariablesPipe;

$result = PromptManager::chain()
    ->pipe(new SanitizeVariablesPipe(escapeHtml: true))
    ->pipe(new ValidateVariablesPipe(['query'], strict: true))
    ->template('search-prompt')
    ->run($context);
```

Action Classes
--------------

[](#action-classes)

Use action classes for more control:

```
use Yannelli\PromptManager\Actions\RenderPromptAction;
use Yannelli\PromptManager\Actions\CreateTemplateAction;
use Yannelli\PromptManager\Actions\DuplicateTemplateAction;
use Yannelli\PromptManager\Actions\ExportTemplateAction;
use Yannelli\PromptManager\Actions\ImportTemplateAction;

// Create
$template = app(CreateTemplateAction::class)->handle($data);

// Duplicate
$copy = app(DuplicateTemplateAction::class)->handle('original-slug', 'new-slug');

// Export/Import
$exported = app(ExportTemplateAction::class)->handle('my-template', includeAllVersions: true);
$imported = app(ImportTemplateAction::class)->handle($exported, overwrite: true);
```

Configuration
-------------

[](#configuration)

```
// config/prompt-manager.php

return [
    // Default prompt type
    'default_type_key' => 'user',

    // Registered types
    'types' => [
        'system' => SystemPromptType::class,
        'user' => UserPromptType::class,
        'assistant' => AssistantPromptType::class,
    ],

    // Template renderer
    'renderer' => 'simple', // 'simple' or 'blade'

    // Version settings
    'versioning' => [
        'auto_publish' => false,
        'keep_versions' => null, // null = keep all
    ],

    // Database tables
    'tables' => [
        'templates' => 'prompt_templates',
        'versions' => 'prompt_template_versions',
        'components' => 'prompt_components',
        'executions' => 'prompt_executions',
    ],

    // Execution tracking
    'track_executions' => false,

    // Cache settings
    'cache' => [
        'enabled' => true,
        'ttl' => 3600,
        'prefix' => 'prompt_manager',
    ],
];
```

Testing
-------

[](#testing)

```
composer test
```

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

Learn more about our mission:
**Author:** [Ryan Yannelli](https://ryanyannelli.com)
**Sponsor:** [Nextvisit AI Medical Scribe](https://nextvisit.ai)

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance71

Regular maintenance activity

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity37

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

164d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/53b64331d4de8c9cef47bc20707ed728c0e900cd2bda4ed7d95359ced8b9adf1?d=identicon)[yannelli](/maintainers/yannelli)

---

Top Contributors

[![yannelli](https://avatars.githubusercontent.com/u/59575788?v=4)](https://github.com/yannelli "yannelli (8 commits)")

---

Tags

ailaravelpackagelaravelaiversioningtemplatesllmprompts

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/yannelli-prompt-manager-laravel/health.svg)

```
[![Health](https://phpackages.com/badges/yannelli-prompt-manager-laravel/health.svg)](https://phpackages.com/packages/yannelli-prompt-manager-laravel)
```

###  Alternatives

[spatie/laravel-livewire-wizard

Build wizards using Livewire

4061.0M4](/packages/spatie-laravel-livewire-wizard)[laracraft-tech/laravel-useful-additions

A collection of useful Laravel additions!

58109.4k](/packages/laracraft-tech-laravel-useful-additions)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

255.2k](/packages/aedart-athenaeum)[tonysm/importmap-laravel

Use ESM with importmap to manage modern JavaScript in Laravel without transpiling or bundling.

148399.8k1](/packages/tonysm-importmap-laravel)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
