From 9126c2fdd13019c858e8fe2f80655e95d8929f63 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Sun, 15 Jun 2025 06:12:42 +0000 Subject: [PATCH 1/3] Fix missing @record_function decorator and AutoGen instrumentation issues - Add @record_function decorator to legacy module with deprecation warning - Update AutoGen instrumentation minimum version from 0.1.0 to 0.3.2 - Add support for both 'autogen' and 'ag2' packages in instrumentation - Fix import issues in AG2 example with fallback import pattern - Export record_function in main __init__.py for backward compatibility Fixes missing manual instrumentation functionality that was available in previous versions and improves AutoGen instrumentation reliability. Co-Authored-By: Alex --- agentops/__init__.py | 2 ++ agentops/instrumentation/__init__.py | 3 ++- agentops/legacy/__init__.py | 12 ++++++++++++ examples/ag2/agentchat_with_memory.py | 8 +++++++- 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/agentops/__init__.py b/agentops/__init__.py index c0e0f3c95..979e121b8 100755 --- a/agentops/__init__.py +++ b/agentops/__init__.py @@ -4,6 +4,7 @@ end_session, track_agent, track_tool, + record_function, end_all_sessions, Session, ToolEvent, @@ -260,6 +261,7 @@ def end_trace( "configure", "get_client", "record", + "record_function", "start_trace", "end_trace", "start_session", diff --git a/agentops/instrumentation/__init__.py b/agentops/instrumentation/__init__.py index 84ace1d6d..d6cfb0049 100644 --- a/agentops/instrumentation/__init__.py +++ b/agentops/instrumentation/__init__.py @@ -92,7 +92,8 @@ class InstrumentorConfig(TypedDict): "class_name": "CrewAIInstrumentor", "min_version": "0.56.0", }, - "autogen": {"module_name": "agentops.instrumentation.ag2", "class_name": "AG2Instrumentor", "min_version": "0.1.0"}, + "autogen": {"module_name": "agentops.instrumentation.ag2", "class_name": "AG2Instrumentor", "min_version": "0.3.2"}, + "ag2": {"module_name": "agentops.instrumentation.ag2", "class_name": "AG2Instrumentor", "min_version": "0.1.0"}, "agents": { "module_name": "agentops.instrumentation.openai_agents", "class_name": "OpenAIAgentsInstrumentor", diff --git a/agentops/legacy/__init__.py b/agentops/legacy/__init__.py index 5f77800d2..2044dc851 100644 --- a/agentops/legacy/__init__.py +++ b/agentops/legacy/__init__.py @@ -263,6 +263,17 @@ def noop(f: Any) -> Any: return noop +@deprecated("Use @tool decorator instead.") +def record_function(*args: Any, **kwargs: Any) -> Any: + """@deprecated Use @tool decorator instead. Wraps the @tool decorator for backward compatibility.""" + from agentops.sdk.decorators import tool + + if not args or not callable(args[0]): + return tool(*args, **kwargs) + else: + return tool(args[0], **kwargs) + + __all__ = [ "start_session", "end_session", @@ -271,6 +282,7 @@ def noop(f: Any) -> Any: "ActionEvent", "track_agent", "track_tool", + "record_function", "end_all_sessions", "Session", "LLMEvent", diff --git a/examples/ag2/agentchat_with_memory.py b/examples/ag2/agentchat_with_memory.py index 7d3099509..1044cddfa 100644 --- a/examples/ag2/agentchat_with_memory.py +++ b/examples/ag2/agentchat_with_memory.py @@ -21,7 +21,13 @@ from dotenv import load_dotenv import agentops from mem0 import MemoryClient -from autogen import ConversableAgent +try: + from autogen import ConversableAgent +except ImportError: + try: + from ag2 import ConversableAgent + except ImportError: + raise ImportError("Neither 'autogen' nor 'ag2' package found. Please install one of them.") load_dotenv() os.environ["AGENTOPS_API_KEY"] = os.getenv("AGENTOPS_API_KEY", "your_api_key_here") From f5d493514bf416829693fda34bd9a290ff661f81 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Mon, 16 Jun 2025 16:04:38 +0000 Subject: [PATCH 2/3] Fix pre-commit formatting issues - Remove trailing whitespace in agentops/legacy/__init__.py - Add blank line after imports in examples/ag2/agentchat_with_memory.py Resolves ruff-format pre-commit check failures. Co-Authored-By: Alex --- agentops/legacy/__init__.py | 2 +- examples/ag2/agentchat_with_memory.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/agentops/legacy/__init__.py b/agentops/legacy/__init__.py index 2044dc851..a8e8e9fe2 100644 --- a/agentops/legacy/__init__.py +++ b/agentops/legacy/__init__.py @@ -267,7 +267,7 @@ def noop(f: Any) -> Any: def record_function(*args: Any, **kwargs: Any) -> Any: """@deprecated Use @tool decorator instead. Wraps the @tool decorator for backward compatibility.""" from agentops.sdk.decorators import tool - + if not args or not callable(args[0]): return tool(*args, **kwargs) else: diff --git a/examples/ag2/agentchat_with_memory.py b/examples/ag2/agentchat_with_memory.py index 1044cddfa..39140e780 100644 --- a/examples/ag2/agentchat_with_memory.py +++ b/examples/ag2/agentchat_with_memory.py @@ -21,6 +21,7 @@ from dotenv import load_dotenv import agentops from mem0 import MemoryClient + try: from autogen import ConversableAgent except ImportError: From 52ce3d4392282a3cfcfd59dce763d0936a9bc645 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Mon, 16 Jun 2025 22:52:45 +0000 Subject: [PATCH 3/3] Remove autogen entry from instrumentation dictionary Address GitHub comment from the-praxs: AutoGen does not have an instrumentation in our codebase and uses its telemetry instead. Keep only the ag2 entry which is the correct package for AgentOps instrumentation. Co-Authored-By: Alex --- agentops/instrumentation/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/agentops/instrumentation/__init__.py b/agentops/instrumentation/__init__.py index d6cfb0049..c751aa702 100644 --- a/agentops/instrumentation/__init__.py +++ b/agentops/instrumentation/__init__.py @@ -92,7 +92,6 @@ class InstrumentorConfig(TypedDict): "class_name": "CrewAIInstrumentor", "min_version": "0.56.0", }, - "autogen": {"module_name": "agentops.instrumentation.ag2", "class_name": "AG2Instrumentor", "min_version": "0.3.2"}, "ag2": {"module_name": "agentops.instrumentation.ag2", "class_name": "AG2Instrumentor", "min_version": "0.1.0"}, "agents": { "module_name": "agentops.instrumentation.openai_agents",