Skip to content

Python SDK for AI agent monitoring, LLM cost tracking, benchmarking, and more. Integrates with most LLMs and agent frameworks including CrewAI, Agno, OpenAI Agents SDK, Langchain, Autogen, AG2, and CamelAI

feature: pass host_envs in session

Shawn Qiu4ebd588abec7
diff --git a/agentops/client.py b/agentops/client.py
index 023466f8..6f2d2d85 100644
--- a/agentops/client.py
+++ b/agentops/client.py
@@ -9,6 +9,7 @@ from .event import Event
from .helpers import get_ISO_time
from .session import Session
from .worker import Worker
+from .host_env import get_host_env
from uuid import uuid4
from typing import Optional, List
from pydantic import Field
@@ -233,7 +234,8 @@ class Client:
if not config and not self.config:
return logging.warn("AgentOps: Cannot start session - missing configuration")
- self._session = Session(str(uuid4()), tags or self._tags)
+ self._session = Session(
+ str(uuid4()), tags or self._tags, host_env=get_host_env())
self._worker = Worker(config or self.config)
self._worker.start_session(self._session)
diff --git a/agentops/host_env.py b/agentops/host_env.py
new file mode 100644
index 00000000..1587c9d6
--- /dev/null
+++ b/agentops/host_env.py
@@ -0,0 +1,63 @@
+import platform
+import psutil
+import socket
+
+
+def get_os_details():
+ return {
+ "Hostname": socket.gethostname(),
+ "OS": platform.system(),
+ "OS Version": platform.version(),
+ "OS Release": platform.release()
+ }
+
+
+def get_cpu_details():
+ return {
+ "Physical cores": psutil.cpu_count(logical=False),
+ "Total cores": psutil.cpu_count(logical=True),
+ "Max Frequency": f"{psutil.cpu_freq().max:.2f}Mhz",
+ "CPU Usage": f"{psutil.cpu_percent()}%"
+ }
+
+
+def get_ram_details():
+ ram_info = psutil.virtual_memory()
+ return {
+ "Total": f"{ram_info.total / (1024**3):.2f} GB",
+ "Available": f"{ram_info.available / (1024**3):.2f} GB",
+ "Used": f"{ram_info.used / (1024**3):.2f} GB",
+ "Percentage": f"{ram_info.percent}%"
+ }
+
+
+def get_disk_details():
+ partitions = psutil.disk_partitions()
+ disk_info = {}
+ for partition in partitions:
+ usage = psutil.disk_usage(partition.mountpoint)
+ disk_info[partition.device] = {
+ "Mountpoint": partition.mountpoint,
+ "Total": f"{usage.total / (1024**3):.2f} GB",
+ "Used": f"{usage.used / (1024**3):.2f} GB",
+ "Free": f"{usage.free / (1024**3):.2f} GB",
+ "Percentage": f"{usage.percent}%"
+ }
+ return disk_info
+
+
+def get_host_env():
+ return {
+ "OS": get_os_details(),
+ "CPU": get_cpu_details(),
+ "RAM": get_ram_details(),
+ "Disk": get_disk_details(),
+ }
+
+
+if __name__ == "__main__":
+ print("Gathering system information...")
+ print("OS Details:", get_os_details())
+ print("CPU Details:", get_cpu_details())
+ print("RAM Details:", get_ram_details())
+ print("Disk Details:", get_disk_details())
diff --git a/agentops/session.py b/agentops/session.py
index c23958ca..8b1d8a11 100644
--- a/agentops/session.py
+++ b/agentops/session.py
@@ -19,7 +19,7 @@ class Session:
"""
- def __init__(self, session_id: str, tags: Optional[List[str]] = None):
+ def __init__(self, session_id: str, tags: Optional[List[str]] = None, host_env: Optional[dict] = None):
self.end_timestamp = None
self.rating = None
self.end_state = None
@@ -28,6 +28,7 @@ class Session:
self.tags = tags
self.video = None
self.end_state_reason = None
+ self.host_env = host_env
def set_session_video(self, video: str):
"""