detect_agent
This is a Python port of Vercel's
detect-agentpackage.
A lightweight utility for detecting if code is being executed by an AI agent or automated development environment.
Installation
uv add detect_agent
Usage
from detect_agent import determine_agent
result = determine_agent()
if result["is_agent"]:
agent = result["agent"]
print(f"Running in {agent['name']} environment")
# Adapt behavior for AI agent context
Agent Definitions
Detection rules are vendored from upstream agents.json (validated against agents.schema.json) and evaluated in array order; the first match wins.
Supported Agents
This package can detect the following AI agents and development environments:
- Cursor (Anysphere)
- Claude Code (Anthropic)
- Claude Cowork (Anthropic)
- Kimi Code (Moonshot AI)
- Grok Build (xAI)
- Devin (Cognition Labs)
- Gemini CLI (Google)
- Codex (OpenAI)
- Antigravity (Google DeepMind)
- Augment
- Cline
- OpenCode
- OpenClaw
- Goose (Block)
- Junie (JetBrains)
- Kiro (AWS)
- Pi
- GitHub Copilot
- Replit
- Custom agents (via the
AI_AGENTenvironment variable)
See agents.json for the exact environment variables and conditions used to detect each one.
The AI_AGENT Standard
We're promoting AI_AGENT as a universal environment variable standard for AI development tools. This allows any tool or library to easily detect when it's running in an AI-driven environment.
For AI Tool Developers
Set the AI_AGENT environment variable to identify your tool:
export AI_AGENT="your-tool-name"
# or
AI_AGENT="your-tool-name" your-command
Recommended Naming Convention
- Use lowercase with hyphens for multi-word names
- Include version information if needed, separated by an
@symbol - Examples:
claude-code,cursor-cli,devin@1,custom-agent@2.0
Development
uv sync --extra dev
uv run pytest
# Lint and format check (CI)
uv run ruff check . && uv run ruff format --check .
# Fix and format
uv run ruff check . --fix && uv run ruff format .
Use Cases
Adaptive Behavior
import os
from detect_agent import determine_agent
def setup_environment():
result = determine_agent()
if result["is_agent"]:
agent = result["agent"]
# Running in AI environment - adjust behavior
os.environ["LOG_LEVEL"] = "verbose"
print(f"Detected AI agent: {agent['name']}")
Telemetry and Analytics
import time
from detect_agent import determine_agent
def track_usage(event: str):
result = determine_agent()
analytics.track(
event,
{
"agent": result["agent"]["name"] if result["is_agent"] else "human",
"timestamp": time.time(),
},
)
Feature Toggles
from detect_agent import determine_agent
def should_enable_feature(feature: str) -> bool:
result = determine_agent()
# Enable experimental features for AI agents
if result["is_agent"] and feature == "experimental-ai-mode":
return True
return False
Contributing
Adding New Agent Support
To add support for a new AI agent:
- Sync detection rules from upstream
agents.jsonintodetect_agent/agents.json. Agents are evaluated in array order — the first match wins. - Sync or extend test cases in
tests/testcases.json. - Update this README with the new agent information.
Links
Metadata
Release files for detect_agent 0.6.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| detect_agent-0.6.0.tar.gz | 45.9 kB | Without provenance | Details for detect_agent-0.6.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| detect_agent-0.6.0-py3-none-any.whl | Python 3 | none | any | Details for detect_agent-0.6.0-py3-none-any.whl |
Total release size: 57.3 kB
Release files / detect_agent-0.6.0.tar.gz
| Download URL | detect_agent-0.6.0.tar.gz |
|---|---|
| Size | 45.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e1b1bba5d4e20f59f97aeae4016291f9563818a33ff7c0e8a18c6b948b5cd939
|
|
BLAKE2b-256 checksum How to use checksums |
500762586d442e629fd4208da5dd1bee7bb604898604d9343b0a3fb9c973fc06
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / detect_agent-0.6.0-py3-none-any.whl
| Download URL | detect_agent-0.6.0-py3-none-any.whl |
|---|---|
| Size | 11.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d218806fda221486d886d68526acd950cef9eb09571189968bfc004acd5ca595
|
|
BLAKE2b-256 checksum How to use checksums |
f8654df635649962338b3f4cd4cbb0f360e1354f8b2043b4728284de8a1a3341
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for detect_agent 0.6.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.