AI agent builder for Laravilt Framework

Maintainers

Details

github.com/laravilt/ai

Source

Issues

Installs: 0

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/laravilt/ai

v0.0.1 2025-11-12 16:13 UTC

This package is auto-updated.

Last update: 2025-12-02 13:11:12 UTC


README

AI agent builder package for Laravilt Framework. Build AI agents with tools from your Laravel models.

Features

  • Agent - Base agent class with tools, instructions, and metadata
  • Tool - Base tool class with parameter schemas and custom handlers
  • ResourceAgent - Auto-generate CRUD tools from Laravel models
  • QueryTool - Search and query records
  • CreateTool - Create new records with validation
  • UpdateTool - Update existing records
  • DeleteTool - Delete records (soft delete and force delete support)
  • Export to OpenAI and Anthropic formats

Installation

composer require laravilt/ai

Usage

Resource Agent

use Laravilt\AI\ResourceAgent;
use App\Models\User;

$agent = ResourceAgent::make(User::class)
    ->name('user-agent')
    ->instructions('You are a helpful assistant that manages users.')
    ->meta([
        'model' => 'gpt-4',
        'temperature' => 0.7,
    ]);

// Export to OpenAI format
$openai = $agent->toArray();

// Export to JSON
$json = $agent->toJson();

Custom Agent with Tools

use Laravilt\AI\Agent;
use Laravilt\AI\Tool;

class WeatherTool extends Tool
{
    protected string $name = 'get_weather';
    protected string $description = 'Get the current weather for a location';

    protected array $parameters = [
        'location' => [
            'type' => 'string',
            'description' => 'The city name',
            'required' => true,
        ],
    ];

    protected function handle(array $arguments): array
    {
        $location = $arguments['location'];
        // Fetch weather data...
        return ['temperature' => 72, 'condition' => 'sunny'];
    }
}

$agent = Agent::make()
    ->name('weather-assistant')
    ->instructions('Provide weather information.')
    ->tools([
        new WeatherTool(),
    ]);

Individual Tools

use Laravilt\AI\Tools\QueryTool;
use Laravilt\AI\Tools\CreateTool;
use Laravilt\AI\Tools\UpdateTool;
use Laravilt\AI\Tools\DeleteTool;
use App\Models\Post;

// Query Tool
$queryTool = QueryTool::make(Post::class)
    ->searchable(['title', 'content']);

// Create Tool
$createTool = CreateTool::make(Post::class)
    ->rules([
        'title' => 'required|string|max:255',
        'content' => 'required|string',
    ]);

// Update Tool
$updateTool = UpdateTool::make(Post::class)
    ->rules([
        'title' => 'string|max:255',
        'content' => 'string',
    ]);

// Delete Tool (with soft delete)
$deleteTool = DeleteTool::make(Post::class)
    ->softDelete();

Testing

composer test              # Run tests
composer test:coverage     # With coverage
composer test:types        # PHPStan analysis
composer test:style        # Code style check
composer format            # Auto-fix code style

Changelog

Please see CHANGELOG for more information.

Contributing

Please see CONTRIBUTING for details.

Security

Please review SECURITY for security issues.

License

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