neurophic / laravel
Laravel integration for the Neurophic memory API: a facade, per-user scoping and optional Laravel AI tools
Requires
- php: ^8.3
- illuminate/container: ^12.0|^13.0
- illuminate/contracts: ^12.0|^13.0
- illuminate/support: ^12.0|^13.0
- neurophic/neurophic: ^0.1
Requires (Dev)
- laravel/ai: ^0.11|^1.0
- orchestra/testbench: ^10.0|^11.0
- pestphp/pest: ^3.0|^4.0
Suggests
- laravel/ai: Required for the RecallTool and RememberTool agent tools (^0.11|^1.0).
Provides
None
Conflicts
None
Replaces
None
This package is not auto-updated.
Last update: 2026-12-02 10:23:32 UTC
README
Laravel integration for the Neurophic memory API: a facade, per-user scoping and tools for the Laravel AI SDK.
Installation
composer require neurophic/laravel
Requires PHP 8.3+ and Laravel 12+.
Set your project key in .env:
NEUROPHIC_API_KEY=nph_xxx
Optionally publish the config:
php artisan vendor:publish --tag=neurophic-config
Usage
use Neurophic\Laravel\Facades\Neurophic; Neurophic::ingest('user-123', 'Prefers oat milk'); Neurophic::retrieve('user-123', 'coffee preferences')->markdown();
The facade takes the same arguments as the neurophic/neurophic client. The client itself is bound in the container, so you can also type-hint Neurophic\Neurophic.
Per-user scoping
Neurophic::for() binds the client to one user, so you never pass an identifier. Given an authenticated user, the identifier is its auth identifier and the display name its name attribute; a plain string works too.
use Neurophic\Enums\MemoryRole; use Neurophic\Enums\RerankMode; $memory = Neurophic::for($request->user()); $memory->ingest('Prefers oat milk'); $memory->ingest('Suggested the flat white', role: MemoryRole::Assistant); $memory->context('coffee preferences'); $memory->retrieve('coffee preferences', rerank: RerankMode::Fast)->markdown(); $memory->retrieve('coffee preferences', sources: true)->structured(); $memory->list(); $memory->get($id); $memory->delete($id);
Laravel AI tools
Give any Laravel AI agent long-term memory with RecallTool and RememberTool. Laravel AI is optional, so install it first:
composer require laravel/ai
namespace App\Ai\Agents; use App\Models\User; use Laravel\Ai\Contracts\Agent; use Laravel\Ai\Contracts\HasTools; use Laravel\Ai\Promptable; use Neurophic\Enums\MemoryRole; use Neurophic\Enums\RerankMode; use Neurophic\Laravel\Ai\RecallTool; use Neurophic\Laravel\Ai\RememberTool; class Assistant implements Agent, HasTools { use Promptable; public function __construct(public User $user) {} public function instructions(): string { return 'You are a helpful assistant with long-term memory. ' .'Recall relevant memories before answering, and remember important new facts.'; } public function tools(): iterable { return [ RecallTool::for($this->user, roles: [MemoryRole::User, MemoryRole::Assistant], rerank: RerankMode::Fast), RememberTool::for($this->user), ]; } }
RememberTooltakescontent.RecallTooltakesqueryand optionalgoal,since,untilandlimit.
roles, sources and rerank on RecallTool::for() apply to every search and are set by you, never by the model.
Or put remembered context straight into the system prompt:
public function instructions(): string { $context = Neurophic::for($this->user)->context('user preferences and history'); return 'You are a helpful assistant.' .($context !== '' ? "\n\n## Context from memory\n{$context}" : ''); }
Laravel AI's built-in conversation memory covers a single conversation. Neurophic is the long-term layer: memories persist across conversations, sessions and channels.
Errors
Every API failure throws Neurophic\Exceptions\NeurophicException. See the neurophic/neurophic README for the error model.
Documentation
Full reference at neurophic.ai/docs/sdk/laravel.
License
MIT