diff --git a/agentops/client.py b/agentops/client.py index 7108e3939..8be6e13e7 100644 --- a/agentops/client.py +++ b/agentops/client.py @@ -98,6 +98,7 @@ def __init__( os.environ.get("AGENTOPS_ENV_DATA_OPT_OUT", "False").lower() == "true" ) + self.llm_tracker = None self.config = None try: diff --git a/agentops/helpers.py b/agentops/helpers.py index 24b623a3c..a63c2b1e9 100644 --- a/agentops/helpers.py +++ b/agentops/helpers.py @@ -23,7 +23,8 @@ def singleton(class_): instances = {} def getinstance(*args, **kwargs): - if class_ not in instances: + allow_multiple_instances = kwargs.pop("allow_multiple_instances", False) + if allow_multiple_instances or class_ not in instances: instances[class_] = class_(*args, **kwargs) return instances[class_] diff --git a/tests/test_teardown.py b/tests/test_teardown.py index 2a59e297f..455d0b756 100644 --- a/tests/test_teardown.py +++ b/tests/test_teardown.py @@ -20,8 +20,19 @@ class TestSessions: def setup_method(self): self.api_key = "random_api_key" self.event_type = "test_event_type" - self.client = Client(self.api_key) + self.client = Client(self.api_key, allow_multiple_instances=False) def test_exit(self): # Tests should not hang. ... + + def test_can_stop_with_no_instrumentation(self): + non_instrumented = Client(self.api_key, instrument_llm_calls=False, + allow_multiple_instances=True) + assert non_instrumented.llm_tracker is None + non_instrumented.stop_instrumenting() + + def test_initializes_llm_tracker_when_enabled(self): + instrumented = Client(self.api_key, instrument_llm_calls=True, + allow_multiple_instances=True) + assert instrumented.llm_tracker is not None