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

Function build_graph_recursive

internagent/vis_tree.py:15–36  ·  view source on GitHub ↗

Recursively adds nodes and edges to the graphviz object.

(graph, hyp_id, hyp_map, child_map)

Source from the content-addressed store, hash-verified

13 return '\n'.join(textwrap.wrap(text, width=width, replace_whitespace=False))
14
15def build_graph_recursive(graph, hyp_id, hyp_map, child_map):
16 """Recursively adds nodes and edges to the graphviz object."""
17 if hyp_id not in hyp_map:
18 print(f"Warning: Hypothesis ID {hyp_id} not found in map.")
19 return
20
21 hyp = hyp_map[hyp_id]
22 node_label = f"ID: {hyp['id']}\nIter: {hyp.get('iteration', 'N/A')}\n\n{wrap_text(hyp['text'], NODE_WIDTH)}"
23
24 # Add the node
25 graph.node(hyp_id, label=node_label, shape='box', style='rounded,filled', fillcolor='lightblue' if hyp.get('iteration', -1) == 0 else 'lightgrey')
26
27 # Add edges to children and recurse
28 if hyp_id in child_map:
29 for child_id in child_map[hyp_id]:
30 if child_id in hyp_map:
31 # Add child node (and its subtree)
32 build_graph_recursive(graph, child_id, hyp_map, child_map)
33 # Add edge from current node to child
34 graph.edge(hyp_id, child_id)
35 else:
36 print(f"Warning: Child ID {child_id} referenced by {hyp_id} not found in map.")
37
38def vis_tree(json_file, output_pdf):
39 """

Callers 1

vis_treeFunction · 0.85

Calls 2

wrap_textFunction · 0.70
getMethod · 0.45

Tested by

no test coverage detected