Skip to content

Commit

Permalink
cannot create new sessions after end
Browse files Browse the repository at this point in the history
  • Loading branch information
bboynton97 authored and siyangqiu committed Feb 22, 2024
1 parent a20fda9 commit f864131
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
44 changes: 22 additions & 22 deletions agentops/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,26 @@ def signal_handler(self, signum, frame):
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.
Expand All @@ -129,7 +149,7 @@ def record(self, event: Event):
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:
Expand Down Expand Up @@ -162,26 +182,6 @@ def sync_wrapper(*args, **kwargs):

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
Expand Down Expand Up @@ -299,7 +299,7 @@ def end_session(self, end_state: str = Field("Indeterminate",
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
Expand Down
2 changes: 1 addition & 1 deletion agentops/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@ def has_ended(self) -> bool:
Returns:
bool: Whether the session has been ended
"""
return hasattr(self, "end_state")
return self.end_state is not None

0 comments on commit f864131

Please sign in to comment.