papi-ai/laravel

Laravel bridge for PapiAI - AI agent library

Maintainers

Package info

github.com/papi-ai/laravel

pkg:composer/papi-ai/laravel

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.9.1 2026-03-08 18:14 UTC

This package is not auto-updated.

Last update: 2026-03-10 18:23:40 UTC


README

Laravel integration for the PapiAI AI agent library. Provides a service provider, facade, Eloquent conversation store, and queue integration.

Installation

composer require papi-ai/laravel

The service provider is auto-discovered by Laravel. No manual registration needed.

Configuration

Publish the configuration file:

php artisan vendor:publish --tag=papi-config

This creates config/papi.php where you can configure:

  • Default provider -- which AI provider to use (openai, anthropic, etc.)
  • Provider settings -- API keys, models, and driver classes
  • Middleware -- middleware classes applied to all agents
  • Conversation storage -- file-based or Eloquent-based

Environment Variables

PAPI_PROVIDER=openai
OPENAI_API_KEY=your-openai-key
ANTHROPIC_API_KEY=your-anthropic-key

Usage

Using the Facade

use PapiAI\Laravel\Facades\Papi;

// Simple prompt
$response = Papi::run('What is the capital of France?');
echo $response->text;

// Streaming
foreach (Papi::stream('Tell me a story') as $chunk) {
    echo $chunk->text;
}

Resolving from the Container

// Get the configured provider
$provider = app('papi');

// Get the pre-configured agent
$agent = app('papi.agent');
$response = $agent->run('Hello!');

Adding Tools

use PapiAI\Laravel\Facades\Papi;

Papi::addTool(new MyCustomTool());
$response = Papi::run('Use my tool to do something');

Middleware

Configure middleware in config/papi.php:

'middleware' => [
    \PapiAI\Core\Middleware\LoggingMiddleware::class,
    \PapiAI\Core\Middleware\RetryMiddleware::class,
],

Or add middleware at runtime:

use PapiAI\Laravel\Facades\Papi;

Papi::addMiddleware(new RateLimitMiddleware(maxRequests: 10));

Conversation Storage

Switch to Eloquent-based storage in config/papi.php:

'conversation' => [
    'store' => 'eloquent',
],

The Eloquent store uses the papi_conversations table. Create a migration:

Schema::create('papi_conversations', function (Blueprint $table) {
    $table->string('id')->primary();
    $table->json('data');
    $table->timestamp('updated_at')->nullable();
});

Queue Integration

Dispatch agent jobs to Laravel queues:

use PapiAI\Laravel\Queue\LaravelQueue;
use PapiAI\Core\AgentJob;

$queue = app(LaravelQueue::class);

$jobId = $queue->dispatch(new AgentJob(
    agentClass: MyAgent::class,
    prompt: 'Process this in the background',
));

$status = $queue->status($jobId);

Requirements

  • PHP 8.2+
  • Laravel 10, 11, or 12
  • papi-ai/papi-core ^0.8

License

MIT