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

cannot create new sessions after end

Braelyn Boynton628d4e3408c2
diff --git a/agentops/client.py b/agentops/client.py
index 99494819..fc669262 100644
--- a/agentops/client.py
+++ b/agentops/client.py
@@ -116,6 +116,26 @@ class Client:
end_state_reason=f'Signal {signal_name} detected')
sys.exit(0)
+ def add_tags(self, tags: List[str]):
+ if self._session is None:
+ return print("You must create a session before assigning tags")
+
+ if self._tags is not None:
+ self._tags.extend(tags)
+ else:
+ self._tags = tags
+
+ self._session.tags = self._tags
+ self._worker.update_session(self._session)
+
+ def set_tags(self, tags: List[str]):
+ if self._session is None:
+ return print("You must create a session before assigning tags")
+
+ self._tags = tags
+ self._session.tags = tags
+ self._worker.update_session(self._session)
+
def record(self, event: Event):
"""
Record an event with the AgentOps service.
@@ -124,7 +144,7 @@ class Client:
event (Event): The event to record.
"""
- if not self._session is None:
+ if not self._session is None and not self._session.has_ended:
self._worker.add_event(
{'session_id': self._session.session_id, **event.__dict__})
else:
@@ -157,26 +177,6 @@ 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._tags is not None:
- self._tags.extend(tags)
- else:
- self._tags = tags
-
- self._session.tags = self._tags
- self._worker.update_session(self._session)
-
- def set_tags(self, tags: List[str]):
- if self._session is None:
- return print("You must create a session before assigning tags")
-
- self._tags = tags
- self._session.tags = tags
- self._worker.update_session(self._session)
-
def _record_event_sync(self, func, event_name, tags, *args, **kwargs):
init_time = get_ISO_time()
func_args = inspect.signature(func).parameters
@@ -294,7 +294,7 @@ class Client:
end_state_reason (str, optional): The reason for ending the session.
video (str, optional): The video screen recording of the session
"""
- if self._session is None:
+ if self._session is None or self._session.has_ended:
return print("Session has already been ended.")
self._session.video = video
diff --git a/agentops/session.py b/agentops/session.py
index 0c79b681..c23958ca 100644
--- a/agentops/session.py
+++ b/agentops/session.py
@@ -60,4 +60,4 @@ class Session:
Returns:
bool: Whether the session has been ended
"""
- return hasattr(self, "end_state")
+ return self.end_state is not None