Skip to content

Python SDK for AI agent monitoring, LLM cost tracking, benchmarking, and more. Integrates with most LLMs and agent frameworks including CrewAI, Agno, OpenAI Agents SDK, Langchain, Autogen, AG2, and CamelAI

Move `agentops.enums` to their respective module (#647)

teocns6d0459a18609
diff --git a/agentops/enums.py b/agentops/enums.py
deleted file mode 100644
index cce03392..00000000
--- a/agentops/enums.py
+++ /dev/null
@@ -1,26 +0,0 @@
-from enum import Enum
-
-
-class EventType(Enum):
- LLM = "llms"
- ACTION = "actions"
- API = "apis"
- TOOL = "tools"
- ERROR = "errors"
-
-
-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
diff --git a/agentops/event.py b/agentops/event.py
index 1ed356bf..abffcacc 100644
--- a/agentops/event.py
+++ b/agentops/event.py
@@ -7,19 +7,27 @@ Data Class:
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.
diff --git a/agentops/partners/autogen_logger.py b/agentops/partners/autogen_logger.py
index e35b04c8..9fc85fb2 100644
--- a/agentops/partners/autogen_logger.py
+++ b/agentops/partners/autogen_logger.py
@@ -11,7 +11,7 @@ from openai.types.chat import ChatCompletion
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
diff --git a/agentops/session.py b/agentops/session.py
index b9f07d20..95d1fba1 100644
--- a/agentops/session.py
+++ b/agentops/session.py
@@ -6,6 +6,7 @@ import json
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
@@ -13,16 +14,10 @@ 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
@@ -63,6 +58,23 @@ OTEL Guidelines:
"""
+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
@@ -290,7 +302,7 @@ class 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: