Skip to content

Commit 0c2865b

Browse files
committed
introduce AutoGen instrumentation for multi-agent collaboration
1 parent 83d333e commit 0c2865b

File tree

22 files changed

+3429
-834
lines changed

22 files changed

+3429
-834
lines changed

agentops/instrumentation/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ class InstrumentorConfig(TypedDict):
8282
"class_name": "CrewaiInstrumentor",
8383
"min_version": "0.56.0",
8484
},
85+
"autogen_agentchat": {
86+
"module_name": "agentops.instrumentation.agentic.autogen",
87+
"class_name": "AutoGenInstrumentor",
88+
"min_version": "0.0.1", # Original AutoGen versions are older
89+
},
8590
"autogen": {
8691
"module_name": "agentops.instrumentation.agentic.ag2",
8792
"class_name": "AG2Instrumentor",
@@ -282,6 +287,15 @@ def _perform_instrumentation(package_name: str):
282287
if not _should_instrument_package(package_name):
283288
return
284289

290+
# If we are about to instrument the FIRST agentic library, set the flag **before** importing
291+
# its instrumentor. This prevents re-entrancy where the agentic library imports a provider
292+
# (e.g. ``openai``) while its own instrumentor module is still only *partially* initialised,
293+
# which leads to the ``partially initialised module ... has no attribute`` circular-import
294+
# error that users are seeing. We only set this once – subsequent calls will short-circuit
295+
# in ``_should_instrument_package``.
296+
if package_name in AGENTIC_LIBRARIES and not _has_agentic_library:
297+
_has_agentic_library = True
298+
285299
# Get the appropriate configuration for the package
286300
# Ensure package_name is a key in either PROVIDERS or AGENTIC_LIBRARIES
287301
if package_name not in PROVIDERS and package_name not in AGENTIC_LIBRARIES:
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
"""AutoGen Instrumentation Module
2+
3+
This module provides instrumentation for the original AutoGen framework (autogen_agentchat).
4+
It creates create_agent spans that match the expected trace structure for AutoGen agents.
5+
6+
"""
7+
8+
from agentops.instrumentation.common import LibraryInfo
9+
10+
# Library information
11+
_library_info = LibraryInfo(name="autogen_agentchat")
12+
LIBRARY_NAME = _library_info.name
13+
LIBRARY_VERSION = _library_info.version
14+
15+
# Import after defining constants to avoid circular imports
16+
from .instrumentor import AutoGenInstrumentor
17+
18+
# Import modular components for advanced users
19+
from .agents import (
20+
BaseChatAgentInstrumentor,
21+
AssistantAgentInstrumentor,
22+
UserProxyAgentInstrumentor,
23+
CodeExecutorAgentInstrumentor,
24+
SocietyOfMindAgentInstrumentor,
25+
)
26+
from .teams import (
27+
RoundRobinGroupChatInstrumentor,
28+
SelectorGroupChatInstrumentor,
29+
SwarmInstrumentor,
30+
)
31+
from .utils import (
32+
AutoGenSpanManager,
33+
extract_agent_attributes,
34+
safe_str,
35+
safe_extract_content,
36+
create_agent_span,
37+
instrument_async_generator,
38+
instrument_coroutine,
39+
)
40+
41+
__all__ = [
42+
# Main instrumentors
43+
"AutoGenInstrumentor",
44+
45+
# Library info
46+
"LIBRARY_NAME",
47+
"LIBRARY_VERSION",
48+
49+
# Agent instrumentors
50+
"BaseChatAgentInstrumentor",
51+
"AssistantAgentInstrumentor",
52+
"UserProxyAgentInstrumentor",
53+
"CodeExecutorAgentInstrumentor",
54+
"SocietyOfMindAgentInstrumentor",
55+
56+
# Team instrumentors
57+
"RoundRobinGroupChatInstrumentor",
58+
"SelectorGroupChatInstrumentor",
59+
"SwarmInstrumentor",
60+
61+
# Utilities
62+
"AutoGenSpanManager",
63+
"extract_agent_attributes",
64+
"safe_str",
65+
"safe_extract_content",
66+
"create_agent_span",
67+
"instrument_async_generator",
68+
"instrument_coroutine",
69+
]
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"""AutoGen agent instrumentation."""
2+
3+
from .common import (
4+
CommonAgentWrappers,
5+
BaseChatAgentInstrumentor,
6+
AssistantAgentInstrumentor,
7+
UserProxyAgentInstrumentor,
8+
CodeExecutorAgentInstrumentor,
9+
SocietyOfMindAgentInstrumentor,
10+
)
11+
12+
__all__ = [
13+
"CommonAgentWrappers",
14+
"BaseChatAgentInstrumentor",
15+
"AssistantAgentInstrumentor",
16+
"UserProxyAgentInstrumentor",
17+
"CodeExecutorAgentInstrumentor",
18+
"SocietyOfMindAgentInstrumentor",
19+
]

0 commit comments

Comments
 (0)