Rahul-8799 commited on
Commit
90521dc
·
verified ·
1 Parent(s): 6aa229b

Update utils/langgraph_pipeline.py

Browse files
Files changed (1) hide show
  1. utils/langgraph_pipeline.py +50 -51
utils/langgraph_pipeline.py CHANGED
@@ -1,57 +1,56 @@
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,
8
  software_architect_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
 
 
1
+ from langgraph.graph import StateGraph, END
2
+ from langgraph.prebuilt import ToolNode
 
 
3
  from agents import (
4
  product_manager_agent,
5
  project_manager_agent,
6
  software_architect_agent,
7
  software_engineer_agent,
8
+ quality_assurance_agent,
9
  )
10
+
11
+ # Define the state schema
12
+ state_schema = {
13
+ "input": str,
14
+ "pm_output": str,
15
+ "proj_output": str,
16
+ "arch_output": str,
17
+ "dev_output": str,
18
+ "qa_output": str,
19
+ "chat_log": list,
20
+ }
21
+
22
+ # Wrap each agent
23
+ pm_node = ToolNode.from_callable(product_manager_agent.run)
24
+ proj_node = ToolNode.from_callable(project_manager_agent.run)
25
+ arch_node = ToolNode.from_callable(software_architect_agent.run)
26
+ dev_node = ToolNode.from_callable(software_engineer_agent.run)
27
+ qa_node = ToolNode.from_callable(quality_assurance_agent.run)
28
+
29
+ # Define the graph
30
+ graph = StateGraph(state_schema)
31
+
32
+ graph.add_node("ProductManager", pm_node)
33
+ graph.add_node("ProjectManager", proj_node)
34
+ graph.add_node("SoftwareArchitect", arch_node)
35
+ graph.add_node("SoftwareEngineer", dev_node)
36
+ graph.add_node("QualityAssurance", qa_node)
37
+
38
+ graph.set_entry_point("ProductManager")
39
+ graph.add_edge("ProductManager", "ProjectManager")
40
+ graph.add_edge("ProjectManager", "SoftwareArchitect")
41
+ graph.add_edge("SoftwareArchitect", "SoftwareEngineer")
42
+ graph.add_edge("SoftwareEngineer", "QualityAssurance")
43
+ graph.add_edge("QualityAssurance", END)
44
+
45
+ # Compile it
46
+ compiled_graph = graph.compile()
47
+
48
+ # Define the wrapper
49
+ def run_pipeline_and_save(prompt: str):
50
+ initial_state = {
51
+ "input": prompt,
52
+ "chat_log": [],
53
+ }
54
+ final_state = compiled_graph.invoke(initial_state)
55
+
56
+ return final_state["chat_log"], final_state["qa_output"]