Skip to content

introduce AutoGen instrumentation. #1157

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
14 changes: 14 additions & 0 deletions agentops/instrumentation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ class InstrumentorConfig(TypedDict):
"class_name": "CrewaiInstrumentor",
"min_version": "0.56.0",
},
"autogen_agentchat": {
"module_name": "agentops.instrumentation.agentic.autogen",
"class_name": "AutoGenInstrumentor",
"min_version": "0.0.1", # Original AutoGen versions are older
},
"autogen": {
"module_name": "agentops.instrumentation.agentic.ag2",
"class_name": "AG2Instrumentor",
Expand Down Expand Up @@ -282,6 +287,15 @@ def _perform_instrumentation(package_name: str):
if not _should_instrument_package(package_name):
return

# If we are about to instrument the FIRST agentic library, set the flag **before** importing
# its instrumentor. This prevents re-entrancy where the agentic library imports a provider
# (e.g. ``openai``) while its own instrumentor module is still only *partially* initialised,
# which leads to the ``partially initialised module ... has no attribute`` circular-import
# error that users are seeing. We only set this once – subsequent calls will short-circuit
# in ``_should_instrument_package``.
if package_name in AGENTIC_LIBRARIES and not _has_agentic_library:
_has_agentic_library = True

# Get the appropriate configuration for the package
# Ensure package_name is a key in either PROVIDERS or AGENTIC_LIBRARIES
if package_name not in PROVIDERS and package_name not in AGENTIC_LIBRARIES:
Expand Down
69 changes: 69 additions & 0 deletions agentops/instrumentation/agentic/autogen/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
"""AutoGen Instrumentation Module

This module provides instrumentation for the original AutoGen framework (autogen_agentchat).
It creates create_agent spans that match the expected trace structure for AutoGen agents.

"""

from agentops.instrumentation.common import LibraryInfo

# Library information
_library_info = LibraryInfo(name="autogen_agentchat")
LIBRARY_NAME = _library_info.name
LIBRARY_VERSION = _library_info.version

# Import after defining constants to avoid circular imports
from .instrumentor import AutoGenInstrumentor

# Import modular components for advanced users
from .agents import (
BaseChatAgentInstrumentor,
AssistantAgentInstrumentor,
UserProxyAgentInstrumentor,
CodeExecutorAgentInstrumentor,
SocietyOfMindAgentInstrumentor,
)
from .teams import (
RoundRobinGroupChatInstrumentor,
SelectorGroupChatInstrumentor,
SwarmInstrumentor,
)
from .utils import (
AutoGenSpanManager,
extract_agent_attributes,
safe_str,
safe_extract_content,
create_agent_span,
instrument_async_generator,
instrument_coroutine,
)

__all__ = [
# Main instrumentors
"AutoGenInstrumentor",

# Library info
"LIBRARY_NAME",
"LIBRARY_VERSION",

# Agent instrumentors
"BaseChatAgentInstrumentor",
"AssistantAgentInstrumentor",
"UserProxyAgentInstrumentor",
"CodeExecutorAgentInstrumentor",
"SocietyOfMindAgentInstrumentor",

# Team instrumentors
"RoundRobinGroupChatInstrumentor",
"SelectorGroupChatInstrumentor",
"SwarmInstrumentor",

# Utilities
"AutoGenSpanManager",
"extract_agent_attributes",
"safe_str",
"safe_extract_content",
"create_agent_span",
"instrument_async_generator",
"instrument_coroutine",
]
19 changes: 19 additions & 0 deletions agentops/instrumentation/agentic/autogen/agents/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""AutoGen agent instrumentation."""

from .common import (
CommonAgentWrappers,
BaseChatAgentInstrumentor,
AssistantAgentInstrumentor,
UserProxyAgentInstrumentor,
CodeExecutorAgentInstrumentor,
SocietyOfMindAgentInstrumentor,
)

__all__ = [
"CommonAgentWrappers",
"BaseChatAgentInstrumentor",
"AssistantAgentInstrumentor",
"UserProxyAgentInstrumentor",
"CodeExecutorAgentInstrumentor",
"SocietyOfMindAgentInstrumentor",
]
Loading
Loading