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
moves session_id out of event and to batched request
Braelyn Boynton5ec901fe5937
diff --git a/agentops/client.py b/agentops/client.pyindex 6f2d2d85..6fc14228 100644--- a/agentops/client.py+++ b/agentops/client.py@@ -101,11 +101,10 @@ class Client:event (Event): The event to record."""- if not self._session is None and not self._session.has_ended:- self._worker.add_event(- {'session_id': self._session.session_id, **event.__dict__})+ if self._session is not None and not self._session.has_ended:+ self._worker.add_event(event.__dict__)else:- logging.warn("AgentOps: Cannot record event - no current session")+ logging.warning("AgentOps: Cannot record event - no current session")def record_function(self, event_name: str, tags: Optional[List[str]] = None):"""@@ -124,11 +123,13 @@ class Client:@functools.wraps(func)async def async_wrapper(*args, **kwargs):return await self._record_event_async(func, event_name, tags, *args, **kwargs)+return async_wrapperelse:@functools.wraps(func)def sync_wrapper(*args, **kwargs):return self._record_event_sync(func, event_name, tags, *args, **kwargs)+return sync_wrapperreturn decoratordiff --git a/agentops/worker.py b/agentops/worker.pyindex 63e40938..f6928340 100644--- a/agentops/worker.py+++ b/agentops/worker.py@@ -5,6 +5,7 @@ from .http import HttpClientfrom .config import Configurationfrom .session import Sessionfrom typing import Dict+import loggingdef is_jsonable(x):@@ -47,6 +48,7 @@ class Worker:self.thread = threading.Thread(target=self.run)self.thread.daemon = Trueself.thread.start()+ self._session: Session | None = Nonedef add_event(self, event: dict) -> None:with self.lock:@@ -61,6 +63,7 @@ class Worker:self.queue = []payload = {+ "session_id": self._session.session_id,"events": events}@@ -71,6 +74,7 @@ class Worker:self.config.api_key)def start_session(self, session: Session) -> None:+ self._session = sessionwith self.lock:payload = {"session": session.__dict__@@ -85,6 +89,7 @@ class Worker:self.stop_flag.set()self.thread.join()self.flush_queue()+ self._session = Nonewith self.lock:payload = {