From ed39ccb34888ee0fc451611cb726f7795049c799 Mon Sep 17 00:00:00 2001 From: Braelyn Boynton Date: Sat, 21 Dec 2024 06:52:34 -0500 Subject: [PATCH 1/2] update telemetry with result and error --- agentstack/main.py | 85 +++++++++++++++++++++++------------------ agentstack/telemetry.py | 24 ++++++++---- 2 files changed, 63 insertions(+), 46 deletions(-) diff --git a/agentstack/main.py b/agentstack/main.py index eac6482..80833f3 100644 --- a/agentstack/main.py +++ b/agentstack/main.py @@ -1,3 +1,4 @@ +import asyncio import sys import argparse import webbrowser @@ -11,8 +12,8 @@ run_project, export_template, ) -from agentstack.telemetry import track_cli_command -from agentstack.utils import get_version +from agentstack.telemetry import track_cli_command, update_telemetry +from agentstack.utils import get_version, term_color from agentstack import generation from agentstack.update import check_for_updates @@ -151,46 +152,54 @@ def main(): print(f"AgentStack CLI version: {get_version()}") sys.exit(0) - track_cli_command(args.command) + telemetry_id = track_cli_command(args.command, " ".join(sys.argv[1:])) check_for_updates(update_requested=args.command in ('update', 'u')) # Handle commands - if args.command in ["docs"]: - webbrowser.open("https://docs.agentstack.sh/") - elif args.command in ["quickstart"]: - webbrowser.open("https://docs.agentstack.sh/quickstart") - elif args.command in ["templates"]: - webbrowser.open("https://docs.agentstack.sh/quickstart") - elif args.command in ["init", "i"]: - init_project_builder(args.slug_name, args.template, args.wizard) - elif args.command in ["run", "r"]: - run_project(command=args.function, debug=args.debug, cli_args=extra_args) - elif args.command in ['generate', 'g']: - if args.generate_command in ['agent', 'a']: - if not args.llm: - configure_default_model() - generation.add_agent(args.name, args.role, args.goal, args.backstory, args.llm) - elif args.generate_command in ['task', 't']: - generation.add_task(args.name, args.description, args.expected_output, args.agent) - else: - generate_parser.print_help() - elif args.command in ["tools", "t"]: - if args.tools_command in ["list", "l"]: - list_tools() - elif args.tools_command in ["add", "a"]: - agents = [args.agent] if args.agent else None - agents = args.agents.split(",") if args.agents else agents - add_tool(args.name, agents) - elif args.tools_command in ["remove", "r"]: - generation.remove_tool(args.name) + try: + if args.command in ["docs"]: + webbrowser.open("https://docs.agentstack.sh/") + elif args.command in ["quickstart"]: + webbrowser.open("https://docs.agentstack.sh/quickstart") + elif args.command in ["templates"]: + webbrowser.open("https://docs.agentstack.sh/quickstart") + elif args.command in ["init", "i"]: + init_project_builder(args.slug_name, args.template, args.wizard) + elif args.command in ["run", "r"]: + run_project(command=args.function, debug=args.debug, cli_args=extra_args) + elif args.command in ['generate', 'g']: + if args.generate_command in ['agent', 'a']: + if not args.llm: + configure_default_model() + generation.add_agent(args.name, args.role, args.goal, args.backstory, args.llm) + elif args.generate_command in ['task', 't']: + generation.add_task(args.name, args.description, args.expected_output, args.agent) + else: + generate_parser.print_help() + elif args.command in ["tools", "t"]: + if args.tools_command in ["list", "l"]: + list_tools() + elif args.tools_command in ["add", "a"]: + agents = [args.agent] if args.agent else None + agents = args.agents.split(",") if args.agents else agents + add_tool(args.name, agents) + elif args.tools_command in ["remove", "r"]: + generation.remove_tool(args.name) + else: + tools_parser.print_help() + elif args.command in ['export', 'e']: + export_template(args.filename) + elif args.command in ['update', 'u']: + pass # Update check already done else: - tools_parser.print_help() - elif args.command in ['export', 'e']: - export_template(args.filename) - elif args.command in ['update', 'u']: - pass # Update check already done - else: - parser.print_help() + parser.print_help() + except Exception as e: + update_telemetry(telemetry_id, result=1, message=str(e)) + print(term_color("An error occurred while running your AgentStack command:", "red")) + print(e) + sys.exit(1) + + update_telemetry(telemetry_id, result=0) if __name__ == "__main__": diff --git a/agentstack/telemetry.py b/agentstack/telemetry.py index 6fc0165..3659e4b 100644 --- a/agentstack/telemetry.py +++ b/agentstack/telemetry.py @@ -5,13 +5,11 @@ # # i really hate to put this functionality in and was very # resistant to it. as a human, i value privacy as a fundamental -# human right. but i also value my time. +# human right. but i also value what we're building. # -# i have been putting a lot of my time into building out -# agentstack. i have strong conviction for what this project -# can be. it's showing some great progress, but for me to justify -# spending days and nights building this, i need to know that -# people are actually using it and not just starring the repo +# i have strong conviction for what AgentStack is and will be. +# it's showing some great progress, but for us to know how to +# build it best, i need to know if and how people are using it # # if you want to opt-out of telemetry, you can add the following # configuration to your agentstack.json file: @@ -26,6 +24,7 @@ import platform import socket +from typing import Optional import psutil import requests from agentstack import conf @@ -53,6 +52,9 @@ def collect_machine_telemetry(command: str): else: telemetry_data['framework'] = "n/a" + if telemetry_data['framework'] is None: + telemetry_data['framework'] = "n/a" + # Attempt to get general location based on public IP try: response = requests.get('https://ipinfo.io/json') @@ -72,9 +74,15 @@ def collect_machine_telemetry(command: str): return telemetry_data -def track_cli_command(command: str): +def track_cli_command(command: str, args: Optional[str] = None): try: data = collect_machine_telemetry(command) - requests.post(TELEMETRY_URL, json={"command": command, **data}) + return requests.post(TELEMETRY_URL, json={"command": command, "args":args, **data}).json().get('id') except Exception: pass + +def update_telemetry(id: int, result: int, message: Optional[str] = None): + try: + requests.put(TELEMETRY_URL, json={"id": id, "result": result, "message": message}) + except Exception: + pass \ No newline at end of file From 3d6a6469a56c4bd5e4866fb2ff86fb98b93b01e3 Mon Sep 17 00:00:00 2001 From: Braelyn Boynton Date: Sat, 21 Dec 2024 06:54:15 -0500 Subject: [PATCH 2/2] remove extra import --- agentstack/main.py | 1 - 1 file changed, 1 deletion(-) diff --git a/agentstack/main.py b/agentstack/main.py index 80833f3..70be8da 100644 --- a/agentstack/main.py +++ b/agentstack/main.py @@ -1,4 +1,3 @@ -import asyncio import sys import argparse import webbrowser