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
Refactored end_state
Howard Gil082ebb653f20
diff --git a/agentops/__init__.py b/agentops/__init__.pyindex fd826eef..b233a531 100755--- a/agentops/__init__.py+++ b/agentops/__init__.py@@ -6,9 +6,8 @@ from .client import Clientfrom .config import Configurationfrom .event import ActionEvent, LLMEvent, ToolEvent, ErrorEvent, Eventfrom .event import Event, ActionEvent, LLMEvent, ToolEvent, ErrorEvent-from .enums import Models, LLMMessageFormat+from .enums import Models, LLMMessageFormat, EndStatefrom .decorators import record_function-from pydantic import Fieldfrom os import environ@@ -24,9 +23,7 @@ def init(api_key: Optional[str] = None,Client(api_key, parent_key, tags, endpoint, max_wait_time, max_queue_size, override, auto_start_session)-def end_session(end_state: str = Field("Indeterminate",- description="End state of the session",- pattern="^(Success|Fail|Indeterminate)$"),+def end_session(end_state: str,end_state_reason: Optional[str] = None,video: Optional[str] = None):Client().end_session(end_state, end_state_reason, video)@@ -45,4 +42,4 @@ def add_tags(tags: List[str]):def set_tags(tags: List[str]):- Client().set_tags(tags)\ No newline at end of file+ Client().set_tags(tags)diff --git a/agentops/client.py b/agentops/client.pyindex 2b5005e7..c047915e 100644--- a/agentops/client.py+++ b/agentops/client.py@@ -6,13 +6,13 @@ Classes:"""from .event import ActionEvent, ErrorEvent, Event+from .enums import EndStatefrom .helpers import get_ISO_time, singleton, check_call_stack_for_agent_idfrom .session import Sessionfrom .worker import Workerfrom .host_env import get_host_envfrom uuid import uuid4from typing import Optional, List-from pydantic import Fieldfrom os import environimport tracebackimport logging@@ -222,22 +222,24 @@ class Client(metaclass=MetaClient):logging.info('View info on this session at https://agentops.ai/dashboard?session_id={}'.format(self._session.session_id))- def end_session(self, end_state: str = Field("Indeterminate",- description="End state of the session",- pattern="^(Success|Fail|Indeterminate)$"),+ def end_session(self,+ end_state: str,end_state_reason: Optional[str] = None,video: Optional[str] = None):"""End the current session with the AgentOps service.Args:- end_state (str, optional): The final state of the session.+ end_state (str): The final state of the session.end_state_reason (str, optional): The reason for ending the session.video (str, optional): The video screen recording of the session"""if self._session is None or self._session.has_ended:return logging.warning("AgentOps: Cannot end session - no current session")+ if not any(end_state == state.value for state in EndState):+ return logging.warning("AgentOps: Invalid end_state. Please use one of the EndState enums")+self._session.video = videoself._session.end_session(end_state, end_state_reason)self._worker.end_session(self._session)@@ -288,7 +290,7 @@ class Client(metaclass=MetaClient):# Then call the default excepthook to exit the programsys.__excepthook__(exc_type, exc_value, exc_traceback)- atexit.register(lambda: cleanup(end_state="Success", end_state_reason="Process exited normally"))+ atexit.register(lambda: cleanup(end_state="Indeterminate", end_state_reason="Process exited normally"))signal.signal(signal.SIGINT, signal_handler)signal.signal(signal.SIGTERM, signal_handler)sys.excepthook = handle_exceptiondiff --git a/agentops/enums.py b/agentops/enums.pyindex 66bf3ea9..1d6d6677 100644--- a/agentops/enums.py+++ b/agentops/enums.py@@ -26,3 +26,9 @@ class Models(Enum):class LLMMessageFormat(Enum):STRING = "string"CHATML = "chatml"+++class EndState(Enum):+ SUCCESS = "Success"+ FAIL = "Fail"+ INDETERMINATE = "Indeterminate"diff --git a/pyproject.toml b/pyproject.tomlindex d197ee51..20c5fdcf 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -21,7 +21,6 @@ classifiers = []dependencies = ["requests==2.31.0",- "pydantic>=1.9.0","psutil==5.9.8"][project.optional-dependencies]diff --git a/tox.ini b/tox.iniindex 86213961..7988a93b 100644--- a/tox.ini+++ b/tox.ini@@ -13,7 +13,6 @@ deps =pytest-mockrequests_mockcoverage- pydanticmypy: mypytypes-requestspsutil