Skip to content
Back to home

§ INTEGRATION · AUTOGEN

AutoGen agent instrumentation

One call wraps generate_reply so every conversation round runs through Execlave enforcement and every tool call is gated by your policies.

§ 01

Prerequisites

  • Execlave account with an active API key — Settings → API keys.
  • A registered agent in Execlave. Use its lowercase-kebab agent_id.
  • AutoGen pyautogen >=0.2 or the newer autogen-agentchat distribution.
§ 02

Install

Instrumentation is shipped behind an optional extra so the default SDK install does not pull AutoGen.

Python

pip install 'execlave-sdk[autogen]'
§ 03

Instant setup with a copilot

Paste this prompt into your AI coding assistant.

§ Copy prompt · paste into your AI coding assistant
You are adding Execlave (an AI agent governance platform) to an existing Python project that uses Microsoft AutoGen (pyautogen / autogen-agentchat). Do not rewrite existing agents — only attach instrumentation. Rules you MUST follow:1. Install the correct extra: `pip install 'execlave-sdk[autogen]'`. Add it to requirements.txt / pyproject.toml.2. Read `EXECLAVE_API_KEY` from environment variables. Never hardcode keys. Add it to `.env.example`.3. Create exactly ONE Execlave client per process and reuse it: `exe = Execlave(api_key=os.environ["EXECLAVE_API_KEY"])`.4. Call `instrument_autogen_agent(agent, exe, agent_id="<stable-kebab-id>")` for each agent in the conversation, BEFORE the first `generate_reply` or chat run. Import: `from execlave.integrations.autogen import instrument_autogen_agent`.5. `agent_id` is a stable kebab-case string identifying this agent in the Execlave dashboard — NOT the AutoGen agent's display name.6. `instrument_autogen_agent` is IDEMPOTENT — a `_execlave_instrumented` marker is set on the agent so calling it twice is a no-op. Do not guard it with your own check.7. Wrap the call site (`assistant.generate_reply`, `user_proxy.initiate_chat`, etc.) in try/except for `execlave.errors.PolicyBlockedError`. On block, return a structured 4xx response containing `exc.violations`. Do NOT swallow.8. Do NOT call `exe.enforce_policy` manually — the wrapper enforces on the last user message (input policies) and on each `tool_calls` / `function_call` entry in the reply (tool-allowlist policies).9. Tool calls are extracted from both the modern `tool_calls` list and the legacy `function_call` shape. You do not need to normalise the reply yourself.10. On process shutdown, call `exe.flush()`.11. JavaScript is NOT supported — AutoGen is Python-only. Deliverables:- Add the install command and env vars to the project manifest and `.env.example`.- One diff per file; do not modify unrelated agent logic. Reference: https://www.execlave.com/docs/integrations/autogenAPI reference: https://www.execlave.com/docs/sdk-reference
§ 04

Quick start

One call wires Execlave around generate_reply. Input enforcement runs on the last user message; tool-allowlist enforcement runs on every tool_calls / function_call entry in the reply.

Python

from autogen import ConversableAgentfrom execlave import Execlavefrom execlave.integrations.autogen import instrument_autogen_agent exe = Execlave(api_key="exe_prod_...") assistant = ConversableAgent(    name="assistant",    llm_config={"config_list": [{"model": "gpt-4o-mini"}]},) # Idempotent — safe to call repeatedly. Wraps generate_reply so the# last user message goes through pre-execution enforcement, and every# tool_calls / function_call entry in the reply runs a tool-allowlist# check before the tool is allowed to run.instrument_autogen_agent(assistant, exe, agent_id="ops-assistant") reply = assistant.generate_reply(    messages=[{"role": "user", "content": "Pull last week's incidents"}],)
§ 05

Handling blocks

A blocked input or tool raises PolicyBlockedError with the exact violations. The agent's reply is never returned to the caller in that case.

Python

from execlave.errors import PolicyBlockedError try:    reply = assistant.generate_reply(messages=conversation)except PolicyBlockedError as exc:    return {"error": "blocked", "violations": exc.violations}
§ 06

What's next

AutoGen integration — Execlave Docs