From 4c1623ccb0699a79eb3ebdc363c1c110efec2a3f Mon Sep 17 00:00:00 2001 From: Braelyn Boynton Date: Tue, 30 Apr 2024 15:05:51 -0700 Subject: [PATCH 1/4] allow host env opt out --- agentops/__init__.py | 7 +++++-- agentops/client.py | 8 ++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/agentops/__init__.py b/agentops/__init__.py index 6cd37a41..aa80481f 100755 --- a/agentops/__init__.py +++ b/agentops/__init__.py @@ -20,7 +20,8 @@ def init(api_key: Optional[str] = None, override: Optional[bool] = None, # Deprecated instrument_llm_calls=True, auto_start_session=True, - inherited_session_id: Optional[str] = None + inherited_session_id: Optional[str] = None, + env_data_opt_out: Optional[bool] = False ): """ Initializes the AgentOps singleton pattern. @@ -42,6 +43,7 @@ def init(api_key: Optional[str] = None, instrument_llm_calls (bool): Whether to instrument LLM calls and emit LLMEvents.. auto_start_session (bool): Whether to start a session automatically when the client is created. inherited_session_id (optional, str): Init Agentops with an existing Session + env_data_opt_out (optional, bool): Opt out of AgentOps tracking environment data for debugging like storage, memory and CPU Attributes: """ set_logging_level_info() @@ -54,7 +56,8 @@ def init(api_key: Optional[str] = None, override=override, instrument_llm_calls=instrument_llm_calls, auto_start_session=auto_start_session, - inherited_session_id=inherited_session_id + inherited_session_id=inherited_session_id, + env_data_opt_out=env_data_opt_out ) return inherited_session_id or c.current_session_id diff --git a/agentops/client.py b/agentops/client.py index 2aa90e00..43755272 100644 --- a/agentops/client.py +++ b/agentops/client.py @@ -50,6 +50,7 @@ class Client(metaclass=MetaClient): instrument_llm_calls (bool): Whether to instrument LLM calls and emit LLMEvents.. auto_start_session (bool): Whether to start a session automatically when the client is created. inherited_session_id (optional, str): Init Agentops with an existing Session + env_data_opt_out (optional, bool): Opt out of AgentOps tracking environment data for debugging like storage, memory and CPU Attributes: _session (Session, optional): A Session is a grouping of events (e.g. a run of your agent). _worker (Worker, optional): A Worker manages the event queue and sends session updates to the AgentOps api server @@ -65,7 +66,8 @@ def __init__(self, override: Optional[bool] = None, # Deprecated instrument_llm_calls=True, auto_start_session=True, - inherited_session_id: Optional[str] = None + inherited_session_id: Optional[str] = None, + env_data_opt_out: Optional[bool] = False ): if override is not None: @@ -77,6 +79,8 @@ def __init__(self, self._worker = None self._tags = tags + self._env_data_opt_out = env_data_opt_out + try: self.config = Configuration(api_key=api_key, parent_key=parent_key, @@ -234,7 +238,7 @@ def start_session(self, tags: Optional[List[str]] = None, config: Optional[Confi if not config and not self.config: return logger.warning("🖇 AgentOps: Cannot start session - missing configuration") - self._session = Session(inherited_session_id or uuid4(), tags or self._tags, host_env=get_host_env()) + self._session = Session(inherited_session_id or uuid4(), tags or self._tags, host_env=(get_host_env() if self._env_data_opt_out else None)) self._worker = Worker(config or self.config) start_session_result = self._worker.start_session(self._session) if not start_session_result: From b2101b722f21fc20281d781b65a6add07879a44d Mon Sep 17 00:00:00 2001 From: Braelyn Boynton Date: Tue, 30 Apr 2024 15:40:03 -0700 Subject: [PATCH 2/4] still get sdk and os --- agentops/client.py | 2 +- agentops/host_env.py | 22 ++++++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/agentops/client.py b/agentops/client.py index 43755272..e41fa99b 100644 --- a/agentops/client.py +++ b/agentops/client.py @@ -238,7 +238,7 @@ def start_session(self, tags: Optional[List[str]] = None, config: Optional[Confi if not config and not self.config: return logger.warning("🖇 AgentOps: Cannot start session - missing configuration") - self._session = Session(inherited_session_id or uuid4(), tags or self._tags, host_env=(get_host_env() if self._env_data_opt_out else None)) + self._session = Session(inherited_session_id or uuid4(), tags or self._tags, host_env=get_host_env(self._env_data_opt_out)) self._worker = Worker(config or self.config) start_session_result = self._worker.start_session(self._session) if not start_session_result: diff --git a/agentops/host_env.py b/agentops/host_env.py index 42974a43..3b289033 100644 --- a/agentops/host_env.py +++ b/agentops/host_env.py @@ -54,11 +54,17 @@ def get_disk_details(): return disk_info -def get_host_env(): - return { - "SDK": get_sdk_details(), - "OS": get_os_details(), - "CPU": get_cpu_details(), - "RAM": get_ram_details(), - "Disk": get_disk_details(), - } +def get_host_env(opt_out: bool = False): + if opt_out: + return { + "SDK": get_sdk_details(), + "OS": get_os_details() + } + else: + return { + "SDK": get_sdk_details(), + "OS": get_os_details(), + "CPU": get_cpu_details(), + "RAM": get_ram_details(), + "Disk": get_disk_details(), + } From 81c13269859be3cc6b03249a41412dcaaa2a0b76 Mon Sep 17 00:00:00 2001 From: Braelyn Boynton Date: Wed, 1 May 2024 16:04:56 -0700 Subject: [PATCH 3/4] use env var --- agentops/__init__.py | 4 +--- agentops/client.py | 7 +++---- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/agentops/__init__.py b/agentops/__init__.py index aa80481f..e6f368dd 100755 --- a/agentops/__init__.py +++ b/agentops/__init__.py @@ -43,7 +43,6 @@ def init(api_key: Optional[str] = None, instrument_llm_calls (bool): Whether to instrument LLM calls and emit LLMEvents.. auto_start_session (bool): Whether to start a session automatically when the client is created. inherited_session_id (optional, str): Init Agentops with an existing Session - env_data_opt_out (optional, bool): Opt out of AgentOps tracking environment data for debugging like storage, memory and CPU Attributes: """ set_logging_level_info() @@ -56,8 +55,7 @@ def init(api_key: Optional[str] = None, override=override, instrument_llm_calls=instrument_llm_calls, auto_start_session=auto_start_session, - inherited_session_id=inherited_session_id, - env_data_opt_out=env_data_opt_out + inherited_session_id=inherited_session_id ) return inherited_session_id or c.current_session_id diff --git a/agentops/client.py b/agentops/client.py index e41fa99b..aead1c13 100644 --- a/agentops/client.py +++ b/agentops/client.py @@ -4,6 +4,7 @@ Classes: Client: Provides methods to interact with the AgentOps service. """ +import os from .event import ActionEvent, ErrorEvent, Event from .enums import EndState @@ -50,7 +51,6 @@ class Client(metaclass=MetaClient): instrument_llm_calls (bool): Whether to instrument LLM calls and emit LLMEvents.. auto_start_session (bool): Whether to start a session automatically when the client is created. inherited_session_id (optional, str): Init Agentops with an existing Session - env_data_opt_out (optional, bool): Opt out of AgentOps tracking environment data for debugging like storage, memory and CPU Attributes: _session (Session, optional): A Session is a grouping of events (e.g. a run of your agent). _worker (Worker, optional): A Worker manages the event queue and sends session updates to the AgentOps api server @@ -66,8 +66,7 @@ def __init__(self, override: Optional[bool] = None, # Deprecated instrument_llm_calls=True, auto_start_session=True, - inherited_session_id: Optional[str] = None, - env_data_opt_out: Optional[bool] = False + inherited_session_id: Optional[str] = None ): if override is not None: @@ -79,7 +78,7 @@ def __init__(self, self._worker = None self._tags = tags - self._env_data_opt_out = env_data_opt_out + self._env_data_opt_out = os.getenv('AGENTOPS_ENV_DATA_OPT_OUT') and os.getenv('AGENTOPS_ENV_DATA_OPT_OUT').lower() == 'true' try: self.config = Configuration(api_key=api_key, From 8dab6a51dddfc0bcdd2a601fc6766e67adcd8cd2 Mon Sep 17 00:00:00 2001 From: Braelyn Boynton Date: Wed, 1 May 2024 16:08:28 -0700 Subject: [PATCH 4/4] use env var --- agentops/__init__.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/agentops/__init__.py b/agentops/__init__.py index e6f368dd..6cd37a41 100755 --- a/agentops/__init__.py +++ b/agentops/__init__.py @@ -20,8 +20,7 @@ def init(api_key: Optional[str] = None, override: Optional[bool] = None, # Deprecated instrument_llm_calls=True, auto_start_session=True, - inherited_session_id: Optional[str] = None, - env_data_opt_out: Optional[bool] = False + inherited_session_id: Optional[str] = None ): """ Initializes the AgentOps singleton pattern.