Skip to content

Commit

Permalink
Record trigger_event when recording ErrorEvent (#178)
Browse files Browse the repository at this point in the history
* WIP. Now recording trigger_events along with ErrorEvents. Previously wasn't, which was an oversight. However this is a hacky fix we may want to revisit

* Reordering response logic so crash-possible parameters are parsed later

* Done
  • Loading branch information
HowieG authored May 2, 2024
1 parent c869271 commit 139488a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
15 changes: 8 additions & 7 deletions agentops/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ def record(self, event: Event | ErrorEvent):
"""

if self._session is not None and not self._session.has_ended:
if isinstance(event, ErrorEvent):
if event.trigger_event:
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__)
else:
logger.warning(
Expand Down Expand Up @@ -168,9 +174,6 @@ def _record_event_sync(self, func, event_name, *args, **kwargs):

event.returns = returns
event.end_timestamp = get_ISO_time()
# TODO: If func excepts this will never get called
# the dev loses all the useful stuff in ActionEvent they would need for debugging
# we should either record earlier or have Error post the supplied event to supabase
self.record(event)

except Exception as e:
Expand Down Expand Up @@ -207,9 +210,6 @@ async def _record_event_async(self, func, event_name, *args, **kwargs):

event.returns = returns
event.end_timestamp = get_ISO_time()
# TODO: If func excepts this will never get called
# the dev loses all the useful stuff in ActionEvent they would need for debugging
# we should either record earlier or have Error post the supplied event to supabase
self.record(event)

except Exception as e:
Expand Down Expand Up @@ -275,7 +275,8 @@ def end_session(self,
print('🖇 AgentOps: Could not determine cost of run.')
else:

print('🖇 AgentOps: This run cost ${}'.format('{:.2f}'.format(token_cost) if token_cost == 0 else '{:.6f}'.format(token_cost)))
print('🖇 AgentOps: This run cost ${}'.format('{:.2f}'.format(
token_cost) if token_cost == 0 else '{:.6f}'.format(token_cost)))
self._session = None
self._worker = None

Expand Down
4 changes: 0 additions & 4 deletions agentops/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,6 @@ class ErrorEvent():

def __post_init__(self):
self.event_type = EventType.ERROR.value
if self.trigger_event:
self.trigger_event_id = self.trigger_event.id
self.trigger_event_type = self.trigger_event.event_type
self.trigger_event = None # removes trigger_event from serialization
if self.exception:
self.error_type = self.error_type or type(self.exception).__name__
self.details = self.details or str(self.exception)
Expand Down

0 comments on commit 139488a

Please sign in to comment.