Detect if code is running in an AI agent or automated development environment
Project description
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)
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file detect_agent-0.1.1.tar.gz.
File metadata
- Download URL: detect_agent-0.1.1.tar.gz
- Upload date:
- Size: 14.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
28e6070ce4e0e17a400bbe391c957056bda93656b344de7e06eae5aeb5fbdc2a
|
|
| MD5 |
a7db169de6059c42601d364bde913265
|
|
| BLAKE2b-256 |
40c2ccda387b261abae034896acd206133dbfa11a42ec8905ab3dbd9182b543a
|
File details
Details for the file detect_agent-0.1.1-py3-none-any.whl.
File metadata
- Download URL: detect_agent-0.1.1-py3-none-any.whl
- Upload date:
- Size: 3.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
63ebe8e6175fb6e7e178212033a85d61a0bdd1f11d057141c6302e001a995d6d
|
|
| MD5 |
ea10bcc2e2d7f336cd9f2691667a7814
|
|
| BLAKE2b-256 |
ec06a8069264201af537423292ce7e65d85581303e7631d003f694dbb7bdc39b
|