Spaces:
Runtime error
Runtime error
Update utils/langgraph_pipeline.py
Browse files- 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 |
-
|
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
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
graph
|
32 |
-
|
33 |
-
graph.add_node("
|
34 |
-
|
35 |
-
|
36 |
-
graph.
|
37 |
-
graph.
|
38 |
-
|
39 |
-
graph.
|
40 |
-
graph.add_edge("
|
41 |
-
|
42 |
-
|
43 |
-
graph.
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
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(
|
67 |
-
|
68 |
-
|
69 |
-
|
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
|
|
|
|
|
|