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

fix: `AG2` minor refactor for `LIBRARY_NAME` & `LIBRARY_VERSION` (#1010)

Pratyush Shukla0267c6f3b776
diff --git a/agentops/instrumentation/ag2/__init__.py b/agentops/instrumentation/ag2/__init__.py
index ae1fbffb..87655005 100644
--- a/agentops/instrumentation/ag2/__init__.py
+++ b/agentops/instrumentation/ag2/__init__.py
@@ -5,7 +5,24 @@ interactions, conversation flows, and tool usage while focusing on summary-level
than individual message exchanges.
"""
-from agentops.instrumentation.ag2.instrumentor import AG2Instrumentor
-from agentops.instrumentation.ag2.version import LIBRARY_NAME, LIBRARY_VERSION
+from agentops.logging import logger
+
+
+def get_version() -> str:
+ """Get the version of the AG2 package, or 'unknown' if not found"""
+ try:
+ from importlib.metadata import version
+
+ return version("ag2")
+ except ImportError:
+ logger.debug("Could not find AG2 version")
+ return "unknown"
+
+
+LIBRARY_NAME = "ag2"
+LIBRARY_VERSION: str = get_version()
+
+# Import after defining constants to avoid circular imports
+from agentops.instrumentation.ag2.instrumentor import AG2Instrumentor # noqa: E402
__all__ = ["AG2Instrumentor", "LIBRARY_NAME", "LIBRARY_VERSION"]
diff --git a/agentops/instrumentation/ag2/instrumentor.py b/agentops/instrumentation/ag2/instrumentor.py
index 302c0c7c..9818d3a3 100644
--- a/agentops/instrumentation/ag2/instrumentor.py
+++ b/agentops/instrumentation/ag2/instrumentor.py
@@ -13,7 +13,7 @@ from opentelemetry.metrics import get_meter
from wrapt import wrap_function_wrapper
from agentops.logging import logger
-from agentops.instrumentation.ag2.version import LIBRARY_NAME, LIBRARY_VERSION
+from agentops.instrumentation.ag2 import LIBRARY_NAME, LIBRARY_VERSION
from agentops.semconv import Meters
from agentops.semconv.message import MessageAttributes
from agentops.semconv.span_attributes import SpanAttributes
diff --git a/agentops/instrumentation/ag2/version.py b/agentops/instrumentation/ag2/version.py
deleted file mode 100644
index 3aab496e..00000000
--- a/agentops/instrumentation/ag2/version.py
+++ /dev/null
@@ -1,4 +0,0 @@
-"""Version information for AG2 instrumentation."""
-
-LIBRARY_NAME = "ag2"
-LIBRARY_VERSION = "0.3.2"