| Install | |
|---|---|
composer require eslam-reda-div/filament-copilot |
|
| Latest Version: | 1.0.0 |
| PHP: | ^8.2 |
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.
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.
make:copilot-tool artisan command (list, view, search, create, edit, delete, force-delete, restore, custom).Ctrl+Shift+K from anywhere in your panel.| Dependency | Version |
|---|---|
| PHP | ^8.2 |
| Laravel | 11.x / 12.x |
| Filament | ^5.0 |
| Livewire | ^3.5 (ships with Filament v5) |
| Laravel AI SDK | ^0.2.7 |
| Spatie 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.
composer require eslam-reda-div/filament-copilot
The interactive installer will guide you through all setup steps:
php artisan filament-copilot:install
This command will:
config/filament-copilot.phppublic/vendor/filament-copilot/config/ai.php).env fileIf 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
The configuration file is published to config/filament-copilot.php. Here is a breakdown of every option:
'provider' => env('COPILOT_PROVIDER', 'openai'),
'model' => env('COPILOT_MODEL'),
Set via your .env file. See Supported AI Providers for the full list.
'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' => [
'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' => [
'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.
'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' => [
'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' => [
// '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' => 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' => [
// \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.
Register the plugin in your Filament panel provider:
use EslamRedaDiv\FilamentCopilot\FilamentCopilotPlugin;
public function panel(Panel $panel): Panel
{
return $panel
// ...
->plugin(FilamentCopilotPlugin::make());
}
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)
);
}
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(),
];
}
}
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(),
];
}
}
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(),
];
}
}
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.
For resource tools, 9 templates are available:
| Template | Description | Default 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.
Every tool extends BaseTool and implements three methods:
<?php
declare(strict_types=1);
namespace App\Filament\Resources\UserResource\CopilotTools;
use App\Filament\Resources\UserResource;
use EslamRedaDiv\FilamentCopilot\Tools\BaseTool;
use Illuminate\Contracts\JsonSchema\JsonSchema;
use Laravel\Ai\Tools\Request;
use Stringable;
class SearchUsersTool extends BaseTool
{
/**
* A description of what this tool does — shown to the AI agent.
*/
public function description(): Stringable|string
{
return 'Search users by name or email.';
}
/**
* The JSON Schema defining the tool's parameters.
*/
public function schema(JsonSchema $schema): array
{
return [
'query' => $schema->string()
->description('The search keyword (name or email)')
->required(),
'limit' => $schema->integer()
->description('Maximum number of results to return')
->default(10),
];
}
/**
* Execute the tool and return a string result to the AI agent.
*/
public function handle(Request $request): Stringable|string
{
$model = UserResource::getModel();
$query = (string) $request['query'];
$limit = (int) ($request['limit'] ?? 10);
$results = $model::query()
->where('name', 'like', "%{$query}%")
->orWhere('email', 'like', "%{$query}%")
->limit($limit)
->get(['id', 'name', 'email']);
if ($results->isEmpty()) {
return "No users found matching '{$query}'.";
}
return $results->map(fn ($user) =>
"#{$user->id} — {$user->name} ({$user->email})"
)->implode("\n");
}
}
Tools are generated in a specific folder structure depending on the type:
Resource tools:
app/Filament/Resources/
└── UserResource/
├── UserResource.php
└── CopilotTools/
├── ListUsersTool.php
├── SearchUsersTool.php
├── CreateUserTool.php
└── ...
Page tools:
app/Filament/Pages/
├── Dashboard.php
└── CopilotTools/
└── Dashboard/
└── DashboardStatsTool.php
Widget tools:
app/Filament/Widgets/
├── RevenueChart.php
└── CopilotTools/
└── RevenueChart/
└── GetRevenueDataTool.php
After generating a tool, register it in the copilotTools() method of your resource, page, or widget:
public static function copilotTools(): array
{
return [
new \App\Filament\Resources\UserResource\CopilotTools\ListUsersTool(),
new \App\Filament\Resources\UserResource\CopilotTools\SearchUsersTool(),
];
}
The following tools are automatically available to the AI agent without any configuration:
| Tool | Description |
|---|---|
ListResourcesTool |
Lists all copilot-enabled resources in the current panel |
ListPagesTool |
Lists all copilot-enabled pages in the current panel |
ListWidgetsTool |
Lists all copilot-enabled widgets in the current panel |
GetToolsTool |
Discovers available tools for a specific resource, page, or widget |
RunToolTool |
Executes a discovered tool with provided arguments |
RememberTool |
Stores a key-value memory for the current user |
RecallTool |
Retrieves a stored memory (or lists all memories) |
The agent uses these tools to navigate your panel structure and execute operations dynamically.
To enable conversation history on your User model, add the HasCopilotChat trait:
use EslamRedaDiv\FilamentCopilot\Concerns\HasCopilotChat;
class User extends Authenticatable
{
use HasCopilotChat;
// ...
}
This adds a copilotConversations() polymorphic relationship to your user model.
┌─────────────────────────────────────────────────────┐
│ Filament Panel │
│ │
│ ┌──────────┐ ┌───────────────┐ ┌──────────────┐ │
│ │ Copilot │ │ Conversation │ │ Copilot │ │
│ │ Button │──│ Sidebar │ │ Chat │ │
│ └──────────┘ └───────────────┘ └──────┬───────┘ │
│ │ │
│ SSE Stream │
│ │ │
├───────────────────────────────────────────┼─────────┤
│ ▼ │
│ ┌────────────────────────────────────────────────┐ │
│ │ StreamController │ │
│ │ Auth → Rate Limit → Build Agent → Stream │ │
│ └──────────────────────┬─────────────────────────┘ │
│ │ │
│ ┌───────────────────────▼───────────────────────┐ │
│ │ CopilotAgent │ │
│ │ Temperature: 0.3 | MaxTokens: 4096 │ │
│ │ Middleware: Audit + RateLimit │ │
│ └───────────────────────┬───────────────────────┘ │
│ │ │
│ ┌───────────┐ ┌───────▼────────┐ ┌───────────┐ │
│ │ Context │ │ Tool Registry │ │ Conversa- │ │
│ │ Builder │ │ (built-in + │ │ tion │ │
│ │ │ │ global + │ │ Manager │ │
│ │ • Resources│ │ per-target) │ │ │ │
│ │ • Pages │ └────────────────┘ └───────────┘ │
│ │ • Widgets │ │
│ │ • Memory │ │
│ └───────────┘ │
│ │
│ ┌──────────────────────────────────────────────┐ │
│ │ Laravel AI SDK │ │
│ │ OpenAI | Anthropic | Gemini | Groq | ... │ │
│ └──────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────┘
POST request is made to /copilot/stream.StreamController validates auth, checks rate limits, and creates/loads the conversation.CopilotAgent is built with tools, messages, and middleware.The ContextBuilder assembles the system prompt from multiple sources:
RunToolTool resolves the target tool class and executes it with the provided arguments.copilot_tool_calls table with full status tracking.Filament Copilot dispatches the following events that you can listen to:
| Event | When |
|---|---|
CopilotConversationCreated |
A new conversation is created |
CopilotMessageSent |
A user sends a message |
CopilotResponseReceived |
The AI agent responds |
CopilotToolExecuted |
A tool is executed |
CopilotToolApprovalRequired |
A tool requires user approval before execution |
CopilotRateLimitExceeded |
A user exceeds their rate limit |
// In your EventServiceProvider or event discovery
use EslamRedaDiv\FilamentCopilot\Events\CopilotToolExecuted;
class LogToolExecution
{
public function handle(CopilotToolExecuted $event): void
{
logger()->info('Tool executed', [
'tool' => $event->toolCall->tool_class,
'user_id' => $event->toolCall->conversation->participant_id,
]);
}
}
The package creates 7 database tables:
| Table | Model | Description |
|---|---|---|
copilot_conversations |
CopilotConversation |
Conversation storage with polymorphic participant and tenant |
copilot_messages |
CopilotMessage |
Message history with role enum and token tracking |
copilot_tool_calls |
CopilotToolCall |
Tool call tracking with approval status workflow |
copilot_audit_logs |
CopilotAuditLog |
Detailed audit trail with 25 action types |
copilot_rate_limits |
CopilotRateLimit |
Per-user rate limit configuration and blocking |
copilot_token_usages |
CopilotTokenUsage |
Daily token usage tracking per model and provider |
copilot_agent_memories |
CopilotAgentMemory |
Per-user key-value memory store |
All models use ULIDs as primary keys and support polymorphic relationships for participant and tenant.
| Enum | Values |
|---|---|
MessageRole |
User, Assistant, System, Tool |
ToolCallStatus |
Pending, Approved, Rejected, Executed, Failed |
AuditAction |
25 actions including MessageSent, ToolCalled, RecordCreated, RecordDeleted, etc. |
Enable the management dashboard to monitor copilot usage from within your Filament panel:
FilamentCopilotPlugin::make()
->managementEnabled()
->managementGuard('admin') // optional: restrict to specific guard
This adds:
Override the default system prompt via config or the plugin API:
// config/filament-copilot.php
'system_prompt' => 'You are a helpful assistant for our e-commerce admin panel. Focus on order management and customer support.',
Or via the plugin:
FilamentCopilotPlugin::make()
->systemPrompt('You are a helpful assistant for our e-commerce admin panel.')
Control who can access the copilot:
FilamentCopilotPlugin::make()
->authorizeUsing(fn ($user) => $user->hasRole('admin'))
The package also respects Filament's built-in authorization policies when respect_authorization is enabled (default: true).
Publish the translation files to customize all UI strings:
php artisan vendor:publish --tag=filament-copilot-translations
The package ships with a complete English translation file containing 100+ keys.
Publish the Blade views to customize the UI:
php artisan vendor:publish --tag=filament-copilot-views
Publish the tool generator stubs to customize the generated tool templates:
php artisan vendor:publish --tag=filament-copilot-stubs
Stubs are published to stubs/filament-copilot/ in your project root.
The package includes 81 tests with 159 assertions covering:
Run the tests:
cd packages/filament-copilot
php vendor/bin/pest
| Provider | Env Key | Example Models |
|---|---|---|
| OpenAI | OPENAI_API_KEY |
gpt-4o, gpt-4o-mini, o3, o4-mini |
| Anthropic | ANTHROPIC_API_KEY |
claude-sonnet-4, claude-opus-4, claude-haiku-4 |
| Google Gemini | GEMINI_API_KEY |
gemini-2.0-flash, gemini-2.5-pro, gemini-2.5-flash |
| Groq | GROQ_API_KEY |
llama-3.3-70b-versatile, mixtral-8x7b |
| xAI | XAI_API_KEY |
grok-3, grok-3-mini |
| DeepSeek | DEEPSEEK_API_KEY |
deepseek-chat, deepseek-reasoner |
| Mistral | MISTRAL_API_KEY |
mistral-large-latest, codestral-latest |
| Ollama | (none — local) | llama3, mistral, codellama, phi3 |
Configure via .env:
COPILOT_PROVIDER=openai
COPILOT_MODEL=gpt-4o
OPENAI_API_KEY=sk-...
We warmly welcome contributions from the Laravel and FilamentPHP open-source community! Whether it's a bug fix, a new feature, improved documentation, or just a typo fix — every contribution matters and is greatly appreciated.
git checkout -b feature/my-awesome-feature
php vendor/bin/pest
git commit -m "Add: my awesome feature"
Found a bug? Have a question? Want to request a feature?
We review all issues and pull requests and try to respond as quickly as possible. Thank you to everyone who takes the time to help improve this package — you're what makes the open-source ecosystem great! ❤️
# Clone the repository
git clone https://github.com/eslam-reda-div/filament-copilot.git
cd filament-copilot
# Install dependencies
composer install
# Run tests
php vendor/bin/pest
# Build assets (if modifying CSS)
npm install
npm run build
If you discover a security vulnerability, please report it responsibly. Send an email to the maintainer instead of opening a public issue. All security vulnerabilities will be promptly addressed.
Built with:
The MIT License (MIT). Please see LICENSE.md for more information.