laravel/agent-detector
Lightweight PHP/Laravel utility to detect when your code runs inside an AI agent or automated dev environment. Detect via AgentDetector::detect() or detectAgent(), identify known agents like Cursor, Gemini, Codex, Claude, or custom via env vars.
/opt/.devin), which aligns well with Laravel’s .env configuration system and containerized deployments.AI_AGENT env var, allowing TPMs to extend functionality for proprietary or niche tools.AgentDetector to Laravel\AgentDetector could impact existing integrations.AgentDetected events for observability.composer require laravel/agent-detector
detectAgent() in any PHP file.DetectAgentMiddleware to run detection on every request.AgentDetector to Laravel’s container for dependency injection.AgentDetected) for observability.AI_AGENT), which must be set in .env or runtime./opt/.devin).AgentDetected events) to track usage patterns.printenv or getenv()).AgentDetector::AGENT_ENV_VARS to list all checked variables./opt/.devin) may add ~1-5ms per request if in middleware.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Missing env vars | False negative (agent undetected) | Default to isAgent = false; log warnings. |
| Custom agent not supported | Undetected | Extend KnownAgent enum or use AI_AGENT var. |
| Filesystem check fails (e.g., Devin) | False negative | Fallback to env var checks. |
| PHP < 8.2 | Installation failure | Upgrade PHP or use a legacy fork. |
| High-frequency checks | Minor latency | Cache results or move detection to init phase. |
detectAgent()).AI_AGENT=test-agent in CI to simulate agent behavior.How can I help you explore Laravel packages today?