承接 illuma-law/laravel-prompt-registry 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

illuma-law/laravel-prompt-registry

最新稳定版本:v0.1.4

Composer 安装命令:

composer require illuma-law/laravel-prompt-registry

包简介

Dynamic AI agent prompt registration and retrieval for Laravel.

README 文档

README

Run Tests PHPStan Latest Version on Packagist Total Downloads License

A lightweight, dynamic registry for AI agent prompt definitions in Laravel.

This package provides a centralized system to register and look up AI prompt metadata across your Laravel application. Instead of hardcoding AI agent configurations, you can register an agent's associated class, name, description, fallback Blade views, and LLM tiers (Standard vs Extended) either via configuration or programmatically.

Features

  • Centralized Configuration: Define all your application's AI prompts in a single config file.
  • Dynamic Registration: Register prompts on the fly from Service Providers or external packages.
  • Bidirectional Lookup: Fetch prompt definitions by their string key, or look up the configuration using the Agent's class name.
  • Tier Routing: Built-in support for defining whether an agent requires an 'extended' (smarter/larger) model tier or can operate on a 'standard' tier by default.
  • Dependency Injection & Facade: Use the PromptRegistry facade for quick access, or inject PromptRegistryManager for robust testing.

Installation

Install the package via Composer:

composer require illuma-law/laravel-prompt-registry

Publish the config file:

php artisan vendor:publish --tag="laravel-prompt-registry-config"

Configuration

The published config/prompt-registry.php holds an array where each key is a dot-notation identifier for the prompt definition:

return [
    'prompts' => [
        'agents.content_creator' => [
            'agent'                => \App\Ai\Agents\ContentCreatorAgent::class,
            'name'                 => 'Content Creator Agent',
            'description'          => 'Generates marketing social content.',
            'fallback_view'        => 'prompts.agents.content_creator',
            'default_primary_tier' => 'standard', // Optional: 'standard' | 'extended'
        ],
        'agents.legal_analyst' => [
            'agent'                => \App\Ai\Agents\LegalAnalystAgent::class,
            'name'                 => 'Legal Analyst',
            'description'          => 'Analyzes complex legal documents.',
            'fallback_view'        => 'prompts.agents.legal_analyst',
            'default_primary_tier' => 'extended',
        ],
    ],
];

Usage & Integration

Programmatic Registration

While configuration is the easiest method, you can register prompts anywhere (like in a package's ServiceProvider):

use IllumaLaw\PromptRegistry\Facades\PromptRegistry;

// Register a single prompt
PromptRegistry::register('agents.custom', [
    'agent'         => \App\Ai\Agents\CustomAgent::class,
    'name'          => 'Custom Agent',
    'description'   => 'A custom agent for specialized tasks.',
    'fallback_view' => 'prompts.agents.custom',
]);

// Register multiple prompts
PromptRegistry::registerMany([
    // ...
]);

Retrieving Prompts

The package provides multiple ways to fetch the registered definitions:

use IllumaLaw\PromptRegistry\Facades\PromptRegistry;
use App\Ai\Agents\ContentCreatorAgent;

// Look up by registry key
$definition = PromptRegistry::forKey('agents.content_creator');
// Returns array: ['agent' => '...', 'name' => '...', 'description' => '...', ...]

// Look up by Agent class name
$definition = PromptRegistry::forAgent(ContentCreatorAgent::class);

// Get the default primary tier directly for routing (returns 'standard' or 'extended')
$tier = PromptRegistry::defaultPrimaryTierForAgent(ContentCreatorAgent::class);

// Get all registered prompts (flat list)
$all = PromptRegistry::all();

// Get all registered prompts, keyed by their registry key
$byKey = PromptRegistry::definitionsByKey();

Exception Handling

If you attempt to retrieve a prompt that hasn't been registered, the registry will throw an \InvalidArgumentException. This enforces strict configuration correctness.

use IllumaLaw\PromptRegistry\Facades\PromptRegistry;

try {
    $definition = PromptRegistry::forKey('agents.unknown');
} catch (\InvalidArgumentException $e) {
    // "No prompt definition was registered for key [agents.unknown]."
}

Dependency Injection

You can resolve the underlying PromptRegistryManager from the Laravel container directly if you prefer dependency injection over Facades:

namespace App\Services;

use IllumaLaw\PromptRegistry\PromptRegistryManager;

class PromptService
{
    public function __construct(
        protected PromptRegistryManager $registry
    ) {}

    public function handle(): void
    {
        $definition = $this->registry->forKey('agents.content_creator');
    }
}

Testing

The test suite uses Pest and maintains 100% code coverage.

# Run tests
composer test

# Run static analysis
composer analyse

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 33
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 9
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-20

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固