Skip to content

Commit dabe8f3

Browse files
authored
Merge pull request #52 from AgentOps-AI/telemetry
Telemetry and Run
2 parents 9694ab5 + 722e9a1 commit dabe8f3

6 files changed

Lines changed: 101 additions & 4 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ agentstack tools add <tool_name>
8383

8484
## Running Your Agent
8585

86-
`python src/main.py`
86+
`agentstack run`
8787

8888
Runs the agent project in development mode.<br>
8989

agentstack/cli/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ def insert_template(project_details: dict, framework_name: str, design: dict):
311311
" Next, run:\n"
312312
f" cd {project_metadata.project_slug}\n"
313313
" poetry install\n"
314-
" poetry run python src/main.py\n\n"
314+
" agentstack run\n\n"
315315
" Add agents and tasks with:\n"
316316
" `agentstack generate agent/task <name>`\n\n"
317317
" Run `agentstack quickstart` or `agentstack docs` for next steps.\n"

agentstack/main.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import argparse
2+
import os
23
import sys
34

45
from agentstack.cli import init_project_builder, list_tools
5-
from agentstack.utils import get_version
6+
from agentstack.telemetry import track_cli_command
7+
from agentstack.utils import get_version, get_framework
68
import agentstack.generation as generation
79

810
import webbrowser
@@ -28,6 +30,9 @@ def main():
2830
init_parser.add_argument('slug_name', nargs='?', help="The directory name to place the project in")
2931
init_parser.add_argument('--no-wizard', action='store_true', help="Skip wizard steps")
3032

33+
# 'run' command
34+
run_parser = subparsers.add_parser('run', aliases=['r'], help='Run your agent')
35+
3136
# 'generate' command
3237
generate_parser = subparsers.add_parser('generate', aliases=['g'], help='Generate agents or tasks')
3338

@@ -74,13 +79,19 @@ def main():
7479
print(f"AgentStack CLI version: {get_version()}")
7580
return
7681

82+
track_cli_command(args.command)
83+
7784
# Handle commands
7885
if args.command in ['docs']:
7986
webbrowser.open('https://docs.agentstack.sh/')
8087
if args.command in ['quickstart']:
8188
webbrowser.open('https://docs.agentstack.sh/quickstart')
8289
if args.command in ['init', 'i']:
8390
init_project_builder(args.slug_name, args.no_wizard)
91+
if args.command in ['run', 'r']:
92+
framework = get_framework()
93+
if framework == "crewai":
94+
os.system('python src/main.py')
8495
elif args.command in ['generate', 'g']:
8596
if args.generate_command in ['agent', 'a']:
8697
generation.generate_agent(args.name, args.role, args.goal, args.backstory, args.llm)

agentstack/telemetry.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# hi :)
2+
#
3+
# if you're reading this, you probably saw "telemetry.py" and
4+
# got mad and went to go see how we're spying on you
5+
#
6+
# i really hate to put this functionality in and was very
7+
# resistant to it. as a human, i value privacy as a fundamental
8+
# human right. but i also value my time.
9+
#
10+
# i have been putting a lot of my time into building out
11+
# agentstack. i have strong conviction for what this project
12+
# can be. it's showing some great progress, but for me to justify
13+
# spending days and nights building this, i need to know that
14+
# people are actually using it and not just starring the repo
15+
#
16+
# if you want to opt-out of telemetry, you can add the following
17+
# configuration to your agentstack.json file:
18+
#
19+
# telemetry_opt_out: false
20+
#
21+
# i'm a single developer with a passion, working to lower the barrier
22+
# of entry to building and deploying agents. it would be really
23+
# cool of you to allow telemetry <3
24+
#
25+
# - braelyn
26+
27+
import platform
28+
import socket
29+
import psutil
30+
import requests
31+
from agentstack.utils import get_telemetry_opt_out, get_framework, get_version
32+
33+
# TELEMETRY_URL = 'https://api.agentstack.sh/telemetry'
34+
TELEMETRY_URL = 'http://localhost:3000/telemetry'
35+
36+
def collect_machine_telemetry():
37+
if get_telemetry_opt_out():
38+
return
39+
40+
telemetry_data = {
41+
'os': platform.system(),
42+
'hostname': socket.gethostname(),
43+
'platform': platform.platform(),
44+
'os_version': platform.version(),
45+
'cpu_count': psutil.cpu_count(logical=True),
46+
'memory': psutil.virtual_memory().total,
47+
'framework': get_framework(),
48+
'agentstack_version': get_version()
49+
}
50+
51+
# Attempt to get general location based on public IP
52+
try:
53+
response = requests.get('https://ipinfo.io/json')
54+
if response.status_code == 200:
55+
location_data = response.json()
56+
telemetry_data.update({
57+
'ip': location_data.get('ip'),
58+
'city': location_data.get('city'),
59+
'region': location_data.get('region'),
60+
'country': location_data.get('country')
61+
})
62+
except requests.RequestException as e:
63+
telemetry_data['location_error'] = str(e)
64+
65+
return telemetry_data
66+
67+
68+
def track_cli_command(command):
69+
try:
70+
data = collect_machine_telemetry()
71+
requests.post(TELEMETRY_URL, json={"command": command, **data})
72+
except:
73+
pass

agentstack/utils.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,19 @@ def get_framework(path: Optional[str] = None) -> str:
4141
sys.exit(1)
4242

4343

44+
def get_telemetry_opt_out(path: Optional[str] = None) -> str:
45+
try:
46+
file_path = 'agentstack.json'
47+
if path is not None:
48+
file_path = path + '/' + file_path
49+
50+
agentstack_data = open_json_file(file_path)
51+
opt_out = agentstack_data.get('telemetry_opt_out', False)
52+
return opt_out
53+
except FileNotFoundError:
54+
print("\033[31mFile agentstack.json does not exist. Are you in the right directory?\033[0m")
55+
sys.exit(1)
56+
4457
def camel_to_snake(name):
4558
s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name)
4659
return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower()

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "agentstack"
7-
version = "0.1.9"
7+
version = "0.1.10"
88
description = "The fastest way to build robust AI agents"
99
authors = [
1010
{ name="Braelyn Boynton", email="bboynton97@gmail.com" }

0 commit comments

Comments
 (0)