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)
| 130 | |
| 131 | |
| 132 | def 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 | |
| 162 | def get_config_list( |