AutoGen Integration
AutoGen reply hooks and group chat audit integration.
Overview
AgentTrust integrates with Microsoft AutoGen via AgentTrustReplyHook (per-message validation) and AgentTrustGroupChatMonitor (post-conversation audit).
Tier: Team+ for adapters · OSS for basic @harness wrapping
Why It Matters
AutoGen group chats involve multiple agents exchanging messages. Governance hooks validate each reply and audit the full conversation.
Prerequisites
pip install agentrust-py pyautogenStep-by-Step Guide
Reply hook (per message)
Construct the hook, then attach it to the agent. attach() targets AutoGen v0.2
(pyautogen); attach_v4() targets AutoGen v0.4 (autogen-agentchat).
from autogen import AssistantAgent
from agentrust_sdk import AgentTrustReplyHook
hook = AgentTrustReplyHook(
agent_id="autogen-assistant",
base_url="http://127.0.0.1:8765", # adapter default is :8000
)
assistant = AssistantAgent("researcher", llm_config={...})
hook.attach(assistant) # v0.2
# hook.attach_v4(agent) # v0.4Group chat monitor
The monitor patches groupchat.append, so every message any speaker adds is validated.
from autogen import GroupChat, GroupChatManager
from agentrust_sdk import AgentTrustGroupChatMonitor
monitor = AgentTrustGroupChatMonitor(agent_id="autogen-group")
groupchat = GroupChat(agents=[...], messages=[])
manager = GroupChatManager(groupchat=groupchat)
monitor.attach(groupchat)block_on_block defaults to False on the group-chat monitor — group conversations
are audited rather than interrupted. Set it to True if a policy violation should abort
the conversation.
Alternative: @harness on wrapper
from agentrust_sdk import harness
@harness(agent_id="autogen-wrapper", framework="AutoGen")
def run_group_chat(user, input):
result = group_chat.run(input)
return {"conversation": result}Examples
See examples/autogen_agent.py.
Best Practices
- Use reply hook for real-time per-message governance
- Use group monitor for conversation-level audit trail
- Set distinct agent IDs per AutoGen agent role
Common Mistakes
- Catching
TierGateErroraround construction — the adapter raises plainRuntimeError, and it raises on an unconfigured machine because the key resolves to OSS - Validating only final message (miss intermediate risky outputs)
Troubleshooting
| Issue | Fix |
|---|---|
| Hook not called | Call hook.attach(agent) (v0.2) or hook.attach_v4(agent) (v0.4) — constructing the hook alone registers nothing |
RuntimeError: [AgentTrust] AutoGen adapter requires Team tier… | Upgrade to Team tier (this is not a TierGateError) |