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
Python agentagentopsagents-sdkaianthropicautogencost-estimationcrewaievalsevaluation-metricsgroqlangchainllmmistralollamaopenaiopenai-agents
dont add duplicate tags (#177)
Braelyn Boyntond1bbee4cdd27
diff --git a/agentops/client.py b/agentops/client.pyindex 2aa90e00..cca33753 100644--- a/agentops/client.py+++ b/agentops/client.py@@ -75,7 +75,6 @@ class Client(metaclass=MetaClient):self._session = Noneself._worker = None- self._tags = tagstry:self.config = Configuration(api_key=api_key,@@ -90,6 +89,8 @@ class Client(metaclass=MetaClient):if auto_start_session:self.start_session(tags, self.config, inherited_session_id)+ else:+ self._tags_for_future_session = tagsif instrument_llm_calls:self.llm_tracker = LlmTracker(self)@@ -102,13 +103,14 @@ class Client(metaclass=MetaClient):Args:tags (List[str]): The list of tags to append."""- if self._tags is not None:- self._tags.extend(tags)+ if self._session.tags is not None:+ for tag in tags:+ if tag not in self._session.tags:+ self._session.tags.append(tag)else:- self._tags = tags+ self._session.tags = tagsif self._session is not None:- self._session.tags = self._tagsself._worker.update_session(self._session)def set_tags(self, tags: List[str]):@@ -118,7 +120,7 @@ class Client(metaclass=MetaClient):Args:tags (List[str]): The list of tags to set."""- self._tags = tags+ self._tags_for_future_session = tagsif self._session is not None:self._session.tags = tags@@ -234,7 +236,7 @@ class Client(metaclass=MetaClient):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_for_future_session, host_env=get_host_env())self._worker = Worker(config or self.config)start_session_result = self._worker.start_session(self._session)if not start_session_result:diff --git a/tests/test_session.py b/tests/test_session.pyindex c553e7bd..d7b92f88 100644--- a/tests/test_session.py+++ b/tests/test_session.py@@ -48,6 +48,25 @@ class TestSessions:assert request_json['session']['end_state'] == end_stateassert request_json['session']['tags'] == None+ def test_add_tags(self, mock_req):+ # Arrange+ tags = ['GPT-4']+ agentops.start_session(tags=tags, config=self.config)+ agentops.add_tags(['test-tag', 'dupe-tag'])+ agentops.add_tags(['dupe-tag'])++ # Act+ end_state = 'Success'+ agentops.end_session(end_state)+ time.sleep(0.15)++ # Assert 3 requests, 1 for session init, 1 for event, 1 for end session+ assert mock_req.last_request.headers['X-Agentops-Auth'] == self.api_key+ request_json = mock_req.last_request.json()+ assert request_json['session']['end_state'] == end_state+ assert request_json['session']['tags'] == ['GPT-4', 'test-tag', 'dupe-tag']++def test_tags(self, mock_req):# Arrangetags = ['GPT-4']