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

set and add tags then update the session

Braelyn Boyntoncbaa0fcd6bf6
diff --git a/agentops/client.py b/agentops/client.py
index cb310152..cdc480d6 100644
--- a/agentops/client.py
+++ b/agentops/client.py
@@ -72,7 +72,10 @@ class Client:
sys.excepthook = self.handle_exception
if not bypass_new_session:
- self._start_session(tags)
+ self.start_session(tags)
+ else:
+ self.session = None
+ self.worker = None
if override:
if 'openai' in sys.modules:
@@ -154,6 +157,9 @@ class Client:
return decorator
def add_tags(self, tags: List[str]):
+ if self.session is None:
+ return print("You must create a session before assigning tags")
+
if self.session.tags is not None:
self.session.tags.extend(tags)
else:
@@ -163,7 +169,7 @@ class Client:
def set_tags(self, tags: List[str]):
if self.session is None:
- raise Exception("You must create a session before assigning tags")
+ return print("You must create a session before assigning tags")
self.session.tags = tags
self.worker.update_session(self.session)
@@ -255,7 +261,7 @@ class Client:
return returns
- def _start_session(self, tags: Optional[List[str]] = None):
+ def start_session(self, tags: Optional[List[str]] = None):
"""
Start a new session for recording events.