JuliusBrussee/caveman · error · ImportError
Install caveman-middleware[autogen] to use the AutoGen…
Error message
Install caveman-middleware[autogen] to use the AutoGen adapter
What it means
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.
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)
Example fix
// before pip install caveman-middleware // after pip install 'caveman-middleware[autogen]'
Defensive patterns
Strategy: fallback
Validate before calling
import importlib.util
missing = [m for m in ('autogen_core', 'autogen_agentchat', 'autogen_ext', 'pydantic') if importlib.util.find_spec(m) is None]
if missing:
raise SystemExit(f'install caveman-middleware[autogen]; missing: {missing}') Try / catch
try:
import caveman_middleware.autogen as cm_autogen
except ImportError as e:
if 'caveman-middleware[autogen]' in str(e):
raise SystemExit('AutoGen adapter requested but extras not installed') from e
raise Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "X is not installed. Please install it with pip install Y": missing optional dependency errors — ImportError/ValueError raised when a library's optional extra was never installed — this error's family across 22 libraries.
Related errors
- Install caveman-middleware[litellm] to use the LiteLLM…
- Install caveman-middleware[llama-index] to use the…
- Install caveman-middleware[mcp] for the native MCP adapter
- Install caveman-middleware[pydantic-ai] to use the Pydantic…
- Install caveman-middleware[strands] to use the Strands…
AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20).
Data as JSON: /api/errors/97b6b7ed568a1256.
Report an issue: GitHub.
Appendix: source
Thrown at packages/middleware/python/caveman_middleware/autogen.py:30
import json
import uuid
import weakref
from collections import Counter
from contextlib import contextmanager
from dataclasses import asdict
from importlib.metadata import version
from typing import Any, Mapping
try:
from autogen_core import CancellationToken, Component, ComponentModel, FunctionCall
from autogen_core.models import (
AssistantMessage, ChatCompletionClient, CreateResult,
FunctionExecutionResult, FunctionExecutionResultMessage, SystemMessage, UserMessage,
)
from autogen_core.tools import BaseTool, FunctionTool, StaticStreamWorkbench, TextResultContent, ToolResult, Workbench
from pydantic import BaseModel
except ModuleNotFoundError as error:
raise ImportError("Install caveman-middleware[autogen] to use the AutoGen adapter") from error
from caveman_cloud.middleware import Adapter, Candidate, MiddlewareError, MiddlewareRuntime, Scope
from caveman_cloud.middleware.runtime import RECOVERY_DESCRIPTION, RECOVERY_SCHEMA
from ._native import Attempt, manifest, owner
from ._versions import matches_framework, supports_framework
from ._usage import usage
FRAMEWORK_VERSION = version("autogen-core")
ADAPTER = Adapter("autogen", "0.1.0", FRAMEWORK_VERSION, "autogen-messages-v1")
_component_runtimes = contextvars.ContextVar("caveman_autogen_component_runtimes", default={})
_loaded_components = contextvars.ContextVar("caveman_autogen_loaded_components", default=None)
@contextmanager
def component_runtimes(runtimes: Mapping[str, Any]):
"""Bind trusted runtimes while AutoGen loads a saved component.
Configurations store a reference key, never runtime credentials. Loading aView on GitHub (pinned to 3ee70a1026)