Spaces:
Runtime error
Runtime error
Update utils/langgraph_pipeline.py
Browse files- utils/langgraph_pipeline.py +53 -20
utils/langgraph_pipeline.py
CHANGED
@@ -1,39 +1,72 @@
|
|
1 |
from langgraph.graph import StateGraph
|
|
|
|
|
2 |
from agents import (
|
3 |
product_manager_agent,
|
4 |
project_manager_agent,
|
5 |
software_architect_agent,
|
6 |
software_engineer_agent,
|
7 |
-
quality_assurance_agent
|
8 |
)
|
|
|
9 |
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
-
|
|
|
|
|
14 |
|
15 |
-
graph.add_node("
|
16 |
-
graph.add_node("
|
17 |
-
graph.add_node("Architect",
|
18 |
-
graph.add_node("Engineer",
|
19 |
-
graph.add_node("QA",
|
20 |
|
21 |
-
graph.set_entry_point("
|
22 |
-
graph.add_edge("
|
23 |
-
graph.add_edge("
|
24 |
graph.add_edge("Architect", "Engineer")
|
25 |
graph.add_edge("Engineer", "QA")
|
26 |
-
|
27 |
graph.set_finish_point("QA")
|
28 |
|
29 |
-
|
30 |
|
31 |
-
#
|
32 |
-
|
33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
|
35 |
with open("output/agent_log.json", "w") as f:
|
36 |
-
|
37 |
-
|
|
|
|
|
|
|
38 |
|
39 |
-
return
|
|
|
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,
|
7 |
software_architect_agent,
|
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"]
|