Download the PHP package avvertix/laravel-agent-request without Composer
On this page you can find all versions of the php package avvertix/laravel-agent-request. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download avvertix/laravel-agent-request
More information about avvertix/laravel-agent-request
Files in avvertix/laravel-agent-request
Package laravel-agent-request
Short Description Attempt to identify if an AI Agent want to browse a page
License MIT
Homepage https://github.com/avvertix/laravel-agent-request
Informations about the package laravel-agent-request
Laravel Agent Request
Detect and manage AI agent HTTP requests in Laravel applications. It identifies AI assistants, crawlers, and data-extraction tools via User-Agent patterns and infrastructure headers, then gives you middleware to block, trace, or serve them differently.
Requirements
- PHP 8.3 or higher
Installation
Install the package via Composer:
The service provider is auto-discovered by Laravel.
Configuration
Agent Request is configurable via environment variables.
| Variable | Default | Description |
|---|---|---|
AGENT_REQUEST_ENABLED |
true |
Set to false to bypass all middleware globally |
AGENT_REQUEST_BLOCK |
— | Comma-separated list of categories to block, e.g. assistant,crawler,tool |
In case you want to configure the detection logic you can publish the configuration file:
Environment variables
Agent categories
We groups known AI agents into three categories:
| Category | AgentType |
Description |
|---|---|---|
| Assistants | AgentType::ASSISTANT |
Agents browsing on behalf of a live user (ChatGPT-User, Claude-User, Gemini, Perplexity-User, …) |
| Crawlers | AgentType::CRAWLER |
Automated training and indexing bots (GPTBot, ClaudeBot, Google-Extended, Applebot, …) |
| Tools | AgentType::TOOL |
AI-powered research and data-extraction tools (Diffbot, FirecrawlAgent, Scrapy, TavilyBot, …) |
Requests that match no known pattern return AgentType::HUMAN.
Usage
Detecting agents in a controller
Inject or type-hint AgentRequest instead of the standard Request:
All detection methods available on AgentRequest:
| Method | Returns | Description |
|---|---|---|
isAgent() |
bool |
Any recognised AI agent |
isAiAssistant() |
bool |
User-facing AI assistant |
isAiCrawler() |
bool |
Training or indexing crawler |
isAiTool() |
bool |
Data-extraction or research tool |
isCloudflareBrowserRendering() |
bool |
Cloudflare Browser Rendering infrastructure |
detect() |
AgentType |
Category of the detected agent |
agentName() |
?string |
Canonical name key of the agent, or null |
wantsMarkdown() |
bool |
Accept header contains text/markdown or text/x-markdown |
expectsMarkdown() |
bool |
wantsMarkdown() or Accept: text/plain |
Middleware
Register middleware in bootstrap/app.php or a route group:
DenyAgentMiddleware
Returns a 404 Not Found response for any agent whose category appears in the agent-request.block config list.
By default assistant and tool agents are blocked; crawler agents are allowed through (they respect robots.txt). To block crawlers too, update the config or set the environment variable:
To disable blocking entirely without removing the middleware:
TraceAgentMiddleware
Adds agent_name and agent_type to the Laravel Context for every recognised AI agent request. Laravel includes them in log entries automatically:
This middleware never blocks. Stack it with DenyAgentMiddleware freely.
Request macros
The package adds two macros to the base Illuminate\Http\Request:
Using DetectAgent directly
Generating a robots.txt
Generate a robots.txt that instructs known AI agents to not crawl your site:
--category accepts assistant, crawler, and tool. Pass it multiple times to combine. Omit it to include all three.
Extending the detector
Extend DetectAgent and override the pattern arrays, then register your class in the config:
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
- Alessio Vertemati
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-agent-request with dependencies
spatie/laravel-package-tools Version ^1.16
illuminate/contracts Version ^11.0||^12.0||^13.0
illuminate/http Version ^11.0||^12.0||^13.0
illuminate/support Version ^11.0||^12.0||^13.0