Skip to main content

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_AGENT environment 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, or COPILOT_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
  • 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:

  1. Add detection logic to main.py
  2. Add comprehensive test cases in test.py
  3. Update this README with the new agent information
  4. Follow the existing priority order pattern

Metadata

Release files for detect_agent 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for detect_agent 0.1.0
File Size Uploaded Provenance Actions
detect_agent-0.1.0.tar.gz 14.7 kB Without provenance Details for detect_agent-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for detect_agent 0.1.0
File Interpreter ABI Platform Actions
detect_agent-0.1.0-py3-none-any.whl Python 3 none any Details for detect_agent-0.1.0-py3-none-any.whl

Total release size: 18.1 kB

Release files / detect_agent-0.1.0.tar.gz

Download URL detect_agent-0.1.0.tar.gz
Size 14.7 kB
Tags Source
SHA-256 checksum
How to use checksums
15b7eb3e627c822e0c4a972ae7bdc6940d80582d9ad5bf6968836dc5597c24f7
BLAKE2b-256 checksum
How to use checksums
0c961a8a3e0d59932ad26a60a594d11087116dc7d09ea5f2055a72375aa803e5
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release files / detect_agent-0.1.0-py3-none-any.whl

Download URL detect_agent-0.1.0-py3-none-any.whl
Size 3.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
63be6142bbfabb7aba2a48f0dfc0f13530733d8a4c459484a13f105b762559f9
BLAKE2b-256 checksum
How to use checksums
42d021f008ecba2f279feb6fc3168012545d6cc2a137c69a2103d55291ec58b4
Upload date
Uploaded using Trusted Publishing?
What is 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}

Security for detect_agent 0.1.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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page