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
Python agentagentopsagents-sdkaianthropicautogencost-estimationcrewaievalsevaluation-metricsgroqlangchainllmmistralollamaopenaiopenai-agents
Move `agentops.enums` to their respective module (#647)
teocns6d0459a18609
diff --git a/agentops/enums.py b/agentops/enums.pydeleted file mode 100644index 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" # Defaultdiff --git a/agentops/event.py b/agentops/event.pyindex 1ed356bf..abffcacc 100644--- a/agentops/event.py+++ b/agentops/event.py@@ -7,19 +7,27 @@ Data Class:import tracebackfrom dataclasses import dataclass, field+from enum import Enumfrom typing import Any, Dict, List, Optional, Sequence, Unionfrom uuid import UUID, uuid4-from .enums import EventTypefrom .helpers import check_call_stack_for_agent_id, get_ISO_time+class EventType(Enum):+ LLM = "llms"+ ACTION = "actions"+ API = "apis"+ TOOL = "tools"+ ERROR = "errors"++@dataclassclass 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 belowreturns(str, optional): The return value of the function containing the triggered event, e.g. 2 in example belowinit_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.pyindex e35b04c8..9fc85fb2 100644--- a/agentops/partners/autogen_logger.py+++ b/agentops/partners/autogen_logger.py@@ -11,7 +11,7 @@ from openai.types.chat import ChatCompletionfrom autogen.logger.base_logger import BaseLogger, LLMConfig-from agentops.enums import EndState+from agentops.session import EndStatefrom agentops.helpers import get_ISO_timefrom agentops import LLMEvent, ToolEvent, ActionEventdiff --git a/agentops/session.py b/agentops/session.pyindex b9f07d20..95d1fba1 100644--- a/agentops/session.py+++ b/agentops/session.py@@ -6,6 +6,7 @@ import jsonimport threadingfrom datetime import datetime, timezonefrom decimal import ROUND_HALF_UP, Decimal+from enum import Enumfrom typing import Any, Dict, List, Optional, Sequence, Unionfrom uuid import UUID, uuid4@@ -13,16 +14,10 @@ from opentelemetry import tracefrom opentelemetry.context import attach, detach, set_valuefrom opentelemetry.sdk.resources import SERVICE_NAME, Resourcefrom 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, SpanExportResultfrom termcolor import coloredfrom .config import Configuration-from .enums import EndStatefrom .event import ErrorEvent, Eventfrom .exceptions import ApiServerExceptionfrom .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 Noneif 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 Nonetry: