Spaces:
Runtime error
Runtime error
Update utils/langgraph_pipeline.py
Browse files- utils/langgraph_pipeline.py +50 -51
utils/langgraph_pipeline.py
CHANGED
@@ -1,57 +1,56 @@
|
|
1 |
-
import
|
2 |
-
from langgraph.
|
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 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
|
|
|
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"]
|