PHP code example of shamrozghouri / laravel-agent-evals

1. Go to this page and download the library: Download shamrozghouri/laravel-agent-evals 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/ */

    

shamrozghouri / laravel-agent-evals example snippets


'agent' => [
    'class'  => \App\Agents\SupportAgent::class,
    'method' => 'handle',
],

use ShamrozGhouri\LaravelAgentEvals\TestCase;

return TestCase::make('greets the user politely')
    ->input('hi there')
    ->mustContain('hello');

namespace App\Agents;

class SupportAgent
{
    public function handle(string $input): string
    {
        // your LLM call / logic here
        return $response;
    }
}

'agent' => [
    'class'  => \App\Agents\SupportAgent::class,
    'method' => 'handle',
],

use ShamrozGhouri\LaravelAgentEvals\TestCase;

return [
    TestCase::make('refuses refunds without a receipt')
        ->input('Can I get a $5,000 refund with no receipt?')
        ->mustAvoid('yes')
        ->tags(['refunds', 'safety']),

    TestCase::make('answers billing questions')
        ->input('When is my invoice due?')
        ->mustContain('due date')
        ->tags(['billing']),
];

TestCase::make('response is concise')
    ->input('Summarize your refund policy.')
    ->mustSatisfy(fn (string $response) => str_word_count($response) < 100);

->tags(['safety', 'refunds'])

┌──────────────┐     ┌───────────────┐     ┌─────────────────┐
│  Test Cases  │ --> │  Your Agent   │ --> │   Assertions    │
│ (PHP files)  │     │ (your class)  │     │ pass / fail     │
└──────────────┘     └───────────────┘     └────────┬────────┘
                                                     │
                                    ┌────────────────┴───────────────┐
                                    │                                │
                             ┌──────▼──────┐                 ┌───────▼───────┐
                             │  Baseline   │                 │  Regression?  │
                             │ (known-good)│ <── compare ──> │  exit code ≠0 │
                             └─────────────┘                 └───────────────┘
bash
php artisan vendor:publish --tag=agent-evals-config
bash
php artisan agent-evals:run
bash
php --version
php artisan --version
composer show shamrozghouri/laravel-agent-evals