{"record":{"id":"76c9738e308c8b01","repo":"JuliusBrussee/caveman","slug":"install-caveman-middleware-strands-to-use-the-strands","errorCode":null,"errorMessage":"Install caveman-middleware[strands] to use the Strands adapter","messagePattern":"Install caveman-middleware\\[strands\\] to use the Strands adapter","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"packages/middleware/python/caveman_middleware/strands.py","lineNumber":15,"sourceCode":"\"\"\"Strands native Model delegate, including the structured-output hook gap.\"\"\"\nfrom __future__ import annotations\n\nimport asyncio\nimport json\nimport uuid\nimport weakref\n\ntry:\n    from strands import tool\n    from strands.models.model import Model\n    from strands.plugins import Plugin\n    from strands.types.tools import ToolContext\nexcept ModuleNotFoundError as error:\n    raise ImportError(\"Install caveman-middleware[strands] to use the Strands adapter\") from error\n\nfrom caveman_cloud.middleware import Adapter, Candidate, MiddlewareRuntime, Scope\nfrom caveman_cloud.middleware.runtime import RECOVERY_DESCRIPTION, RECOVERY_SCHEMA\nfrom ._native import Attempt, manifest, owner, plain, replace_path\nfrom ._versions import matches_framework\nfrom ._usage import usage\n\nADAPTER = Adapter(\"strands\", \"0.1.0\", \"1.55.0\", \"strands-content-v1\")\n\n\ndef _scope(source, state):\n    scope = source if isinstance(source, Scope) else source(state or {})\n    if not isinstance(scope, Scope):\n        raise TypeError(\"Strands scope resolver must return a Caveman Scope\")\n    return scope\n\n\nclass CavemanModel(Model):","sourceCodeStart":1,"sourceCodeEnd":33,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/middleware/python/caveman_middleware/strands.py#L1-L33","documentation":"The Strands adapter is an optional extra. The module imports strands at import time; if the strands distribution is missing, the ModuleNotFoundError is re-raised as an ImportError naming the extra to install.","triggerScenarios":"Importing caveman_middleware.strands (or a bundle module that imports it) in an environment where `strands-agents`/strands is not installed, e.g. plain `pip install caveman-middleware`.","commonSituations":"CI runners with only base requirements; serverless images trimmed of extras; onboarding docs followed without the [strands] extra; a move from a monorepo dev env to a clean production env.","solutions":["Run `pip install 'caveman-middleware[strands]'`","Remove the strands adapter import if Strands is not used in this service","Add the extra to your dependency manifest so all environments install it"],"exampleFix":"// before\npip install caveman-middleware\n// after\npip install 'caveman-middleware[strands]'","handlingStrategy":"try-catch","validationCode":"import importlib.util\nif importlib.util.find_spec(\"strands\") is None:\n    raise SystemExit(\"Install caveman-middleware[strands]\")","typeGuard":null,"tryCatchPattern":"try:\n    from caveman_middleware import strands as caveman_strands\nexcept ImportError as e:\n    if \"strands\" in str(e):\n        logging.error(\"Run: pip install 'caveman-middleware[strands]'\")\n    raise","preventionTips":["Install with extras: pip install 'caveman-middleware[strands]'","Pin the extra in your dependency manifest","Only import the strands adapter in services that use Strands","Verify imports in a CI smoke test on clean images"],"tags":["python","import-error","optional-dependency","strands"],"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"}