{"record":{"id":"1eb98837e149a560","repo":"JuliusBrussee/caveman","slug":"expected-an-autogen-chatcompletionclient","errorCode":null,"errorMessage":"Expected an AutoGen ChatCompletionClient","messagePattern":"Expected an AutoGen ChatCompletionClient","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/middleware/python/caveman_middleware/autogen.py","lineNumber":167,"sourceCode":"    scope: Scope\n    runtime_key: str = \"default\"\n\n\nclass CavemanWorkbenchConfig(BaseModel):\n    workbench: ComponentModel | list[ComponentModel]\n    scope: Scope\n    runtime_key: str = \"default\"\n\n\nclass CavemanChatCompletionClient(ChatCompletionClient, Component[CavemanModelConfig]):\n    \"\"\"Delegate every native call; model-only use is recovery-free.\"\"\"\n    component_provider_override = \"caveman_middleware.autogen.CavemanChatCompletionClient\"\n    component_config_schema = CavemanModelConfig\n    component_type = \"model\"\n\n    def __init__(self, model_client: ChatCompletionClient, *, runtime, scope: Scope, runtime_key=\"default\"):\n        if not isinstance(model_client, ChatCompletionClient):\n            raise TypeError(\"Expected an AutoGen ChatCompletionClient\")\n        self.model_client = model_client\n        self.runtime, self.scope = _check(runtime, scope), scope\n        self.runtime_key = runtime_key\n        self.version_supported = _version_supported()\n        if not self.version_supported and self.runtime.mode != \"off\":\n            self.runtime.decline(\"unsupported_version\")\n        # Public configuration inspection occurs once, and only safe route\n        # metadata is retained. Unknown contracts stay recovery-free.\n        try:\n            config = model_client.dump_component().config\n            self.model_id = config.get(\"model\")\n            self.recovery_contract = not any(config.get(k) for k in (\"response_format\", \"json_output\", \"output_format\", \"output_config\", \"extra_body\"))\n            self.recovery_contract &= config.get(\"tool_choice\", \"auto\") == \"auto\"\n        except (TypeError, ValueError, NotImplementedError, AttributeError):\n            self.model_id, self.recovery_contract = None, False\n\n    @property\n    def capabilities(self):","sourceCodeStart":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/middleware/python/caveman_middleware/autogen.py#L149-L185","documentation":"CavemanChatCompletionClient is a wrapper/decorator around an AutoGen ChatCompletionClient, not a standalone model implementation. Its constructor type-checks the wrapped model_client and raises this TypeError if it is not an instance of autogen_ext's (or autogen_core's) ChatCompletionClient, since all calls are delegated to it.","triggerScenarios":"Passing a raw OpenAI/Anthropic client object, a config dict, a string model name, or None as the model_client argument to CavemanChatCompletionClient(...).","commonSituations":"Constructing the underlying client via a helper that returns a different type (e.g. OpenAIChatCompletion built manually vs its config), passing a model name string hoping it resolves, or passing an object from an incompatible AutoGen major version.","solutions":["Wrap a real AutoGen ChatCompletionClient, e.g. OpenAIChatCompletionClient(model='gpt-4o', ...), and pass that instance.","If you have a serialized CavemanModelConfig/ComponentModel, load it via ChatCompletionClient.load_component(...) before wrapping.","Confirm the object implements the ChatCompletionClient protocol from the same installed autogen version (0.7/0.8) the middleware supports.","Never pass model name strings; resolve them into a client first."],"exampleFix":"// before\nclient = CavemanChatCompletionClient('gpt-4o', runtime=rt, scope=scope)\n// after\nfrom autogen_ext.models.openai import OpenAIChatCompletionClient\ninner = OpenAIChatCompletionClient(model='gpt-4o')\nclient = CavemanChatCompletionClient(inner, runtime=rt, scope=scope)","handlingStrategy":"type-guard","validationCode":"from autogen_core.models import ChatCompletionClient\nif not isinstance(inner, ChatCompletionClient):\n    raise TypeError(\"model_client must be a ChatCompletionClient\")","typeGuard":"def is_chat_completion_client(obj) -> bool:\n    from autogen_core.models import ChatCompletionClient\n    return isinstance(obj, ChatCompletionClient)","tryCatchPattern":"try:\n    client = CavemanChatCompletionClient(inner, runtime=rt, scope=scope)\nexcept TypeError as e:\n    if \"ChatCompletionClient\" in str(e):\n        inner = ChatCompletionClient.load_component(inner_config)\n        client = CavemanChatCompletionClient(inner, runtime=rt, scope=scope)\n    else:\n        raise","preventionTips":["Always build the inner client with AutoGen factories (OpenAIChatCompletionClient, etc.), never raw SDK clients.","Verify your autogen-core/autogen-ext versions match the middleware's supported range (0.7-0.8).","Keep model definitions as ComponentModel configs and load via load_component for consistency."],"tags":["python","autogen","type-error","model-client","constructor"],"backgroundTag":"invalid-constructor-argument","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"}