MCPcopy Create free account
hub / github.com/InternScience/InternAgent / add_node_recursive

Function add_node_recursive

visualize_mcts_claude.py:374–421  ·  view source on GitHub ↗
(node_id: str)

Source from the content-addressed store, hash-verified

372 )
373
374 def add_node_recursive(node_id: str):
375 if node_id not in nodes:
376 return
377
378 node = nodes[node_id]
379
380 # 构建标签
381 status_sym = "✓" if node.run_status == "SUCCESS" else "✗" if node.run_status == "FAILED" else "?"
382 stage_name = {"root": "ROOT", "draft": "DRAFT", "improve": "IMPROVE"}.get(node.stage, node.stage.upper())
383
384 label_lines = [
385 f"{status_sym} {stage_name}",
386 f"ID: {node.id[:8]}",
387 ]
388
389 if node.metric is not None:
390 label_lines.append(f"metric: {node.metric:.4f}")
391
392 if node.is_terminal:
393 label_lines.append("[TERMINAL]")
394
395 if node.improve_failure_depth > 0:
396 label_lines.append(f"[F{node.improve_failure_depth}]")
397
398 label = "\n".join(label_lines)
399
400 # 设置颜色
401 if node.id == best_node_id:
402 fillcolor = "#90EE90" # 最佳节点 - 亮绿色
403 elif node.run_status == "SUCCESS":
404 fillcolor = "#E8F5E9" # 成功 - 浅绿色
405 elif node.run_status == "FAILED":
406 fillcolor = "#FFCDD2" # 失败 - 浅红色
407 else:
408 fillcolor = "#F5F5F5" # 未知 - 灰色
409
410 if node.stage == "root":
411 fillcolor = "#BBDEFB" # 根节点 - 浅蓝色
412 elif node.stage == "draft":
413 fillcolor = "#FFF3E0" # draft - 浅橙色
414
415 g.node(node_id, label=label, fillcolor=fillcolor)
416
417 # 递归子节点
418 for child_id in node.children_ids:
419 if child_id in nodes:
420 add_node_recursive(child_id)
421 g.edge(node_id, child_id)
422
423 add_node_recursive(root_id)
424

Callers 1

print_tree_graphvizFunction · 0.70

Calls 1

getMethod · 0.45

Tested by

no test coverage detected