PHP code example of ronu / laravel-agent-protocol

1. Go to this page and download the library: Download ronu/laravel-agent-protocol library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ronu / laravel-agent-protocol example snippets


// config/agent-protocol.php

'resources' => [
    'security.user' => [
        'module' => 'security',
        'model' => App\Models\User::class,
        'request' => App\Http\Requests\UserRequest::class,
        'endpoint' => '/api/security/users',
        'description' => 'Users managed by the security module.',
        'permissions' => ['security.user.view'],
        'fields' => [
            'status' => [
                'label' => 'User status',
                'description' => 'Lifecycle state used to filter active or inactive users.',
                'type' => 'enum',
                'enum_values' => [
                    ['value' => 'active', 'label' => 'Active'],
                    ['value' => 'inactive', 'label' => 'Inactive'],
                ],
            ],
        ],
        'operations' => [
            'delete' => [
                'method' => 'DELETE',
                'endpoint' => '/api/security/users/{id}',
                'permissions' => ['security.user.delete'],
                'risk' => 'high',
                '

Ronu\RestGenericClass\Core\Controllers\RestController

// config/agent-protocol.php

'agent_guard' => [
    'enabled' => true,
    'mode' => 'closed_world',

    'domain' => [
        'enabled' => true,
        'mode' => 'closed',
        'allowed_modules' => ['security', 'clients', 'medical', 'sales'],
        'blocked_resources' => ['system.config', 'security.internal_token'],
        'blocked_topics' => ['passwords', 'tokens', 'secrets', 'system prompts'],
    ],

    'prompt_injection' => [
        'enabled' => true,
        'strategy' => 'detect_and_block',
        'patterns' => [
            'ignore previous instructions',
            'reveal your system prompt',
            'bypass policy',
            'ignora las instrucciones anteriores',
        ],
    ],

    'risk' => [
        'confirmation_

use Ronu\LaravelAgentProtocol\Security\AgentGuard\AgentContext;
use Ronu\LaravelAgentProtocol\Security\AgentGuard\IntentPlan;
use Ronu\LaravelAgentProtocol\Security\AgentGuard\ToolExecutionGuard;

$plan = IntentPlan::fromArray($llmOutput);

$context = new AgentContext(
    userIdentifier: (string) auth()->id(),
    tenantId: request()->header('X-Tenant-Id'),
    locale: request()->header('Accept-Language'),
    source: 'n8n',
    channel: 'webhook',
    permissions: ['security.user.view'],
);

$result = app(ToolExecutionGuard::class)->authorize($plan, $graph, $context);

if (! $result->allowed) {
    return response()->json($result->toArray(), $result->status());
}

// The adapter may now call the real Laravel API.

$wrapped = app(\Ronu\LaravelAgentProtocol\Security\AgentGuard\UntrustedContentSanitizer::class)
    ->wrap($apiResponse);
bash
php artisan agent:cache
php artisan agent:clear
php artisan agent:cache --tenant=7
php artisan agent:clear --tenant=7
bash
composer install --no-dev --optimize-autoloader
php artisan config:cache
php artisan route:cache
php artisan agent:validate
php artisan agent:cache
bash
php artisan agent:discover
php artisan agent:discover --json
php artisan agent:validate
php artisan agent:cache
php artisan agent:clear
php artisan agent:export agent-metadata.json --format=json
php artisan agent:export adp-schema.json --format=json-schema
php artisan agent:export mcp-manifest.json --format=mcp
php artisan agent:docs docs/generated