Microsoft AutoGen’s conversational agent framework enables multi-agent conversations and tool use. The managed-agents package wraps governance around every AutoGen tool call before it executes.
Installation
pip install managed-agents
Governing AutoGen tool functions
AutoGen tools are registered Python functions. Wrap each function with governance before the tool logic runs:
python
from managed_agents import NomoticHarness, GovernanceDenied
import autogen
harness = NomoticHarness(
api_key="nm_live_...",
agent_id="nmc-...",
platform="autogen",
)
async def governed_send_email(
recipient: str,
subject: str,
body: str
) -> str:
try:
await harness.govern(
"send_email",
{"recipient": recipient, "subject": subject}
)
return await send_email_implementation(recipient, subject, body)
except GovernanceDenied as e:
return f"Email blocked by governance: {e}"
# Register with AutoGen
assistant = autogen.AssistantAgent(
name="assistant",
llm_config=llm_config,
)
autogen.register_function(
governed_send_email,
caller=assistant,
executor=user_proxy,
description="Send an email to a recipient"
)
Sync usage
If your AutoGen setup uses synchronous functions, run the async govern call with asyncio:
python
import asyncio
from managed_agents import NomoticHarness, GovernanceDenied
harness = NomoticHarness(
api_key="nm_live_...",
agent_id="nmc-...",
platform="autogen",
)
def governed_query_database(query: str) -> str:
try:
asyncio.run(harness.govern("database_query", {"query": query}))
return execute_query(query)
except GovernanceDenied as e:
return f"Query blocked: {e}"
Verdict callback
Use the on_verdict callback to log every governance decision alongside your AutoGen conversation history:
python
def log_verdict(verdict_result):
print(f"Verdict: {verdict_result.verdict} | UCS: {verdict_result.ucs:.4f}")
harness = NomoticHarness(
api_key="nm_live_...",
agent_id="nmc-...",
platform="autogen",
on_verdict=log_verdict,
)