Spaces:
Runtime error
Runtime error
Rename utils/run_pipeline_and_save.py to utils/langgraph_pipeline.py
Browse files- utils/langgraph_pipeline.py +39 -0
- utils/run_pipeline_and_save.py +0 -45
utils/langgraph_pipeline.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
def run_pipeline_and_save(prompt: str):
|
11 |
+
state = {"prompt": prompt, "chat_log": []}
|
12 |
+
|
13 |
+
graph = StateGraph()
|
14 |
+
|
15 |
+
graph.add_node("PM", lambda s: product_manager_agent.run(s))
|
16 |
+
graph.add_node("ProjM", lambda s: project_manager_agent.run(s))
|
17 |
+
graph.add_node("Architect", lambda s: software_architect_agent.run(s))
|
18 |
+
graph.add_node("Engineer", lambda s: software_engineer_agent.run(s))
|
19 |
+
graph.add_node("QA", lambda s: quality_assurance_agent.run(s))
|
20 |
+
|
21 |
+
graph.set_entry_point("PM")
|
22 |
+
graph.add_edge("PM", "ProjM")
|
23 |
+
graph.add_edge("ProjM", "Architect")
|
24 |
+
graph.add_edge("Architect", "Engineer")
|
25 |
+
graph.add_edge("Engineer", "QA")
|
26 |
+
|
27 |
+
graph.set_finish_point("QA")
|
28 |
+
|
29 |
+
final_state = graph.execute(state)
|
30 |
+
|
31 |
+
# Save outputs
|
32 |
+
with open("output/index.html", "w") as f:
|
33 |
+
f.write(final_state.get("final_output", ""))
|
34 |
+
|
35 |
+
with open("output/agent_log.json", "w") as f:
|
36 |
+
import json
|
37 |
+
json.dump(final_state["chat_log"], f, indent=2)
|
38 |
+
|
39 |
+
return final_state["chat_log"], final_state.get("final_output", "")
|
utils/run_pipeline_and_save.py
DELETED
@@ -1,45 +0,0 @@
|
|
1 |
-
import os
|
2 |
-
import json
|
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 |
-
OUTPUT_DIR = "output"
|
12 |
-
os.makedirs(OUTPUT_DIR, exist_ok=True)
|
13 |
-
|
14 |
-
def run_pipeline_and_save(prompt: str):
|
15 |
-
chat_log = []
|
16 |
-
|
17 |
-
# Step 1: Product Manager
|
18 |
-
pm_output = product_manager_agent.run(prompt)
|
19 |
-
chat_log.append({"Product Manager": pm_output})
|
20 |
-
|
21 |
-
# Step 2: Project Manager
|
22 |
-
proj_output = project_manager_agent.run(pm_output)
|
23 |
-
chat_log.append({"Project Manager": proj_output})
|
24 |
-
|
25 |
-
# Step 3: Software Architect
|
26 |
-
arch_output = software_architect_agent.run(proj_output)
|
27 |
-
chat_log.append({"Software Architect": arch_output})
|
28 |
-
|
29 |
-
# Step 4: Software Engineer
|
30 |
-
eng_output = software_engineer_agent.run(arch_output)
|
31 |
-
chat_log.append({"Software Engineer": eng_output})
|
32 |
-
|
33 |
-
# Step 5: Quality Assurance
|
34 |
-
qa_output = quality_assurance_agent.run(eng_output)
|
35 |
-
chat_log.append({"Quality Assurance": qa_output})
|
36 |
-
|
37 |
-
# Save final UI output files
|
38 |
-
with open(os.path.join(OUTPUT_DIR, "index.html"), "w") as f:
|
39 |
-
f.write(eng_output)
|
40 |
-
|
41 |
-
# Save chat log
|
42 |
-
with open(os.path.join(OUTPUT_DIR, "agent_log.json"), "w") as f:
|
43 |
-
json.dump(chat_log, f, indent=2)
|
44 |
-
|
45 |
-
return chat_log, eng_output
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|