Home / Function/ with_config() — langchain Function Reference

with_config() — langchain Function Reference

Architecture documentation for the with_config() function in base.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  514cf019_f432_1f30_3f62_e457a97002ae["with_config()"]
  74f697e6_2555_becc_640e_6f41ea707eba["_ConfigurableModel"]
  514cf019_f432_1f30_3f62_e457a97002ae -->|defined in| 74f697e6_2555_becc_640e_6f41ea707eba
  0b90fa9e_f078_8f67_ae9e_cb118bf2fe05["_model_params()"]
  514cf019_f432_1f30_3f62_e457a97002ae -->|calls| 0b90fa9e_f078_8f67_ae9e_cb118bf2fe05
  206c801c_28be_c9dd_94bf_bab6c4e3ca55["_remove_prefix()"]
  514cf019_f432_1f30_3f62_e457a97002ae -->|calls| 206c801c_28be_c9dd_94bf_bab6c4e3ca55
  style 514cf019_f432_1f30_3f62_e457a97002ae fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain_v1/langchain/chat_models/base.py lines 668–699

    def with_config(
        self,
        config: RunnableConfig | None = None,
        **kwargs: Any,
    ) -> _ConfigurableModel:
        config = RunnableConfig(**(config or {}), **cast("RunnableConfig", kwargs))
        # Ensure config is not None after creation
        config = ensure_config(config)
        model_params = self._model_params(config)
        remaining_config = {k: v for k, v in config.items() if k != "configurable"}
        remaining_config["configurable"] = {
            k: v
            for k, v in config.get("configurable", {}).items()
            if _remove_prefix(k, self._config_prefix) not in model_params
        }
        queued_declarative_operations = list(self._queued_declarative_operations)
        if remaining_config:
            queued_declarative_operations.append(
                (
                    "with_config",
                    (),
                    {"config": remaining_config},
                ),
            )
        return _ConfigurableModel(
            default_config={**self._default_config, **model_params},
            configurable_fields=list(self._configurable_fields)
            if isinstance(self._configurable_fields, list)
            else self._configurable_fields,
            config_prefix=self._config_prefix,
            queued_declarative_operations=queued_declarative_operations,
        )

Domain

Subdomains

Frequently Asked Questions

What does with_config() do?
with_config() is a function in the langchain codebase, defined in libs/langchain_v1/langchain/chat_models/base.py.
Where is with_config() defined?
with_config() is defined in libs/langchain_v1/langchain/chat_models/base.py at line 668.
What does with_config() call?
with_config() calls 2 function(s): _model_params, _remove_prefix.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free