Skip to content

Commit

Permalink
Move agentops.enums to their respective module (#647)
Browse files Browse the repository at this point in the history
Removing a redundant module `agentops.enums` and instead moving them in the modules they belong:


- Moved `EventType` enum from `enums.py` to `event.py`
- Moved `EndState` enum from `enums.py` to `session.py`
- Removed `enums.py` module
- Updated imports across affected files
- Updated dependency graph in `tach.yml`

Signed-off-by: Teo <[email protected]>
  • Loading branch information
teocns authored Jan 16, 2025
1 parent 06d64d9 commit 6d0459a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 37 deletions.
26 changes: 0 additions & 26 deletions agentops/enums.py

This file was deleted.

12 changes: 10 additions & 2 deletions agentops/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,27 @@

import traceback
from dataclasses import dataclass, field
from enum import Enum
from typing import Any, Dict, List, Optional, Sequence, Union
from uuid import UUID, uuid4

from .enums import EventType
from .helpers import check_call_stack_for_agent_id, get_ISO_time


class EventType(Enum):
LLM = "llms"
ACTION = "actions"
API = "apis"
TOOL = "tools"
ERROR = "errors"


@dataclass
class Event:
"""
Abstract base class for events that will be recorded. Should not be instantiated directly.
event_type(str): The type of event. Defined in enums.EventType. Some values are 'llm', 'action', 'api', 'tool', 'error'.
event_type(str): The type of event. Defined in events.EventType. Some values are 'llm', 'action', 'api', 'tool', 'error'.
params(dict, optional): The parameters of the function containing the triggered event, e.g. {'x': 1} in example below
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.
Expand Down
2 changes: 1 addition & 1 deletion agentops/partners/autogen_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from autogen.logger.base_logger import BaseLogger, LLMConfig

from agentops.enums import EndState
from agentops.session import EndState
from agentops.helpers import get_ISO_time

from agentops import LLMEvent, ToolEvent, ActionEvent
Expand Down
28 changes: 20 additions & 8 deletions agentops/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,18 @@
import threading
from datetime import datetime, timezone
from decimal import ROUND_HALF_UP, Decimal
from enum import Enum
from typing import Any, Dict, List, Optional, Sequence, Union
from uuid import UUID, uuid4

from opentelemetry import trace
from opentelemetry.context import attach, detach, set_value
from opentelemetry.sdk.resources import SERVICE_NAME, Resource
from opentelemetry.sdk.trace import ReadableSpan, TracerProvider
from opentelemetry.sdk.trace.export import (
BatchSpanProcessor,
ConsoleSpanExporter,
SpanExporter,
SpanExportResult,
)
from opentelemetry.sdk.trace.export import BatchSpanProcessor, ConsoleSpanExporter, SpanExporter, SpanExportResult
from termcolor import colored

from .config import Configuration
from .enums import EndState
from .event import ErrorEvent, Event
from .exceptions import ApiServerException
from .helpers import filter_unjsonable, get_ISO_time, safe_serialize
Expand Down Expand Up @@ -63,6 +58,23 @@
"""


class EndState(Enum):
"""
Enum representing the possible end states of a session.
Attributes:
SUCCESS: Indicates the session ended successfully.
FAIL: Indicates the session failed.
INDETERMINATE (default): Indicates the session ended with an indeterminate state.
This is the default state if not specified, e.g. if you forget to call end_session()
at the end of your program or don't pass it the end_state parameter
"""

SUCCESS = "Success"
FAIL = "Fail"
INDETERMINATE = "Indeterminate" # Default


class SessionExporter(SpanExporter):
"""
Manages publishing events for Session
Expand Down Expand Up @@ -290,7 +302,7 @@ def end_session(
return None

if not any(end_state == state.value for state in EndState):
logger.warning("Invalid end_state. Please use one of the EndState enums")
logger.warning("Invalid end_state. Please use one of the EndState")
return None

try:
Expand Down

0 comments on commit 6d0459a

Please sign in to comment.