Detect AI coding agents from their execution environment or User-Agent
Maintained. Last release 3 months ago, commits in 3 of the last 26 weeks. Weaker on commit activity.
pip install agent-detectorAgent Detector
agent-detector is a small, dependency-free Python package for detecting which
AI coding agent is driving the current process, and for parsing that identity
back out of a User-Agent header on the receiving side.
It returns evidence rather than only a boolean, so callers can distinguish an explicit identity from a broad environmental hint.
Installation
pip install agent-detector
Usage
from agent_detector import detect_agent
detection = detect_agent()
if detection:
print(detection.agent) # "codex"
print(detection.confidence) # "high"
print(detection.signal) # "CODEX_THREAD_ID"
The returned DetectionResult contains:
agent: anAgentNameliteral containing a supported agent nameconfidence:high,medium, orlowsource:environment,path, oruser-agentsignal: the name of the matched signal, never its value
Pass a mapping to make detection deterministic in tests:
assert detect_agent({"OPENCODE": "1"}).agent == "opencode"
Require a minimum confidence when broad environmental hints are not useful:
detection = detect_agent(minimum_confidence="high")
minimum_confidence is typed as Literal["high", "medium", "low"] and
defaults to "low".
User-Agent propagation
A client can propagate a detected identity to a server as a second User-Agent
product. The value must be exactly two whitespace-separated products:
<product>/<version> AI-Agent/<agent>
For example:
example-cli/1.2.3 AI-Agent/codex
The rules are strict and case-sensitive:
productandversionare both required and must be non-empty RFC 9110 tokens (letters, digits, and!#$%&'*+-.^_`|~; no/, spaces, or parentheses)