Skip to main content

AutoGen v0.4+ Integration

AutoGenEventHandler subclasses logging.Handler and attaches to AutoGen's EVENT_LOGGER_NAME and TRACE_LOGGER_NAME loggers to capture agent messages, tool calls, and control events without modifying agent code.

Installation

pip install briefcase-ai
pip install autogen-agentchat>=0.4.0
# or
pip install briefcase-ai[autogen]

Quick Setup with auto()

The simplest way to instrument AutoGen is one line:

import briefcase_ai

briefcase_ai.auto("autogen")
# That's it — all AutoGen agent events are now traced.

Setup with install()

Use install() to attach the handler globally. It is idempotent — calling it multiple times returns the same handler instance.

from briefcase_ai.integrations.frameworks import autogen_hook

handler = autogen_hook.install()

Or import directly:

from briefcase_ai.integrations.frameworks.autogen_handler import install

handler = install(context_version="v2.1", async_capture=True)

Constructor

AutoGenEventHandler(
context_version: Optional[str] = None,
async_capture: bool = True,
capture_events: bool = True,
capture_traces: bool = True,
max_input_chars: int = 10000,
max_output_chars: int = 10000,
exporter: Optional[BaseExporter] = None,
)
ParameterDefaultDescription
context_versionNoneVersion tag added to all decision records
async_captureTrueExport in a background daemon thread
capture_eventsTrueCapture records from EVENT_LOGGER_NAME
capture_tracesTrueCapture records from TRACE_LOGGER_NAME
max_input_chars10000Maximum length of captured input strings
max_output_chars10000Maximum length of captured output strings
exporterNonePer-instance BaseExporter override

attach()

Attach this handler to both AutoGen loggers and set their level to DEBUG.

detach()

Remove this handler from all attached loggers.

Basic Usage

import asyncio
from autogen_agentchat.agents import AssistantAgent, UserProxyAgent
from autogen_agentchat.teams import RoundRobinGroupChat
from autogen_agentchat.conditions import MaxMessageTermination
from autogen_ext.models import OpenAIChatCompletionClient
from briefcase_ai.integrations.frameworks import autogen_hook

handler = autogen_hook.install(context_version="v2.1")

model_client = OpenAIChatCompletionClient(model="gpt-4o")

assistant = AssistantAgent("assistant", model_client=model_client)
user_proxy = UserProxyAgent("user_proxy")

team = RoundRobinGroupChat(
[assistant, user_proxy],
termination_condition=MaxMessageTermination(3),
)

async def run():
await team.run(task="Summarize recent AI safety research.")

asyncio.run(run())

for record in handler.get_records():
print(f"{record['decision_type']}: {record['captured_at']}")

Record Format

Each record is a Dict[str, Any]:

{
"decision_id": "uuid-string",
"decision_type": "text_message",
"captured_at": "2026-02-26T10:00:00Z",
"logger": "autogen_agentchat.event",
"inputs": {
"source": "assistant",
"content": "Here is a summary of AI safety research..."
},
"outputs": {},
"context_version": "v2.1"
}

Event Types

decision_typeAutoGen eventKey fields
text_messageTextMessagesource, content
tool_call_requestToolCallRequestEventsource, tool_calls
tool_call_executionToolCallExecutionEventsource, results
tool_call_summaryToolCallSummaryMessagesource, content
control_messageStopMessage / HandoffMessagesource, content, subtype
autogen_eventUnknown / rawtype, raw

Export

from briefcase_ai.config import setup
from briefcase_ai.exporters import SentinelConnector

setup(
exporter=SentinelConnector(
workspace_id="your-workspace-id",
shared_key="your-shared-key",
)
)

handler = autogen_hook.install(async_capture=True)

Public API

MethodReturnsDescription
get_records()List[Dict[str, Any]]All captured decision records
clear()NoneReset all records
decision_countintNumber of captured records (property)
attach()NoneAttach to AutoGen event and trace loggers
detach()NoneRemove from all attached loggers

Module-level function

from briefcase_ai.integrations.frameworks.autogen_handler import install

install(
context_version: Optional[str] = None,
async_capture: bool = True,
) -> AutoGenEventHandler

Advanced: Per-Instance Exporter

Override the global exporter for this handler instance:

from briefcase_ai.exporters import SplunkHECExporter

handler = AutoGenEventHandler(
exporter=SplunkHECExporter(url="https://splunk.example.com:8088", token="your-hec-token"),
)

Troubleshooting

ImportError: autogen-agentchat is required: Install with pip install autogen-agentchat>=0.4.0. The handler raises at instantiation time if the package is absent.

No records captured: Call attach() or install() before your agent team runs. The handler only observes log records emitted after it is attached.

Double installation: install() is idempotent — it returns the existing handler without re-attaching. Use install() rather than manually calling attach() more than once.

Handler not detached after tests: Call handler.detach() in test teardown to avoid handler leaks across tests.

See Also