{"record":{"id":"d2f24a3bf2687282","repo":"langchain-ai/deepagents","slug":"failed-to-instantiate-class-path-for-provide","errorCode":null,"errorMessage":"Failed to instantiate '{class_path}' for '{provider}:{model_name}': {e}","messagePattern":"Failed to instantiate '(.+?)' for '(.+?):(.+?)': (.+?)","errorType":"exception","errorClass":"ModelConfigError","httpStatus":null,"severity":"error","filePath":"libs/code/deepagents_code/config.py","lineNumber":5406,"sourceCode":"    cls = getattr(module, class_name, None)\n    if cls is None:\n        msg = (\n            f\"Class '{class_name}' not found in module '{module_path}' \"\n            f\"for provider '{provider}'\"\n        )\n        raise ModelConfigError(msg)\n\n    if not (isinstance(cls, type) and issubclass(cls, _BaseChatModel)):\n        msg = (\n            f\"'{class_path}' is not a BaseChatModel subclass (got {type(cls).__name__})\"\n        )\n        raise ModelConfigError(msg)\n\n    try:\n        return cls(model=model_name, **kwargs)\n    except Exception as e:\n        msg = f\"Failed to instantiate '{class_path}' for '{provider}:{model_name}': {e}\"\n        raise ModelConfigError(msg) from e\n\n\ndef _create_model_via_init(\n    model_name: str,\n    provider: str,\n    kwargs: dict[str, Any],\n) -> BaseChatModel:\n    \"\"\"Create a model using langchain's `init_chat_model`.\n\n    Args:\n        model_name: Model identifier.\n        provider: Provider name (may be empty for auto-detection).\n        kwargs: Additional keyword arguments.\n\n    Returns:\n        Instantiated `BaseChatModel`.\n\n    Raises:","sourceCodeStart":5388,"sourceCodeEnd":5424,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/code/deepagents_code/config.py#L5388-L5424","documentation":"Raised when a validated BaseChatModel subclass from `class_path` throws any exception in its constructor. The loader calls `cls(model=model_name, **kwargs)` and wraps any failure as `ModelConfigError` chained to the original exception, naming the class path and `provider:model` spec so constructor failures surface uniformly.","triggerScenarios":"`_create_model_from_class` instantiates the class and `__init__` raises — wrong model name, eagerly-validated missing API key, an unsupported kwarg from config params, or an init-time network call failing (config.py:5402-5406).","commonSituations":"Config params passing kwargs the constructor does not accept; custom class validating its API key at init while the env var is absent; a mistyped model name forwarded as `model=`.","solutions":["Read the chained original exception at the end of the traceback — it names the real constructor failure","Fix the offending kwarg in `[providers.<p>.params]` (or per-model params) in config.toml","Supply the missing credential/env var the custom class expects and retry"],"exampleFix":"// before (config.toml)\n[providers.custom.params]\nmax_retries = \"3\"  # constructor expects int\n\n// after\n[providers.custom.params]\nmax_retries = 3","handlingStrategy":"try-catch","validationCode":"import inspect\ndef kwargs_accepted(cls: type, kwargs: dict) -> list[str]:\n    params = inspect.signature(cls.__init__).parameters\n    return [k for k in kwargs if k not in params and k != \"model\"]","typeGuard":null,"tryCatchPattern":"from deepagents_code.model_config import ModelConfigError\ntry:\n    model = create_model(spec, class_path=class_path)\nexcept ModelConfigError as e:\n    logger.error(\"Custom model init failed for %s: %s\", spec, e.__cause__)\n    raise SystemExit(1)  # inspect e.__cause__ for the real constructor error","preventionTips":["Validate that every params-table key matches the class constructor signature","Set required env vars (API keys) before instantiating custom models","Keep constructor cheap: avoid network calls in __init__ of custom classes"],"tags":["config","instantiation","kwargs"],"backgroundTag":"model-init-failed","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}