Skip to content
Zurück zur Startseite

§ INTEGRATION · AUTOGEN

AutoGen-Agent-Instrumentierung

Ein einziger Aufruf umschließt generate_reply, sodass jede Konversationsrunde durch die Execlave-Enforcement-Schicht läuft und jeder Tool-Call durch Ihre Policies abgesichert wird.

§ 01

Voraussetzungen

  • Execlave-Konto mit aktivem API-Schlüssel — Einstellungen → API-Schlüssel.
  • Ein registrierter Agent in Execlave. Verwenden Sie dessen kleingeschriebene Kebab-Case-agent_id.
  • AutoGen pyautogen >=0.2 oder die neuere autogen-agentchat-Distribution.
§ 02

Installation

Die Instrumentierung wird über ein optionales Extra bereitgestellt, sodass die Standardinstallation des SDK AutoGen nicht mit installiert.

Python

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

Sofort einrichten mit einem Copilot

Fügen Sie diesen Prompt in Ihren KI-Coding-Assistenten ein.

§ 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

Schnellstart

Ein Aufruf verdrahtet Execlave um generate_reply. Die Input-Enforcement läuft auf der letzten Benutzernachricht; die Tool-Allowlist-Enforcement läuft auf jedem tool_calls- / function_call-Eintrag der Antwort.

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

Umgang mit Blockierungen

Eine blockierte Eingabe oder ein blockierter Tool-Call löst PolicyBlockedError mit den genauen Verstößen aus. Die Antwort des Agenten wird in diesem Fall niemals an den Aufrufer zurückgegeben.

Python

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

Wie geht es weiter?

AutoGen-Integration — Execlave Docs