detect_agent
This is a Python Port of Vercels NPM package
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"]:
print(f"Running in {result["agent"]["name"]} environment");
Supported Agents
This package can detect the following AI agents and development environments:
- Custom agents via
AI_AGENTenvironment variable - Cursor (cursor editor and cursor-cli)
- Claude Code (Anthropic's Claude)
- Devin (Cognition Labs)
- Gemini CLI (Google)
- Codex (OpenAI)
- Antigravity (Google DeepMind)
- GitHub Copilot (via
AI_AGENT=github-copilot|github-copilot-cli,COPILOT_MODEL,COPILOT_ALLOW_ALL, orCOPILOT_GITHUB_TOKEN) - Replit (online IDE)
- v0 (Vercel's AI assistant, via
AI_AGENT=v0)
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
from detect_agent import determine_agent
import os
def setup_environment():
result = determine_agent()
if (result["is_agent"]) {
# Running in AI environment - adjust behavior
os.environ.setdefault("TOGETHER_LOG", "debug")
print(f"🤖 Detected AI agent: {result["agent"]["name"]}");
Telemetry and Analytics
from detect_agent import determine_agent
def track_usage(event: string):
result = determine_agent();
analytics.track(event, {
"agent": result["agent"]["name"] if result["is_agent"] else "human",
})
Adding New Agent Support
To add support for a new AI agent:
- Add detection logic to
main.py - Add comprehensive test cases in
test.py - Update this README with the new agent information
- Follow the existing priority order pattern
Metadata
Release files for detect_agent 0.3.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.3.0.tar.gz | 42.0 kB | Without provenance | Details for detect_agent-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| detect_agent-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for detect_agent-0.3.0-py3-none-any.whl |
Total release size: 49.8 kB
Release files / detect_agent-0.3.0.tar.gz
| Download URL | detect_agent-0.3.0.tar.gz |
|---|---|
| Size | 42.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
186e8a80638985574417ba752e74ca1b80341280dc6d4308b0a25b4e7bac50f3
|
|
BLAKE2b-256 checksum How to use checksums |
6b4090675e9934cac99acb4d5df050dbed9418587775ed916f12844c71e6a53f
|
| 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.3.0-py3-none-any.whl
| Download URL | detect_agent-0.3.0-py3-none-any.whl |
|---|---|
| Size | 7.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
14c0ab0b90fca111eafea51d22f24fb187591e2a16eda8cbbe856a204ffdd7aa
|
|
BLAKE2b-256 checksum How to use checksums |
1667746fe6402fbe769431d09965f7808c586dcbb0764b4694d62785a88d8736
|
| 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.3.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.