1. Go to this page and download the library: Download refinephp/laravel-ai-batch 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/ */
declare(strict_types=1);
namespace App\Ai\Agents;
use Laravel\Ai\Contracts\Agent;
use Laravel\Ai\Promptable;
final class GeneratePullRequestSummary implements Agent
{
use Promptable;
public function instructions(): string
{
return 'Summarize the pull request accurately in at most five bullets.';
}
}
use App\Ai\Agents\GeneratePullRequestSummary;
use Laravel\Ai\Enums\Lab;
use RefinePhp\LaravelAiBatch\Facades\AiBatch;
$firstPrompt = <<<'PROMPT'
Title: Add invoice export
Diff:
... first diff here ...
PROMPT;
$secondPrompt = <<<'PROMPT'
Title: Fix authorization policy
Diff:
... second diff here ...
PROMPT;
$batch = AiBatch::forProvider(Lab::OpenAI)
->name('pull-request-summaries')
->agent(GeneratePullRequestSummary::class)
->add('pr-123', prompt: $firstPrompt)
->add('pr-124', prompt: $secondPrompt, model: 'gpt-5.4-mini')
->submit();
$localId = $batch->id();
$openAiId = $batch->providerBatchId();
use Laravel\Ai\Files\LocalDocument;
$batch = AiBatch::forProvider(Lab::OpenAI)
->agent(AnalyzeDocument::class)
->add(
'invoice-42',
prompt: 'Extract the invoice fields.',
attachments: [LocalDocument::fromPath(storage_path('app/invoice-42.pdf'))],
)
->submit();
$request = AiBatch::resolve(
agent: GeneratePullRequestSummary::make(),
prompt: 'Generate the pull request summary.',
provider: Lab::OpenAI,
);
$request->provider(); // openai
$request->method(); // POST
$request->endpoint(); // /v1/responses
$request->body(); // final provider-native body
$request->headers(); // always credential-free
$batch = AiBatch::forProvider(Lab::OpenAI)
->name('pull-request-summaries')
->addRequest('pr-123', $request)
->submit();
$batch = AiBatch::findOrFail($localId);
$batch = AiBatch::refresh($batch);
if ($batch->isTerminal()) {
// Results or validation errors are now inspectable.
}
use Illuminate\Support\Facades\Schedule;
Schedule::command('ai:batch:poll --limit=100')
->everyFiveMinutes()
->withoutOverlapping();