(llm)
| 262 | |
| 263 | |
| 264 | def run_workflow_as_server(llm): |
| 265 | # Load subgraph data |
| 266 | with open("workflow.json", 'r') as file: |
| 267 | graphs = json.load(file) |
| 268 | |
| 269 | # Process each subgraph |
| 270 | for graph in graphs: |
| 271 | subgraph_name = graph.get("name") |
| 272 | node_map = parse_nodes_from_json(graph) |
| 273 | |
| 274 | # Register the tool functions dynamically if has tool node, must before build graph |
| 275 | for tool_node in find_nodes_by_type(node_map, "TOOL"): |
| 276 | tool_code = f"{tool_node.description}" |
| 277 | exec(tool_code, globals()) |
| 278 | |
| 279 | |
| 280 | subgraph = build_subgraph(node_map, llm) |
| 281 | subgraph_registry[subgraph_name] = subgraph |
| 282 | |
| 283 | |
| 284 | # Main Graph |
| 285 | main_graph = StateGraph(MainGraphState) |
| 286 | main_graph.add_node("subgraph", invoke_root) |
| 287 | main_graph.set_entry_point("subgraph") |
| 288 | main_graph = main_graph.compile() |
| 289 | |
| 290 | |
| 291 | # ========================== |
| 292 | # Run |
| 293 | # ========================== |
| 294 | for state in main_graph.stream( |
| 295 | { |
| 296 | "input": None, |
| 297 | } |
| 298 | ): |
| 299 | logger(state) |
no test coverage detected