MCPcopy Index your code
hub / github.com/OpenBMB/ChatDev / from_dict

Method from_dict

entity/configs/node/tooling.py:197–274  ·  view source on GitHub ↗
(cls, data: Mapping[str, Any], *, path: str)

Source from the content-addressed store, hash-verified

195
196 @classmethod
197 def from_dict(cls, data: Mapping[str, Any], *, path: str) -> "FunctionToolConfig":
198 mapping = require_mapping(data, path)
199 tools = ensure_list(mapping.get("tools"))
200 if not tools:
201 raise ConfigError("tools must be provided for function tooling", extend_path(path, "tools"))
202
203 catalog = get_function_catalog()
204 expanded_tools: List[Tuple[Dict[str, Any], str]] = []
205 for idx, tool in enumerate(tools):
206 tool_path = extend_path(path, f"tools[{idx}]")
207 if not isinstance(tool, Mapping):
208 raise ConfigError("tool entry must be a mapping", tool_path)
209 normalized = dict(tool)
210 raw_name = normalized.get("name")
211 if not isinstance(raw_name, str) or not raw_name.strip():
212 raise ConfigError("tool name is required", extend_path(tool_path, "name"))
213 name = raw_name.strip()
214 normalized["name"] = name
215 module_name = cls._extract_module_from_all(name)
216 if module_name:
217 expanded_tools.extend(
218 cls._expand_module_all_entry(
219 module_name=module_name,
220 catalog=catalog,
221 path=tool_path,
222 original=normalized,
223 )
224 )
225 continue
226 expanded_tools.append((normalized, tool_path))
227
228 tool_specs: List[Dict[str, Any]] = []
229 seen_functions: Dict[str, str] = {}
230 for entry, entry_path in expanded_tools:
231 normalized = dict(entry)
232 name = normalized.get("name")
233 if not isinstance(name, str) or not name.strip():
234 raise ConfigError("tool name is required", extend_path(entry_path, "name"))
235 metadata = catalog.get(name)
236 if metadata is None:
237 raise ConfigError(
238 f"function '{name}' not found under function directory",
239 extend_path(entry_path, "name"),
240 )
241 previous = seen_functions.get(name)
242 if previous is not None:
243 raise ConfigError(
244 f"function '{name}' is declared multiple times (also in {previous})",
245 extend_path(entry_path, "name"),
246 )
247 seen_functions[name] = entry_path
248
249 auto_fill = normalized.get("auto_fill", True)
250 if not isinstance(auto_fill, bool):
251 raise ConfigError("auto_fill must be boolean", extend_path(entry_path, "auto_fill"))
252 merged = dict(normalized)
253 if auto_fill:
254 if not merged.get("description") and metadata.description:

Callers

nothing calls this directly

Calls 9

require_mappingFunction · 0.90
ensure_listFunction · 0.90
ConfigErrorClass · 0.90
extend_pathFunction · 0.90
get_function_catalogFunction · 0.90
optional_boolFunction · 0.90
getMethod · 0.45

Tested by

no test coverage detected