Rahul-8799 commited on
Commit
9e8fc5f
·
verified ·
1 Parent(s): 745fd96

Update utils/langgraph_pipeline.py

Browse files
Files changed (1) hide show
  1. utils/langgraph_pipeline.py +47 -62
utils/langgraph_pipeline.py CHANGED
@@ -1,6 +1,7 @@
 
1
  from langgraph.graph import StateGraph
2
- from langgraph.prebuilt import ToolNode
3
- from typing import Annotated, TypedDict
4
  from agents import (
5
  product_manager_agent,
6
  project_manager_agent,
@@ -8,65 +9,49 @@ from agents import (
8
  software_engineer_agent,
9
  quality_assurance_agent
10
  )
11
- import os, json
12
-
13
- # 1. Define your State
14
- class State(TypedDict):
15
- prompt: str
16
- pm_output: str
17
- proj_output: str
18
- arch_output: str
19
- eng_output: str
20
- qa_output: str
21
-
22
- # 2. Define each agent as a ToolNode
23
- pm_node = ToolNode.from_function(product_manager_agent.run)
24
- proj_node = ToolNode.from_function(project_manager_agent.run)
25
- arch_node = ToolNode.from_function(software_architect_agent.run)
26
- eng_node = ToolNode.from_function(software_engineer_agent.run)
27
- qa_node = ToolNode.from_function(quality_assurance_agent.run)
28
-
29
- # 3. Build graph with defined input/output
30
- def run_pipeline_and_save(prompt: str):
31
- graph = StateGraph(State)
32
-
33
- graph.add_node("ProductManager", pm_node)
34
- graph.add_node("ProjectManager", proj_node)
35
- graph.add_node("Architect", arch_node)
36
- graph.add_node("Engineer", eng_node)
37
- graph.add_node("QA", qa_node)
38
-
39
- graph.set_entry_point("ProductManager")
40
- graph.add_edge("ProductManager", "ProjectManager")
41
- graph.add_edge("ProjectManager", "Architect")
42
- graph.add_edge("Architect", "Engineer")
43
- graph.add_edge("Engineer", "QA")
44
- graph.set_finish_point("QA")
45
-
46
- final_graph = graph.compile()
47
-
48
- # Initial input
49
- inputs = {"prompt": prompt}
50
-
51
- # Run full chain
52
- results = final_graph.invoke(inputs)
53
-
54
- # Save log
55
- chat_log = [
56
- {"Product Manager": results["pm_output"]},
57
- {"Project Manager": results["proj_output"]},
58
- {"Software Architect": results["arch_output"]},
59
- {"Software Engineer": results["eng_output"]},
60
- {"QA Engineer": results["qa_output"]}
61
- ]
62
-
63
  os.makedirs("output", exist_ok=True)
64
-
65
  with open("output/agent_log.json", "w") as f:
66
- json.dump(chat_log, f, indent=2)
67
-
68
- # Write HTML file if generated
69
- with open("output/index.html", "w") as f:
70
- f.write(results["qa_output"])
71
-
72
- return chat_log, results["qa_output"]
 
1
+ import os, json
2
  from langgraph.graph import StateGraph
3
+ from langgraph.prebuilt.tool_node import ToolNode
4
+
5
  from agents import (
6
  product_manager_agent,
7
  project_manager_agent,
 
9
  software_engineer_agent,
10
  quality_assurance_agent
11
  )
12
+ from utils.zip_output import zip_output
13
+
14
+ def run_pipeline_and_save(prompt):
15
+ conversation = []
16
+
17
+ # Initialize LangGraph state graph
18
+ graph = StateGraph()
19
+ graph.set_input_type(str)
20
+ graph.set_output_type(dict)
21
+
22
+ # Add tool-wrapped nodes
23
+ pm_node = ToolNode(product_manager_agent.run)
24
+ proj_node = ToolNode(project_manager_agent.run)
25
+ arch_node = ToolNode(software_architect_agent.run)
26
+ eng_node = ToolNode(software_engineer_agent.run)
27
+ qa_node = ToolNode(quality_assurance_agent.run)
28
+
29
+ # Add nodes to graph
30
+ graph.add_node("product_manager", pm_node)
31
+ graph.add_node("project_manager", proj_node)
32
+ graph.add_node("software_architect", arch_node)
33
+ graph.add_node("software_engineer", eng_node)
34
+ graph.add_node("quality_assurance", qa_node)
35
+
36
+ # Define execution flow
37
+ graph.set_entry_point("product_manager")
38
+ graph.add_edge("product_manager", "project_manager")
39
+ graph.add_edge("project_manager", "software_architect")
40
+ graph.add_edge("software_architect", "software_engineer")
41
+ graph.add_edge("software_engineer", "quality_assurance")
42
+
43
+ # Compile and execute
44
+ app = graph.compile()
45
+ outputs = app.invoke(prompt)
46
+
47
+ # Capture outputs
48
+ for k, v in outputs.items():
49
+ conversation.append({"agent": k, "message": v})
50
+
51
+ # Save to log and zip output
 
 
 
 
 
 
 
 
 
 
 
 
52
  os.makedirs("output", exist_ok=True)
 
53
  with open("output/agent_log.json", "w") as f:
54
+ json.dump(conversation, f, indent=2)
55
+
56
+ zip_path = zip_output()
57
+ return [(x["agent"], x["message"]) for x in conversation], zip_path