Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

moved agent_id assignment #136

Merged
merged 1 commit into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions agentops/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from .event import Event, ActionEvent, LLMEvent, ToolEvent, ErrorEvent
from .enums import Models
from .decorators import record_function
from .agent import track_agent


def init(api_key: Optional[str] = None,
Expand All @@ -18,13 +19,13 @@ def init(api_key: Optional[str] = None,
override=True,
auto_start_session=True):

Client(api_key=api_key,
parent_key=parent_key,
endpoint=endpoint,
max_wait_time=max_wait_time,
max_queue_size=max_queue_size,
tags=tags,
override=override,
Client(api_key=api_key,
parent_key=parent_key,
endpoint=endpoint,
max_wait_time=max_wait_time,
max_queue_size=max_queue_size,
tags=tags,
override=override,
auto_start_session=auto_start_session)


Expand Down
3 changes: 0 additions & 3 deletions agentops/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,6 @@ def record(self, event: Event | ErrorEvent):
"""

if self._session is not None and not self._session.has_ended:
agent_id = check_call_stack_for_agent_id()
if agent_id:
event.agent_id = agent_id
self._worker.add_event(event.__dict__)
else:
logging.warning(
Expand Down
10 changes: 3 additions & 7 deletions agentops/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from dataclasses import dataclass, field
from typing import List, Optional
from .helpers import get_ISO_time
from .helpers import get_ISO_time, check_call_stack_for_agent_id
from .enums import EventType, Models
from uuid import UUID, uuid4

Expand All @@ -23,6 +23,7 @@ class Event:
returns(str, optional): The return value of the function containing the triggered event, e.g. 2 in example below
init_timestamp(str): A timestamp indicating when the event began. Defaults to the time when this Event was instantiated.
end_timestamp(str): A timestamp indicating when the event ended. Defaults to the time when this Event was instantiated.
agent_id(UUID, optional): The unique identifier of the agent that triggered the event.
id(UUID): A unique identifier for the event. Defaults to a new UUID.

foo(x=1) {
Expand All @@ -40,6 +41,7 @@ class Event:
returns: Optional[str] = None
init_timestamp: Optional[str] = field(default_factory=get_ISO_time)
end_timestamp: str = field(default_factory=get_ISO_time)
agent_id: Optional[UUID] = field(default_factory=check_call_stack_for_agent_id)
id: UUID = field(default_factory=uuid4)
# TODO: has_been_recorded: bool = False

Expand All @@ -49,15 +51,13 @@ class ActionEvent(Event):
"""
For generic events

agent_id(UUID, optional): The unique identifier of the agent that triggered the event.
action_type(str, optional): High level name describing the action
logs(str, optional): For detailed information/logging related to the action
screenshot(str, optional): url to snapshot if agent interacts with UI
"""

event_type: str = EventType.ACTION.value
# TODO: Should not be optional, but non-default argument 'agent_id' follows default argument error
agent_id: Optional[UUID] = None
action_type: Optional[str] = None
logs: Optional[str] = None
screenshot: Optional[str] = None
Expand All @@ -74,7 +74,6 @@ class LLMEvent(Event):
"""
For recording calls to LLMs. AgentOps auto-instruments calls to the most popular LLMs e.g. GPT, Claude, Gemini, etc.

agent_id(UUID, optional): The unique identifier of the agent that triggered the event.
thread_id(UUID, optional): The unique identifier of the contextual thread that a message pertains to.
prompt(str, list, optional): The message or messages that were used to prompt the LLM. Preferably in ChatML format which is more fully supported by AgentOps.
prompt_tokens(int, optional): The number of tokens in the prompt message.
Expand All @@ -85,7 +84,6 @@ class LLMEvent(Event):
"""

event_type: str = EventType.LLM.value
agent_id: Optional[UUID] = None
thread_id: Optional[UUID] = None
prompt: str | List = None
prompt_tokens: Optional[int] = None
Expand All @@ -99,13 +97,11 @@ class ToolEvent(Event):
"""
For recording calls to tools e.g. searchWeb, fetchFromDB

agent_id(UUID, optional): The unique identifier of the agent that triggered the event.
name(str, optional): A name describing the tool or the actual function name if applicable e.g. searchWeb, fetchFromDB.
logs(str, dict, optional): For detailed information/logging related to the tool.

"""
event_type: str = EventType.TOOL.value
agent_id: Optional[UUID] = None
name: Optional[str] = None
logs: Optional[str | dict] = None

Expand Down
Loading