{"record":{"id":"97b6b7ed568a1256","repo":"JuliusBrussee/caveman","slug":"install-caveman-middleware-autogen-to-use-the-autogen","errorCode":null,"errorMessage":"Install caveman-middleware[autogen] to use the AutoGen adapter","messagePattern":"Install caveman-middleware\\[autogen\\] to use the AutoGen adapter","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"packages/middleware/python/caveman_middleware/autogen.py","lineNumber":30,"sourceCode":"import json\nimport uuid\nimport weakref\nfrom collections import Counter\nfrom contextlib import contextmanager\nfrom dataclasses import asdict\nfrom importlib.metadata import version\nfrom typing import Any, Mapping\n\ntry:\n    from autogen_core import CancellationToken, Component, ComponentModel, FunctionCall\n    from autogen_core.models import (\n        AssistantMessage, ChatCompletionClient, CreateResult,\n        FunctionExecutionResult, FunctionExecutionResultMessage, SystemMessage, UserMessage,\n    )\n    from autogen_core.tools import BaseTool, FunctionTool, StaticStreamWorkbench, TextResultContent, ToolResult, Workbench\n    from pydantic import BaseModel\nexcept ModuleNotFoundError as error:\n    raise ImportError(\"Install caveman-middleware[autogen] to use the AutoGen adapter\") from error\n\nfrom caveman_cloud.middleware import Adapter, Candidate, MiddlewareError, MiddlewareRuntime, Scope\nfrom caveman_cloud.middleware.runtime import RECOVERY_DESCRIPTION, RECOVERY_SCHEMA\nfrom ._native import Attempt, manifest, owner\nfrom ._versions import matches_framework, supports_framework\nfrom ._usage import usage\n\nFRAMEWORK_VERSION = version(\"autogen-core\")\nADAPTER = Adapter(\"autogen\", \"0.1.0\", FRAMEWORK_VERSION, \"autogen-messages-v1\")\n_component_runtimes = contextvars.ContextVar(\"caveman_autogen_component_runtimes\", default={})\n_loaded_components = contextvars.ContextVar(\"caveman_autogen_loaded_components\", default=None)\n\n\n@contextmanager\ndef component_runtimes(runtimes: Mapping[str, Any]):\n    \"\"\"Bind trusted runtimes while AutoGen loads a saved component.\n\n    Configurations store a reference key, never runtime credentials. Loading a","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/middleware/python/caveman_middleware/autogen.py#L12-L48","documentation":"The AutoGen adapter imports autogen_core/autogen_agentchat symbols (ChatCompletionClient, BaseTool, Workbench, pydantic BaseModel, etc.) at module import time. If those packages are absent, importing caveman_middleware.autogen raises this ImportError pointing at the extra. The adapter is an optional dependency, not bundled with the base install.","triggerScenarios":"Running `import caveman_middleware.autogen` (or any module importing it) in an environment where autogen-core/autogen-agentchat/autogen-ext or pydantic are not installed; deploying to a slim container image that omitted the [autogen] extra; using a framework integration that imports all adapters eagerly.","commonSituations":"Local dev machine has AutoGen installed but the CI/production image does not; fresh virtualenv created from a requirements.txt that pinned only caveman-middleware; switching a codebase from OpenAI to AutoGen without updating dependencies.","solutions":["Install the extra: pip install 'caveman-middleware[autogen]'","Or install AutoGen directly: pip install 'autogen-core>=0.7,<0.9' autogen-agentchat autogen-ext pydantic","Add caveman-middleware[autogen] to requirements.txt/pyproject dependencies so images and CI include it","If AutoGen is genuinely unused, remove the import of caveman_middleware.autogen (import lazily inside the code path that needs it)"],"exampleFix":"// before\npip install caveman-middleware\n// after\npip install 'caveman-middleware[autogen]'","handlingStrategy":"fallback","validationCode":"import importlib.util\nmissing = [m for m in ('autogen_core', 'autogen_agentchat', 'autogen_ext', 'pydantic') if importlib.util.find_spec(m) is None]\nif missing:\n    raise SystemExit(f'install caveman-middleware[autogen]; missing: {missing}')","typeGuard":null,"tryCatchPattern":"try:\n    import caveman_middleware.autogen as cm_autogen\nexcept ImportError as e:\n    if 'caveman-middleware[autogen]' in str(e):\n        raise SystemExit('AutoGen adapter requested but extras not installed') from e\n    raise","preventionTips":["Pin the extra in requirements/pyproject: caveman-middleware[autogen]","Import the adapter lazily inside the AutoGen-specific code path","Use the same Docker base image for dev and production so optional deps never diverge"],"tags":["python","import-error","dependencies","autogen","optional-dependency"],"backgroundTag":"missing-optional-dependency","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}