Skip to content

Commit 852c73f

Browse files
cursor[bot]cursoragentblainekasten
authored
docs: sync README with upstream detect-agent (#12)
* docs: sync README with upstream detect-agent Co-authored-by: Blaine Kasten <blainekasten@gmail.com> * docs: restore README development section placement Co-authored-by: Blaine Kasten <blainekasten@gmail.com> --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Blaine Kasten <blainekasten@gmail.com>
1 parent b52b22f commit 852c73f

1 file changed

Lines changed: 52 additions & 16 deletions

File tree

README.md

Lines changed: 52 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# detect_agent
22

3-
> This is a Python Port of Vercels NPM package
3+
> This is a Python port of Vercel's `@vercel/detect-agent` npm package.
44
55
A lightweight utility for detecting if code is being executed by an AI agent or automated development environment.
66

@@ -18,7 +18,9 @@ from detect_agent import determine_agent
1818
result = determine_agent()
1919

2020
if result["is_agent"]:
21-
print(f"Running in {result["agent"]["name"]} environment");
21+
agent = result["agent"]
22+
print(f"Running in {agent['name']} environment")
23+
# Adapt behavior for AI agent context
2224
```
2325

2426
## Supported Agents
@@ -72,35 +74,69 @@ uv run ruff check . --fix && uv run ruff format .
7274
### Adaptive Behavior
7375

7476
```python
75-
from detect_agent import determine_agent
7677
import os
7778

79+
from detect_agent import determine_agent
80+
81+
7882
def setup_environment():
79-
result = determine_agent()
83+
result = determine_agent()
8084

81-
if (result["is_agent"]) {
82-
# Running in AI environment - adjust behavior
83-
os.environ.setdefault("TOGETHER_LOG", "debug")
84-
print(f"🤖 Detected AI agent: {result["agent"]["name"]}");
85+
if result["is_agent"]:
86+
agent = result["agent"]
87+
# Running in AI environment - adjust behavior
88+
os.environ["LOG_LEVEL"] = "verbose"
89+
print(f"Detected AI agent: {agent['name']}")
8590
```
8691

8792
### Telemetry and Analytics
8893

8994
```python
95+
import time
96+
9097
from detect_agent import determine_agent
9198

92-
def track_usage(event: string):
93-
result = determine_agent();
9499

95-
analytics.track(event, {
96-
"agent": result["agent"]["name"] if result["is_agent"] else "human",
97-
})
100+
def track_usage(event: str):
101+
result = determine_agent()
102+
103+
analytics.track(
104+
event,
105+
{
106+
"agent": result["agent"]["name"] if result["is_agent"] else "human",
107+
"timestamp": time.time(),
108+
},
109+
)
98110
```
111+
112+
### Feature Toggles
113+
114+
```python
115+
from detect_agent import determine_agent
116+
117+
118+
def should_enable_feature(feature: str) -> bool:
119+
result = determine_agent()
120+
121+
# Enable experimental features for AI agents
122+
if result["is_agent"] and feature == "experimental-ai-mode":
123+
return True
124+
125+
return False
126+
```
127+
128+
## Contributing
129+
99130
### Adding New Agent Support
100131

101132
To add support for a new AI agent:
102133

103-
1. Add detection logic to `main.py`
104-
2. Add comprehensive test cases in `test.py`
134+
1. Add detection logic to `detect_agent/__init__.py`
135+
2. Add comprehensive test cases in `tests/test_detect_agent.py`
105136
3. Update this README with the new agent information
106-
4. Follow the existing priority order pattern
137+
4. Follow the existing priority order pattern
138+
139+
## Links
140+
141+
- [GitHub Repository](https://github.com/togethercomputer/detect_agent)
142+
- [Vercel upstream package](https://github.com/vercel/vercel/tree/main/packages/detect-agent)

0 commit comments

Comments
 (0)