MCPcopy Index your code
hub / github.com/SkyworkAI/DeepResearchAgent / _load_from_code

Method _load_from_code

src/tool/context.py:248–354  ·  view source on GitHub ↗

Load tools from code files. JSON file content example: { "metadata": { "saved_at": str, # "YYYY-MM-DD HH:MM:SS" "num_tools": int, # total tool count "num_versions": int # total version count },

(self)

Source from the content-addressed store, hash-verified

246 return tool_configs
247
248 async def _load_from_code(self):
249 """Load tools from code files.
250
251 JSON file content example:
252 {
253 "metadata": {
254 "saved_at": str, # "YYYY-MM-DD HH:MM:SS"
255 "num_tools": int, # total tool count
256 "num_versions": int # total version count
257 },
258 "tools": {
259 "tool_name": {
260 "current_version": "1.0.0",
261 "versions": {
262 "1.0.0": {
263 "name": str,
264 "description": str,
265 "metadata": dict,
266 "require_grad": bool,
267 "version": str,
268 "cls": Type[Tool],
269 "config": dict,
270 "instance": Tool, # will be built when needed
271 "function_calling": dict,
272 "text": str,
273 "args_schema": BaseModel,
274 "code": str
275 },
276 ...
277 }
278 }
279 }
280 }
281 """
282
283 tool_configs: Dict[str, ToolConfig] = {}
284
285 # If save file does not exist yet, nothing to load
286 if not os.path.exists(self.save_path):
287 logger.info(f"| 📂 Tool config file not found at {self.save_path}, skipping code-based loading")
288 return tool_configs
289
290 # Load all tool configs from json file
291 try:
292 with open(self.save_path, "r", encoding="utf-8") as f:
293 load_data = json.load(f)
294 except json.JSONDecodeError as e:
295 logger.warning(f"| ⚠️ Failed to parse tool config JSON from {self.save_path}: {e}")
296 return tool_configs
297
298 metadata = load_data.get("metadata", {})
299 tools_data = load_data.get("tools", {})
300
301 async def register_tool_class(tool_name: str, tool_data: Dict[str, Any]) -> Optional[Tuple[str, Dict[str, ToolConfig], Optional[ToolConfig]]]:
302 """Load all versions for a single tool from JSON."""
303 try:
304 current_version = tool_data.get("current_version", "1.0.0")
305 versions = tool_data.get("versions", {})

Callers 1

initializeMethod · 0.95

Calls 8

gather_with_concurrencyFunction · 0.90
warningMethod · 0.80
register_versionMethod · 0.80
existsMethod · 0.45
infoMethod · 0.45
loadMethod · 0.45
getMethod · 0.45
valuesMethod · 0.45

Tested by

no test coverage detected