laravel/agent-detector is a lightweight PHP utility that detects whether your code is running inside an AI agent or an automated development environment. It was published as an official Laravel package in April 2026.As AI agents become deeply integrated into modern development workflows, knowing which environment your code is running in becomes increasingly valuable. Real-world use cases include adjusting log verbosity, applying different rate limits, or returning agent-specific responses depending on whether the caller is a human or an AI agent.
Call AgentDetector::detect() to receive an AgentResult object.
use Laravel\AgentDetector\AgentDetector;use Laravel\AgentDetector\KnownAgent;$result = AgentDetector::detect();if ($result->isAgent) { echo "Running inside: {$result->name}";}// Check for a specific known agentif ($result->knownAgent() === KnownAgent::Claude) { echo "Hello from Claude!";}
You can also use the standalone function:
use function Laravel\AgentDetector\detectAgent;$result = detectAgent();
Determine the execution context in a Laravel middleware and branch logic accordingly:
<?phpnamespace App\Http\Middleware;use Closure;use Illuminate\Http\Request;use Laravel\AgentDetector\AgentDetector;class DetectAiAgent{ public function handle(Request $request, Closure $next): mixed { $agent = AgentDetector::detect(); if ($agent->isAgent) { // Store the agent name as a request attribute $request->attributes->set('ai_agent', $agent->name); } return $next($request); }}
laravel/agent-detector wraps a set of straightforward environment variable checks and a filesystem check into a clean, zero-configuration API. A single call to AgentDetector::detect() is all you need.As AI agents become a standard part of development workflows, understanding who — or what — is executing your code will only grow in importance. From logging and rate limiting to customised responses, this package provides the foundation for making your Laravel application agent-aware.
laravel/agent-detector repository
Source code and the latest list of supported agents.