PHPackages                             eslam-reda-div/filament-copilot - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. eslam-reda-div/filament-copilot

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

eslam-reda-div/filament-copilot
===============================

A Filament plugin for AI-powered copilot features.

v1.0.2(2d ago)1150↑20%3MITPHPPHP ^8.2

Since Mar 12Pushed 2d ago2 watchersCompare

[ Source](https://github.com/eslam-reda-div/filament-copilot)[ Packagist](https://packagist.org/packages/eslam-reda-div/filament-copilot)[ Docs](https://github.com/eslam-reda-div/filament-copilot)[ RSS](/packages/eslam-reda-div-filament-copilot/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (9)Versions (3)Used By (0)

Filament Copilot
================

[](#filament-copilot)

[![Latest Version on Packagist](https://camo.githubusercontent.com/6a6b487a2ac34d5e2e44fce6783e4174a5cfd4dd452aab6c3c722e930b242550/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f65736c616d2d726564612d6469762f66696c616d656e742d636f70696c6f742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/eslam-reda-div/filament-copilot)[![Total Downloads](https://camo.githubusercontent.com/0ddda82fcadb6b98caa7f9539397eeb448317777fa956f8cf12e0d6583c16811/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f65736c616d2d726564612d6469762f66696c616d656e742d636f70696c6f742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/eslam-reda-div/filament-copilot)[![License](https://camo.githubusercontent.com/6ac88cf492f736ed8d47af389106d270c98eb0389c102aef6b92bf0fbf167d6d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f65736c616d2d726564612d6469762f66696c616d656e742d636f70696c6f742e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)

**An AI-powered copilot plugin for FilamentPHP v5.** Give your admin panel a built-in AI assistant that understands your resources, pages, and widgets — powered by the official [Laravel AI SDK](https://github.com/laravel/ai).

Filament Copilot integrates directly into your Filament panels with a chat interface, real-time SSE streaming, tool execution, conversation history, agent memory, audit logging, rate limiting, token budget tracking, and a full management dashboard.

---

Table of Contents
-----------------

[](#table-of-contents)

- [Screenshots](#screenshots)
- [Features](#features)
- [Compatibility](#compatibility)
- [Requirements](#requirements)
- [Installation](#installation)
    - [Step 1 — Install via Composer](#step-1--install-via-composer)
    - [Step 2 — Run the Install Command](#step-2--run-the-install-command)
    - [Step 3 — Manual Installation (Alternative)](#step-3--manual-installation-alternative)
- [Configuration](#configuration)
    - [AI Provider &amp; Model](#ai-provider--model)
    - [Rate Limiting](#rate-limiting)
    - [Token Budget](#token-budget)
    - [Audit Logging](#audit-logging)
    - [Agent Memory](#agent-memory)
    - [Management Dashboard](#management-dashboard)
    - [Quick Actions](#quick-actions)
    - [System Prompt](#system-prompt)
    - [Global Tools](#global-tools)
- [Panel Registration](#panel-registration)
    - [Basic Registration](#basic-registration)
    - [Full Configuration via Plugin API](#full-configuration-via-plugin-api)
- [Making Resources Copilot-Enabled](#making-resources-copilot-enabled)
- [Making Pages Copilot-Enabled](#making-pages-copilot-enabled)
- [Making Widgets Copilot-Enabled](#making-widgets-copilot-enabled)
- [Creating Copilot Tools](#creating-copilot-tools)
    - [Using the Generator Command](#using-the-generator-command)
    - [Tool Templates](#tool-templates)
    - [Writing a Custom Tool](#writing-a-custom-tool)
    - [Folder Structure](#folder-structure)
    - [Registering Tools](#registering-tools)
- [Built-in Tools](#built-in-tools)
- [User Model Setup](#user-model-setup)
- [How It Works](#how-it-works)
    - [Architecture](#architecture)
    - [Streaming](#streaming)
    - [Agent &amp; Context Building](#agent--context-building)
    - [Tool Execution Flow](#tool-execution-flow)
- [Events](#events)
- [Models &amp; Database](#models--database)
- [Management Dashboard](#management-dashboard-1)
- [Customization](#customization)
    - [Custom System Prompt](#custom-system-prompt)
    - [Authorization](#authorization)
    - [Translations](#translations)
    - [Views](#views)
    - [Publishing Stubs](#publishing-stubs)
- [Testing](#testing)
- [Supported AI Providers](#supported-ai-providers)
- [Contributing](#contributing)
- [Security](#security)
- [Credits](#credits)
- [License](#license)

---

Screenshots
-----------

[](#screenshots)

 [![Filament Copilot Screenshot 1](screenshot-1.png)](screenshot-1.png)

 [![Filament Copilot Screenshot 2](screenshot-2.png)](screenshot-2.png)

 [![Filament Copilot Screenshot 3](screenshot-3.png)](screenshot-3.png)

 [![Filament Copilot Screenshot 4](screenshot-4.png)](screenshot-4.png)

 [![Filament Copilot Screenshot 5](screenshot-5.png)](screenshot-5.png)

 [![Filament Copilot Screenshot 6](screenshot-6.png)](screenshot-6.png)

 [![Filament Copilot Screenshot 7](screenshot-7.png)](screenshot-7.png)

 [![Filament Copilot Screenshot 8](screenshot-8.png)](screenshot-8.png)

---

Features
--------

[](#features)

- **AI Chat Interface** — A beautiful, real-time chat modal built with Livewire, injected directly into your Filament panels.
- **Real-Time SSE Streaming** — Responses stream token-by-token via Server-Sent Events for an instant, interactive experience.
- **Context-Aware Agent** — The AI agent automatically discovers your copilot-enabled resources, pages, and widgets and builds context from them.
- **Tool Execution** — The agent can call tools you define to list, search, create, edit, delete, and restore records — or perform any custom action.
- **9 Tool Templates** — Generate tools instantly with the `make:copilot-tool` artisan command (list, view, search, create, edit, delete, force-delete, restore, custom).
- **Conversation History** — Full conversation persistence with a sidebar for browsing, loading, and deleting past conversations.
- **Agent Memory** — The AI remembers facts across conversations using a per-user key-value memory store (Remember &amp; Recall tools).
- **Audit Logging** — Comprehensive audit trail tracking messages, tool calls, record access, and navigation events.
- **Rate Limiting** — Per-user hourly/daily message and token rate limits with automatic blocking and unblocking.
- **Token Budget Tracking** — Daily and monthly token budget tracking with configurable warning thresholds.
- **Management Dashboard** — Optional admin dashboard with stats overview, token usage charts, top users table, and full Filament resources for conversations, audit logs, and rate limits.
- **Quick Actions** — Define canned prompt shortcuts that appear in the chat for one-click common queries.
- **8 Supported AI Providers** — OpenAI, Anthropic, Google Gemini, Groq, xAI, DeepSeek, Mistral, and Ollama (local models).
- **Keyboard Shortcut** — Open the copilot with `Ctrl+Shift+K` from anywhere in your panel.
- **Authorization Aware** — Respects Filament's authorization policies out of the box.
- **Fully Translatable** — All UI strings are translatable with a complete English language file (100+ keys).
- **Publishable Assets, Config, Views, Stubs** — Customize everything to fit your needs.
- **81 Tests** — Comprehensive test suite covering models, services, tools, Livewire components, discovery, enums, config, plugin, and streaming.

---

Compatibility
-------------

[](#compatibility)

DependencyVersionPHP^8.2Laravel11.x / 12.xFilament^5.0Livewire^3.5 (ships with Filament v5)Laravel AI SDK^0.2.7Spatie Laravel Package Tools^1.16> **Note:** This package is built for **Filament v5** and **Livewire 3.5+** (as bundled with Filament v5). It leverages the official **Laravel AI SDK** (`laravel/ai`) for all AI operations.

---

Requirements
------------

[](#requirements)

- PHP 8.2 or higher
- Laravel 11 or 12
- Filament v5
- A supported AI provider API key (or Ollama for local models)
- Node.js (only if you need to rebuild the CSS assets)

---

Installation
------------

[](#installation)

### Step 1 — Install via Composer

[](#step-1--install-via-composer)

```
composer require eslam-reda-div/filament-copilot
```

### Step 2 — Run the Install Command

[](#step-2--run-the-install-command)

The interactive installer will guide you through all setup steps:

```
php artisan filament-copilot:install
```

This command will:

1. **Publish the configuration** file to `config/filament-copilot.php`
2. **Publish CSS/JS assets** to `public/vendor/filament-copilot/`
3. **Publish and run database migrations** (7 tables)
4. **Publish the Laravel AI SDK config** (`config/ai.php`)
5. **Configure your AI provider** (OpenAI, Anthropic, Gemini, etc.)
6. **Select your AI model** from popular options or enter a custom one
7. **Set up your API key** in the `.env` file
8. **Display a summary** of all configured settings

### Step 3 — Manual Installation (Alternative)

[](#step-3--manual-installation-alternative)

If you prefer to set things up manually:

```
# Publish configuration
php artisan vendor:publish --tag=filament-copilot-config

# Publish assets
php artisan vendor:publish --tag=filament-copilot-assets

# Publish migrations
php artisan vendor:publish --tag=filament-copilot-migrations

# Run migrations
php artisan migrate

# Publish Laravel AI SDK config
php artisan vendor:publish --tag=ai-config
```

Then add the following to your `.env` file:

```
COPILOT_PROVIDER=openai
COPILOT_MODEL=gpt-4o
OPENAI_API_KEY=your-api-key-here
```

---

Configuration
-------------

[](#configuration)

The configuration file is published to `config/filament-copilot.php`. Here is a breakdown of every option:

### AI Provider &amp; Model

[](#ai-provider--model)

```
'provider' => env('COPILOT_PROVIDER', 'openai'),
'model'    => env('COPILOT_MODEL'),
```

Set via your `.env` file. See [Supported AI Providers](#supported-ai-providers) for the full list.

### Rate Limiting

[](#rate-limiting)

```
'rate_limits' => [
    'enabled'               => false,
    'max_messages_per_hour'  => 60,
    'max_messages_per_day'   => 500,
    'max_tokens_per_hour'    => 100000,
    'max_tokens_per_day'     => 1000000,
],
```

Per-user rate limiting with automatic blocking. Control messages and tokens per hour and per day.

### Token Budget

[](#token-budget)

```
'token_budget' => [
    'enabled'             => false,
    'warn_at_percentage'  => 80,
    'daily_budget'        => null,
    'monthly_budget'      => null,
],
```

Track your AI spending with daily/monthly token budgets and configurable warning thresholds.

### Audit Logging

[](#audit-logging)

```
'audit' => [
    'enabled'            => true,
    'log_messages'       => true,
    'log_tool_calls'     => true,
    'log_record_access'  => true,
    'log_navigation'     => false,
],
```

Comprehensive audit trail. Enable or disable logging granularly per action type.

### Agent Memory

[](#agent-memory)

```
'memory' => [
    'enabled'              => true,
    'max_memories_per_user' => 100,
],
```

The AI agent can remember facts across conversations. Memories are scoped per-user, per-panel, and per-tenant.

### Management Dashboard

[](#management-dashboard)

```
'management' => [
    'enabled' => false,
    'guard'   => null,
],
```

Enable the built-in management UI to view conversations, audit logs, rate limits, token usage charts, and top users — all within your Filament panel.

### Quick Actions

[](#quick-actions)

```
'quick_actions' => [
    // 'Summarize this page' => 'Summarize what this page is about.',
    // 'List all users'      => 'List all users in the system.',
],
```

Define one-click prompt shortcuts that appear in the chat interface.

### System Prompt

[](#system-prompt)

```
'system_prompt' => null,
```

Override the default system prompt with your own. The agent uses a carefully crafted default prompt that includes context discovery, tool usage guidelines, and response formatting rules.

### Global Tools

[](#global-tools)

```
'global_tools' => [
    // \App\CopilotTools\MyGlobalTool::class,
],
```

Register tool classes that should be available on **every** page across the panel, regardless of which resource, page, or widget the user is on.

---

Panel Registration
------------------

[](#panel-registration)

### Basic Registration

[](#basic-registration)

Register the plugin in your Filament panel provider:

```
use EslamRedaDiv\FilamentCopilot\FilamentCopilotPlugin;

public function panel(Panel $panel): Panel
{
    return $panel
        // ...
        ->plugin(FilamentCopilotPlugin::make());
}
```

### Full Configuration via Plugin API

[](#full-configuration-via-plugin-api)

The plugin offers a fluent API for inline configuration that overrides the config file values:

```
use EslamRedaDiv\FilamentCopilot\FilamentCopilotPlugin;

public function panel(Panel $panel): Panel
{
    return $panel
        ->plugin(
            FilamentCopilotPlugin::make()
                ->provider('anthropic')
                ->model('claude-sonnet-4')
                ->systemPrompt('You are a helpful admin assistant.')
                ->globalTools([
                    \App\CopilotTools\SearchEverythingTool::class,
                ])
                ->quickActions([
                    'Show stats'   => 'Show me a summary of today\'s statistics.',
                    'Recent users' => 'List the 10 most recently created users.',
                ])
                ->managementEnabled()
                ->managementGuard('admin')
                ->rateLimitEnabled()
                ->tokenBudgetEnabled()
                ->dailyTokenBudget(50000)
                ->monthlyTokenBudget(1000000)
                ->memoryEnabled()
                ->maxMemoriesPerUser(200)
                ->respectAuthorization()
                ->authorizeUsing(fn ($user) => $user->is_admin)
        );
}
```

---

Making Resources Copilot-Enabled
--------------------------------

[](#making-resources-copilot-enabled)

Implement the `CopilotResource` interface on any Filament resource to make it discoverable by the AI agent:

```
use EslamRedaDiv\FilamentCopilot\Contracts\CopilotResource;

class UserResource extends Resource implements CopilotResource
{
    // ... your existing resource code ...

    public static function copilotResourceDescription(): ?string
    {
        return 'Manages user accounts including names, emails, roles, and permissions.';
    }

    public static function copilotTools(): array
    {
        return [
            new \App\Filament\Resources\UserResource\CopilotTools\ListUsersTool(),
            new \App\Filament\Resources\UserResource\CopilotTools\SearchUsersTool(),
            new \App\Filament\Resources\UserResource\CopilotTools\CreateUserTool(),
            new \App\Filament\Resources\UserResource\CopilotTools\ViewUserTool(),
            new \App\Filament\Resources\UserResource\CopilotTools\EditUserTool(),
            new \App\Filament\Resources\UserResource\CopilotTools\DeleteUserTool(),
        ];
    }
}
```

---

Making Pages Copilot-Enabled
----------------------------

[](#making-pages-copilot-enabled)

Implement the `CopilotPage` interface on any Filament page:

```
use EslamRedaDiv\FilamentCopilot\Contracts\CopilotPage;

class Dashboard extends Page implements CopilotPage
{
    // ... your existing page code ...

    public static function copilotPageDescription(): ?string
    {
        return 'The main dashboard showing key metrics and recent activity.';
    }

    public static function copilotTools(): array
    {
        return [
            new \App\Filament\Pages\CopilotTools\Dashboard\DashboardStatsTool(),
        ];
    }
}
```

---

Making Widgets Copilot-Enabled
------------------------------

[](#making-widgets-copilot-enabled)

Implement the `CopilotWidget` interface on any Filament widget:

```
use EslamRedaDiv\FilamentCopilot\Contracts\CopilotWidget;

class RevenueChart extends Widget implements CopilotWidget
{
    // ... your existing widget code ...

    public static function copilotWidgetDescription(): ?string
    {
        return 'Displays revenue data over the past 30 days as a line chart.';
    }

    public static function copilotTools(): array
    {
        return [
            new \App\Filament\Widgets\CopilotTools\RevenueChart\GetRevenueDataTool(),
        ];
    }
}
```

---

Creating Copilot Tools
----------------------

[](#creating-copilot-tools)

### Using the Generator Command

[](#using-the-generator-command)

The `make:copilot-tool` artisan command provides an interactive 5-step wizard:

```
php artisan make:copilot-tool
```

**Step 1** — Select the Filament panel
**Step 2** — Choose the tool type (Resource / Page / Widget)
**Step 3** — Select the target (lists only copilot-enabled resources/pages/widgets from the chosen panel)
**Step 4** — Pick a template (9 options for resources, custom for pages/widgets)
**Step 5** — Enter the tool class name (with a smart default using proper English pluralization)

The command generates the tool file in the correct folder and namespace, with a summary table showing all settings.

### Tool Templates

[](#tool-templates)

For **resource tools**, 9 templates are available:

TemplateDescriptionDefault Name Example`list`List records with pagination`ListUsersTool``view`View a single record by ID`ViewUserTool``search`Search records by keyword`SearchUsersTool``create`Create a new record`CreateUserTool``edit`Edit/update an existing record`EditUserTool``delete`Delete a record`DeleteUserTool``force-delete`Permanently delete a record`ForceDeleteUserTool``restore`Restore a soft-deleted record`RestoreUserTool``custom`Blank template`UserTool`For **page and widget tools**, only the `custom` template is available.

### Writing a Custom Tool

[](#writing-a-custom-tool)

Every tool extends `BaseTool` and implements three methods:

```
