A Laravel wrapper for neuron-ai that facilitates the integration of the AI agents framework into Laravel applications.
Check out the technical guides and tutorials file to learn how to create your artificial intelligence agents with Neuron. https://docs.neuron-ai.dev/resources/guides-and-tutorials.
- 🚀 Easy installation - Automatic configuration with auto-discovery
- 🎨 Artisan commands - Generate AI agent classes with
make:agentand prompt classes withmake:prompt - ⚙️ Flexible configuration - Support for multiple AI providers
- 🔧 Facade included - Simple access through
NeuronAI:: - 📝 Flexible prompts - Create custom prompt classes with any structure you need
- 🧪 Tests included - Complete test suite
- 📚 Complete documentation - Detailed examples and guides
- OpenAI (GPT-4, GPT-3.5-turbo)
- Anthropic (Claude 3)
- Google Gemini
- Ollama (Local models)
composer require mappweb/laravel-neuron-ai# Publish configuration file
php artisan vendor:publish --provider="Mappweb\LaravelNeuronAi\NeuronServiceProvider" --tag="neuron-ai-config"
# Publish stubs for customization
php artisan vendor:publish --provider="Mappweb\LaravelNeuronAi\NeuronServiceProvider" --tag="neuron-ai-stubs"
# Publish all files
php artisan vendor:publish --provider="Mappweb\LaravelNeuronAi\NeuronServiceProvider" --tag="neuron-ai"Add the following variables to your .env file:
# General configuration
NEURON_AI_DEFAULT_PROVIDER=openai
# OpenAI
OPENAI_API_KEY=your-openai-api-key
OPENAI_MODEL=gpt-4
# Anthropic
ANTHROPIC_API_KEY=your-anthropic-api-key
ANTHROPIC_MODEL=claude-3-sonnet-20240229
# Gemini
GEMINI_API_KEY=your-gemini-api-key
# Ollama (for local models)
OLLAMA_BASE_URL=http://localhost:11434
OLLAMA_MODEL=llama2# Basic agent
php artisan make:agent ChatAgent
# Agent with specific provider
php artisan make:agent ChatAgent --provider=openai
# Agent with custom instructions
php artisan make:agent ChatAgent --instructions="You are a helpful customer support agent"
# Agent with tools
php artisan make:agent ChatAgent --tools="WebSearch,EmailSender"
# Complete agent
php artisan make:agent CustomerSupportAgent \
--provider=anthropic \
--instructions="You are a customer support agent" \
--tools="WebSearch,DatabaseQuery"# Basic prompt
php artisan make:prompt ChatPrompt
# Complete prompt
php artisan make:prompt GreetingPrompt --content="Hello! I'm {$this->name}, your assistant."
# Prompt with custom path
php artisan make:prompt CustomPrompt --path="Custom\\Prompts"<?php
declare(strict_types=1);
namespace App\Agents;
use NeuronAI\Agent;
use NeuronAI\Providers\AIProviderInterface;
use NeuronAI\Providers\OpenAIProvider;
class ChatAgent extends Agent
{
public function provider(): AIProviderInterface
{
return OpenAIProvider::make();
}
public function instructions(): string
{
return 'You are a helpful AI assistant.';
}
}<?php
declare(strict_types=1);
namespace App\Agents;
use NeuronAI\Agent;
use Mappweb\LaravelNeuronAi\Providers\OpenAI\OpenAITranscribeProvider;
use Mappweb\LaravelNeuronAi\Transcribe\TranscribeProviderInterface;
class TranscribeAgent extends Transcribe
{
public function transcribe(): TranscribeProviderInterface
{
return new OpenAITranscribeProvider(
config('neuron-ai.providers.openai.api_key'),
'whisper-1',
'es',
);
}
}<?php
namespace App\Http\Controllers;
use App\Agents\ChatAgent;
use Illuminate\Http\Request;
class ChatController extends Controller
{
public function chat(Request $request)
{
$agent = new ChatAgent();
$response = $agent->chat($request->input('message'));
return response()->json([
'response' => $response
]);
}
}use Mappweb\LaravelNeuronAi\Facades\NeuronAI;
// Basic usage
$agent = NeuronAI::make()
->provider(OpenAIProvider::make())
->instructions('You are a helpful assistant');
$response = $agent->chat('Hello!');
// With configuration from config
$agent = NeuronAI::make()
->provider(config('neuron-ai.default_provider'))
->instructions(config('neuron-ai.agents.default_instructions'));The config/neuron-ai.php file allows you to configure:
return [
// Default provider
'default_provider' => env('NEURON_AI_DEFAULT_PROVIDER', 'openai'),
// Providers configuration
'providers' => [
'openai' => [
'api_key' => env('OPENAI_API_KEY'),
'model' => env('OPENAI_MODEL', 'gpt-4'),
'max_tokens' => env('OPENAI_MAX_TOKENS', 2048),
'temperature' => env('OPENAI_TEMPERATURE', 0.7),
],
// ... other providers
],
// Agents configuration
'agents' => [
'default_instructions' => env('NEURON_AI_DEFAULT_INSTRUCTIONS', 'You are a helpful AI assistant.'),
'default_namespace' => 'App\\Agents',
'timeout' => env('NEURON_AI_TIMEOUT', 30),
],
// Logging and cache
'logging' => [
'enabled' => env('NEURON_AI_LOGGING_ENABLED', true),
'channel' => env('NEURON_AI_LOG_CHANNEL', 'default'),
],
'cache' => [
'enabled' => env('NEURON_AI_CACHE_ENABLED', false),
'ttl' => env('NEURON_AI_CACHE_TTL', 3600),
],
];<?php
declare(strict_types=1);
namespace App\Agents\Prompts;
use Mappweb\LaravelNeuronAi\Prompts\PromptInterface;
class BlogPrompt implements PromptInterface
{
public function __construct(
public string $topic = 'Technology',
public int $wordCount = 500,
public array $keywords = [],
) {
//
}
public function __toString(): string
{
return "Write a {$this->wordCount}-word blog post about {$this->topic}. Include keywords: " . implode(', ', $this->keywords);
}
}| Option | Description | Example |
|---|---|---|
--provider |
AI provider to use | --provider=openai |
--instructions |
Custom instructions | --instructions="You are helpful" |
--tools |
Tools (comma-separated) | --tools="WebSearch,Email" |
--path |
Custom directory | --path="CustomAgents" |
--force |
Overwrite existing files | --force |
| Option | Description | Example |
|---|---|---|
--content (-c) |
Default content/template | --content="Hello {$this->name}!" |
--path |
Custom directory | --path="Custom\\Prompts" |
--force (-f) |
Overwrite existing files | --force |
openai→ OpenAIProvideranthropic→ AnthropicProvidergemini→ GeminiProviderollama→ OllamaProvider
composer testPlease see CHANGELOG for recent changes.
Contributions are welcome. Please review CONTRIBUTING for more details.
If you discover security vulnerabilities, please send an email to [email protected].
The MIT License (MIT). Please see License File for more information.