4,000 emails/month for free | Mailtrap sends real emails now!

The Neuron AI Framework for PHP and Laravel

Published on by

The Neuron AI Framework for PHP and Laravel image

Neuron AI is a PHP Agentic framework to build production-ready AI-driven applications. Along with the core neuron-ai framework, the neuron-laravel package provides Laravel-specific integration points without limiting access to the core framework components.

This package aims to make it easier for Laravel developers to get started with AI agent development using the Neuron AI framework. Neuron doesn't need invasive abstractions, it already has a very simple syntax, 100% typed code, and clear interfaces you can rely on to develop your agentic system or create custom plugins and extensions.

Using the Laravel package's Artisan commands, you can quickly generate files such as a Neuron agent, a tool, a workflow, and more. Using Neuron, you can extend the Agent class to create agents quickly, providing you with rich features like chat history, tools, etc, and a clean interface:

<?php
 
namespace App\Neuron;
 
use NeuronAI\Agent;
use NeuronAI\SystemPrompt;
use NeuronAI\Providers\AIProviderInterface;
use NeuronAI\Providers\Anthropic\Anthropic;
 
class YouTubeAgent extends Agent
{
protected function provider(): AIProviderInterface
{
// return an AI provider instance (Anthropic, OpenAI, Ollama, Gemini, etc.)
return new Anthropic(
key: 'ANTHROPIC_API_KEY',
model: 'ANTHROPIC_MODEL',
);
}
 
public function instructions(): string
{
return (string) new SystemPrompt(
background: ["You are an AI Agent specialized in writing YouTube video summaries."],
steps: [
"Get the url of a YouTube video, or ask the user to provide one.",
"Use the tools you have available to retrieve the transcription of the video.",
"Write the summary.",
],
output: [
"Write a summary in a paragraph without using lists. Use just fluent text.",
"After the summary add a list of three sentences as the three most important takeaways from the video.",
]
);
}
}

As I learned about Neuron, the Chat History feature really stood out to me, providing LLM context out of the box while truncating the conversation to avoid exceeding the LLM content window. Chat history can be stored in-memory, in a file, a database, or any storage you want by implementing the AbstractChatHistory class.

Laravel Neuron Main Features

  • A ready-to-use configuration file for AI providers, embeddings providers credentials
  • A few artisan commands to create the most used components and reduce boilerplate code
  • Facades to automatically instantiate providers and vector stores
  • Ready-to-run migrations if you want to use the EloquentChatHistory component
  • AI coding assistant guidelines integrated with Laravel Boost to help AI write better code

Learn More

While we cannot cover every feature Neuron provides, I recommend starting with the official documentation. It includes details about every part of Neuron as well as videos. Lastly, check out the example app demonstrating a multi-agent workflow in Laravel.

👨‍💻 The source code is available on GitHub: neuron-core/neuron-laravel

Paul Redmond photo

Staff writer at Laravel News. Full stack web developer and author.

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.

image
Laravel Cloud

Easily create and manage your servers and deploy your Laravel applications in seconds.

Visit Laravel Cloud
Bacancy logo

Bacancy

Supercharge your project with a seasoned Laravel developer with 4-6 years of experience for just $3200/month. Get 160 hours of dedicated expertise & a risk-free 15-day trial. Schedule a call now!

Bacancy
Tinkerwell logo

Tinkerwell

The must-have code runner for Laravel developers. Tinker with AI, autocompletion and instant feedback on local and production environments.

Tinkerwell
Get expert guidance in a few days with a Laravel code review logo

Get expert guidance in a few days with a Laravel code review

Expert code review! Get clear, practical feedback from two Laravel devs with 10+ years of experience helping teams build better apps.

Get expert guidance in a few days with a Laravel code review
PhpStorm logo

PhpStorm

The go-to PHP IDE with extensive out-of-the-box support for Laravel and its ecosystem.

PhpStorm
Laravel Cloud logo

Laravel Cloud

Easily create and manage your servers and deploy your Laravel applications in seconds.

Laravel Cloud
Kirschbaum logo

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum
Shift logo

Shift

Running an old Laravel version? Instant, automated Laravel upgrades and code modernization to keep your applications fresh.

Shift
Harpoon: Next generation time tracking and invoicing logo

Harpoon: Next generation time tracking and invoicing

The next generation time-tracking and billing software that helps your agency plan and forecast a profitable future.

Harpoon: Next generation time tracking and invoicing
Lucky Media logo

Lucky Media

Get Lucky Now - the ideal choice for Laravel Development, with over a decade of experience!

Lucky Media
SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a Multi-tenant Laravel SaaS Starter Kit that comes with all features required to run a modern SaaS. Payments, Beautiful Checkout, Admin Panel, User dashboard, Auth, Ready Components, Stats, Blog, Docs and more.

SaaSykit: Laravel SaaS Starter Kit

The latest

View all →
Statamic 6 Is Officially Released image

Statamic 6 Is Officially Released

Read article
Livewire 4 and Blade Improvements in Laravel VS Code Extension v1.5.0 image

Livewire 4 and Blade Improvements in Laravel VS Code Extension v1.5.0

Read article
Manage PostgreSQL Databases Directly in VS Code with Microsoft's Extension image

Manage PostgreSQL Databases Directly in VS Code with Microsoft's Extension

Read article
NativePHP for Mobile Is Now Free image

NativePHP for Mobile Is Now Free

Read article
Fuse for Laravel: A Circuit Breaker Package for Queue Jobs image

Fuse for Laravel: A Circuit Breaker Package for Queue Jobs

Read article
Generate Complete Application Modules with a Single Command using Laravel TurboMaker image

Generate Complete Application Modules with a Single Command using Laravel TurboMaker

Read article