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

Merge branch 'main' into eng-101-langchain-handler

Shawn Qiu35f247484b8c
diff --cc agentops/helpers.py
index 574545e7,70b2ac82..282bd2fa
--- a/agentops/helpers.py
+++ b/agentops/helpers.py
@@@ -6,7 -4,7 +6,8 @@@ import jso
import inspect
import logging
from uuid import UUID
+import os
+ from importlib.metadata import version
def singleton(class_):
@@@ -88,41 -86,10 +89,51 @@@ def check_call_stack_for_agent_id() ->
return getattr(var, '_agent_ops_agent_id')
return None
++
+# Function decorator that prints function name and its arguments to the console for debug purposes
+# Example output:
+ # <AGENTOPS_DEBUG_OUTPUT>
+ # on_llm_start called with arguments:
+ # run_id: UUID('5fda42fe-809b-4179-bad2-321d1a6090c7')
+ # parent_run_id: UUID('63f1c4da-3e9f-4033-94d0-b3ebed06668f')
+ # tags: []
+ # metadata: {}
+ # invocation_params: {'_type': 'openai-chat',
+ # 'model': 'gpt-3.5-turbo',
+ # 'model_name': 'gpt-3.5-turbo',
+ # 'n': 1,
+ # 'stop': ['Observation:'],
+ # 'stream': False,
+ # 'temperature': 0.7}
+ # options: {'stop': ['Observation:']}
+ # name: None
+ # batch_size: 1
+ # </AGENTOPS_DEBUG_OUTPUT>
+
+# regex to filter for just this:
+# <AGENTOPS_DEBUG_OUTPUT>([\s\S]*?)<\/AGENTOPS_DEBUG_OUTPUT>\n
+
-
+def debug_print_function_params(func):
+ @wraps(func)
+ def wrapper(self, *args, **kwargs):
+ if os.getenv('DEBUG_MODE') == 'Y':
+ print("\n<AGENTOPS_DEBUG_OUTPUT>")
+ print(f"{func.__name__} called with arguments:")
+
+ for key, value in kwargs.items():
+ print(f"{key}: {pformat(value)}")
+
+ print("</AGENTOPS_DEBUG_OUTPUT>\n")
+
+ return func(self, *args, **kwargs)
+ return wrapper
++
++
+ def get_agentops_version():
+ try:
+ pkg_version = version("agentops")
+ return pkg_version
+ except Exception as e:
+ print(f"Error reading package version: {e}")
+ return None
++