MCPcopy
hub / github.com/langchain-ai/langchain / ensure_config

Function ensure_config

libs/core/langchain_core/runnables/config.py:132–159  ·  view source on GitHub ↗

Ensure that a config is a dict with all keys present. Args: config (Optional[RunnableConfig], optional): The config to ensure. Defaults to None. Returns: RunnableConfig: The ensured config.

(config: Optional[RunnableConfig] = None)

Source from the content-addressed store, hash-verified

130
131
132def ensure_config(config: Optional[RunnableConfig] = None) -> RunnableConfig:
133 """Ensure that a config is a dict with all keys present.
134
135 Args:
136 config (Optional[RunnableConfig], optional): The config to ensure.
137 Defaults to None.
138
139 Returns:
140 RunnableConfig: The ensured config.
141 """
142 empty = RunnableConfig(
143 tags=[],
144 metadata={},
145 callbacks=None,
146 recursion_limit=25,
147 )
148 if var_config := var_child_runnable_config.get():
149 empty.update(
150 cast(RunnableConfig, {k: v for k, v in var_config.items() if v is not None})
151 )
152 if config is not None:
153 empty.update(
154 cast(RunnableConfig, {k: v for k, v in config.items() if v is not None})
155 )
156 for key, value in empty.get("configurable", {}).items():
157 if isinstance(value, (str, int, float, bool)) and key not in empty["metadata"]:
158 empty["metadata"][key] = value
159 return empty
160
161
162def get_config_list(

Callers 15

invokeMethod · 0.90
fooFunction · 0.90
astreamMethod · 0.90
invokeMethod · 0.90
ainvokeMethod · 0.90
invokeMethod · 0.90
ainvokeMethod · 0.90
invokeMethod · 0.90
ainvokeMethod · 0.90

Calls 3

RunnableConfigClass · 0.85
getMethod · 0.45
updateMethod · 0.45

Tested by 2

fooFunction · 0.72
astreamMethod · 0.72