Rahul-8799 commited on
Commit
fb940d6
·
verified ·
1 Parent(s): f1d3135

Update utils/langgraph_pipeline.py

Browse files
Files changed (1) hide show
  1. utils/langgraph_pipeline.py +8 -14
utils/langgraph_pipeline.py CHANGED
@@ -8,15 +8,13 @@ from agents import (
8
  quality_assurance_agent,
9
  )
10
  from langchain_core.messages import HumanMessage, AIMessage
11
- from langchain_core.messages.base import BaseMessage
12
  from typing import TypedDict, List
13
-
14
 
15
  class InputState(TypedDict):
16
  messages: List[BaseMessage]
17
  chat_log: list
18
 
19
-
20
  class OutputState(TypedDict):
21
  pm_output: str
22
  proj_output: str
@@ -25,10 +23,10 @@ class OutputState(TypedDict):
25
  qa_output: str
26
  chat_log: list
27
 
28
-
29
- # ✅ DO NOT USE @tool here — this bypasses LangChain's strict typing enforcement
30
  def bridge_to_product_manager(state: dict) -> dict:
31
- """Convert HumanMessage into structured AIMessage for Product Manager agent."""
 
 
32
  user_prompt = state["messages"][-1].content
33
 
34
  system_spec = f"""# Stakeholder Prompt
@@ -45,17 +43,16 @@ Please analyze and generate a structured product specification including goals,
45
  "chat_log": state["chat_log"] + [{"role": "System", "content": system_spec}],
46
  }
47
 
 
 
 
48
 
49
- # ✅ Use ToolNode.from_function to avoid StructuredTool issues
50
- bridge_node = ToolNode.from_function(bridge_to_product_manager)
51
  pm_node = ToolNode([product_manager_agent.run])
52
  proj_node = ToolNode([project_manager_agent.run])
53
  arch_node = ToolNode([software_architect_agent.run])
54
  dev_node = ToolNode([software_engineer_agent.run])
55
  qa_node = ToolNode([quality_assurance_agent.run])
56
 
57
-
58
- # LangGraph setup
59
  graph = StateGraph(input=InputState, output=OutputState)
60
 
61
  graph.add_node("Bridge", bridge_node)
@@ -75,13 +72,10 @@ graph.add_edge("QualityAssurance", END)
75
 
76
  compiled_graph = graph.compile()
77
 
78
-
79
  def run_pipeline_and_save(prompt: str):
80
  initial_state = {
81
  "messages": [HumanMessage(content=prompt)],
82
  "chat_log": [],
83
  }
84
-
85
  final_state = compiled_graph.invoke(initial_state)
86
-
87
- return final_state["chat_log"], final_state["qa_output"]
 
8
  quality_assurance_agent,
9
  )
10
  from langchain_core.messages import HumanMessage, AIMessage
 
11
  from typing import TypedDict, List
12
+ from langchain_core.messages.base import BaseMessage
13
 
14
  class InputState(TypedDict):
15
  messages: List[BaseMessage]
16
  chat_log: list
17
 
 
18
  class OutputState(TypedDict):
19
  pm_output: str
20
  proj_output: str
 
23
  qa_output: str
24
  chat_log: list
25
 
 
 
26
  def bridge_to_product_manager(state: dict) -> dict:
27
+ """
28
+ Convert HumanMessage into structured AIMessage for Product Manager agent.
29
+ """
30
  user_prompt = state["messages"][-1].content
31
 
32
  system_spec = f"""# Stakeholder Prompt
 
43
  "chat_log": state["chat_log"] + [{"role": "System", "content": system_spec}],
44
  }
45
 
46
+ # Define the bridge node as a simple function node
47
+ def bridge_node(state: dict) -> dict:
48
+ return bridge_to_product_manager(state)
49
 
 
 
50
  pm_node = ToolNode([product_manager_agent.run])
51
  proj_node = ToolNode([project_manager_agent.run])
52
  arch_node = ToolNode([software_architect_agent.run])
53
  dev_node = ToolNode([software_engineer_agent.run])
54
  qa_node = ToolNode([quality_assurance_agent.run])
55
 
 
 
56
  graph = StateGraph(input=InputState, output=OutputState)
57
 
58
  graph.add_node("Bridge", bridge_node)
 
72
 
73
  compiled_graph = graph.compile()
74
 
 
75
  def run_pipeline_and_save(prompt: str):
76
  initial_state = {
77
  "messages": [HumanMessage(content=prompt)],
78
  "chat_log": [],
79
  }
 
80
  final_state = compiled_graph.invoke(initial_state)
81
+ return final_state["chat_log"], final_state["qa_output"]