laravelai / smartagent
A Laravel package for managing AI agents with support for OpenAI and Gemini
Installs: 1
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/laravelai/smartagent
Requires
- php: ^7.4|^8.0|^8.1|^8.2|^8.3
- ext-json: *
- google/cloud-ai-platform: ^0.7.0|^0.8.0|^0.9.0|^1.0.0|^1.10.0|^1.20.0|^1.30.0|^1.39.0
- illuminate/support: ^8.0|^9.0|^10.0|^11.0|^12.0
- openai-php/client: ^0.6.0|^0.7.0|^0.8.0|^0.9.0|^0.10.0|^0.11.0|^0.12.0|^0.13.0|^0.14.0|^0.15.0|^0.16.0|^0.17.0
Requires (Dev)
- orchestra/testbench: ^6.0|^7.0|^8.0|^9.0
- phpunit/phpunit: ^9.3|^10.0
Suggests
- ext-curl: Required for HTTP requests to external services
- ext-mbstring: Required for string manipulation functions
This package is auto-updated.
Last update: 2025-10-08 15:40:49 UTC
README
Copyright © 2025 Muhammad Junaid Rehman Siddiqui
All rights reserved. This project is licensed under the MIT License - see the LICENSE file for details.
Note: Unauthorized use, modification, or distribution of this software without proper attribution is strictly prohibited and may result in legal action.
A powerful Laravel package for integrating AI agents (OpenAI, Gemini) with database awareness and memory management.
Features
- 🤖 Multiple AI Providers (OpenAI, Gemini)
- 🧠 Conversation Memory & Context Management
- 🗃️ Database Schema Awareness
- 🔄 Automatic Query Generation
- 🔒 Safe Query Execution
- ⚡ Easy Integration
Requirements
- PHP 7.4+
- Laravel 8.0+
- Composer
- OpenAI API key or Google Cloud credentials (for Gemini)
Installation
-
Install via Composer:
composer require laravelai/smartagent:dev-main
-
Run the install command to set up the package:
php artisan ai-agents:install
This will:
- Publish the config file to
config/ai-agents.php
- Add required environment variables to your
.env
file
- Publish the config file to
-
Add your API keys to
.env
:# For OpenAI OPENAI_API_KEY=your_openai_api_key # For Gemini GOOGLE_CLOUD_PROJECT_ID=your_project_id GOOGLE_APPLICATION_CREDENTIALS=/path/to/credentials.json # General Settings AI_AGENT_DRIVER=openai # or 'gemini' AI_AGENT_MODEL=gpt-4 # or 'gemini-pro'
Database Integration
Checking Database Schema
You can inspect your database schema programmatically using the DatabaseSchemaService
:
use LaravelAI\SmartAgent\Services\DatabaseSchemaService; // Get complete database schema $service = new DatabaseSchemaService(); $schema = $service->getSchema(); dd($schema); // Dumps the complete database schema // Get schema for a specific table $tableSchema = $service->getTableSchema('users'); dd($tableSchema); // Dumps schema for 'users' table
Basic Usage
use LaravelAI\SmartAgent\Facades\AiAgent; // Simple chat with a single message $response = AiAgent::chat([ [ 'role' => 'user', 'content' => 'Hello, how are you?' ] ]); // With memory // First message AiAgent::chat([ [ 'role' => 'user', 'content' => 'My name is John' ] ]); // Second message that will have context from the first $response = AiAgent::chat([ [ 'role' => 'user', 'content' => 'What is my name?' ] ]); // Will remember the name is John
Query Generation
// Get query suggestions based on natural language $result = AiAgent::queryWithDatabaseContext( "Show me all active users who made a purchase" ); // Execute safe query $users = AiAgent::executeSafeQuery( "SELECT * FROM users WHERE active = ?", [1] );
Configuration
Edit config/ai-agents.php
for advanced configuration:
return [ 'default' => 'openai', 'database' => [ 'auto_load_schema' => true, 'exclude_tables' => ['migrations', 'password_resets'], ], 'memory' => [ 'enabled' => true, 'max_size' => 10 ] ];
Security
- Only SELECT queries are allowed by default
- All queries are validated against the database schema
- Sensitive information is never logged
License
This package is open-sourced software licensed under the MIT license.
Contributing
Contributions are welcome! Please read CONTRIBUTING.md for details.
Support
For issues and feature requests, please use the GitHub Issues page.