Skip to content

Commit

Permalink
Merge branch 'main' into eng-405-log-session-link-at-end-of-session-too
Browse files Browse the repository at this point in the history
  • Loading branch information
HowieG authored May 22, 2024
2 parents e70cd96 + 99183ed commit 310bb6f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
32 changes: 19 additions & 13 deletions agentops/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,20 @@ def __init__(self,
self._tags: Optional[List[str]] = tags
self._tags_for_future_session: Optional[List[str]] = None

self._env_data_opt_out = os.getenv('AGENTOPS_ENV_DATA_OPT_OUT') and os.getenv(
'AGENTOPS_ENV_DATA_OPT_OUT').lower() == 'true'
self._env_data_opt_out = os.environ.get(
'AGENTOPS_ENV_DATA_OPT_OUT', 'False').lower() == 'true'

try:
self.config = Configuration(api_key=api_key,
parent_key=parent_key,
endpoint=endpoint,
max_wait_time=max_wait_time,
max_queue_size=max_queue_size)

if inherited_session_id is not None:
# Check if inherited_session_id is valid
UUID(inherited_session_id)

except ConfigurationError:
return

Expand All @@ -106,7 +111,7 @@ def __init__(self,
self.llm_tracker = LlmTracker(self)
self.llm_tracker.override_api()

def _check_for_partner_frameworks(self, instrument_llm_calls, auto_start_session) -> (bool, bool):
def _check_for_partner_frameworks(self, instrument_llm_calls, auto_start_session) -> tuple[bool, bool]:
partner_frameworks = get_partner_frameworks()
for framework in partner_frameworks.keys():
if framework in sys.modules:
Expand Down Expand Up @@ -146,7 +151,7 @@ def add_tags(self, tags: List[str]):
else:
if self._tags_for_future_session:
for tag in tags:
if tag not in self._session.tags:
if tag not in self._tags_for_future_session:
self._tags_for_future_session.append(tag)
else:
self._tags_for_future_session = tags
Expand Down Expand Up @@ -183,10 +188,10 @@ def record(self, event: Union[Event, ErrorEvent]):
if not event.trigger_event.end_timestamp or event.trigger_event.init_timestamp == event.trigger_event.end_timestamp:
event.trigger_event.end_timestamp = get_ISO_time()

event.trigger_event_id = event.trigger_event.id
event.trigger_event_type = event.trigger_event.event_type
self._worker.add_event(event.trigger_event.__dict__)
event.trigger_event = None # removes trigger_event from serialization
event.trigger_event_id = event.trigger_event.id
event.trigger_event_type = event.trigger_event.event_type
self._worker.add_event(event.trigger_event.__dict__)
event.trigger_event = None # removes trigger_event from serialization

self._worker.add_event(event.__dict__)

Expand Down Expand Up @@ -288,8 +293,9 @@ def start_session(self, tags: Optional[List[str]] = None, config: Optional[Confi
session_id = UUID(
inherited_session_id) if inherited_session_id is not None else uuid4()

self._session = Session(inherited_session_id or uuid4(),
tags or self._tags_for_future_session, host_env=get_host_env(self._env_data_opt_out))
self._session = Session(session_id=session_id,
tags=tags or self._tags_for_future_session,
host_env=get_host_env(self._env_data_opt_out))
self._worker = Worker(config or self.config)
start_session_result = self._worker.start_session(self._session)
if not start_session_result:
Expand Down Expand Up @@ -337,9 +343,9 @@ def end_session(self,
self._session = None
self._worker = None

def create_agent(self, name: str, agent_id: Optional[str] = None) -> str:
def create_agent(self, name: str, agent_id: Optional[str] = None):
if agent_id is None:
agent_id = str(uuid.uuid4())
agent_id = str(uuid4())
if self._worker:
self._worker.create_agent(name=name, agent_id=agent_id)
return agent_id
Expand Down Expand Up @@ -385,7 +391,7 @@ def handle_exception(exc_type, exc_value, exc_traceback):
sys.__excepthook__(exc_type, exc_value, exc_traceback)

# if main thread
if isinstance(threading.current_thread(), threading._MainThread):
if threading.current_thread() is threading.main_thread():
atexit.register(lambda: cleanup(end_state="Indeterminate",
end_state_reason="Process exited without calling end_session()"))
signal.signal(signal.SIGINT, signal_handler)
Expand Down
7 changes: 4 additions & 3 deletions agentops/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@ class Event:
}
"""

event_type: str # EventType.ENUM.value
event_type: EventType
params: Optional[dict] = None
returns: Optional[str] = None
returns: Optional[str | List[str]] = None
init_timestamp: str = field(default_factory=get_ISO_time)
end_timestamp: Optional[str] = None
agent_id: Optional[UUID] = field(default_factory=check_call_stack_for_agent_id)
agent_id: Optional[UUID] = field(
default_factory=check_call_stack_for_agent_id)
id: UUID = field(default_factory=uuid4)


Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "agentops"
version = "0.1.11"
version = "0.1.12"
authors = [
{ name="Alex Reibman", email="[email protected]" },
{ name="Shawn Qiu", email="[email protected]" },
Expand Down

0 comments on commit 310bb6f

Please sign in to comment.