Skip to content

Commit

Permalink
Merge pull request #160 from AgentOps-AI/upgraded-telemetry
Browse files Browse the repository at this point in the history
update telemetry with result and error
  • Loading branch information
bboynton97 authored Dec 21, 2024
2 parents 4d5e9f7 + 3d6a646 commit 1efdf66
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 46 deletions.
84 changes: 46 additions & 38 deletions agentstack/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,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

Expand Down Expand Up @@ -151,46 +151,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__":
Expand Down
24 changes: 16 additions & 8 deletions agentstack/telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -26,6 +24,7 @@

import platform
import socket
from typing import Optional
import psutil
import requests
from agentstack import conf
Expand Down Expand Up @@ -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')
Expand All @@ -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

0 comments on commit 1efdf66

Please sign in to comment.