dina1 commited on
Commit
1fb4ee6
·
verified ·
1 Parent(s): d6e4d09

Update agents/graph_builder_langgraph.py

Browse files
Files changed (1) hide show
  1. agents/graph_builder_langgraph.py +15 -8
agents/graph_builder_langgraph.py CHANGED
@@ -55,15 +55,23 @@ async def node_generate(state: State, config=None, runtime=None) -> State:
55
  res = await generate_ui_html(state["requirements"], reference_html)
56
  return {"html": res["html"], "attempts": state.get("attempts", 0) + 1}
57
 
 
58
  async def node_qa(state: State, config=None, runtime=None) -> State:
59
- """Runs QA and guarantees dict output."""
60
  qa_result = await run_ui_qa(state["html"])
61
  if not isinstance(qa_result, dict):
62
  qa_result = {"score": 0, "comment": str(qa_result)}
63
- if "score" not in qa_result:
 
 
 
 
64
  qa_result["score"] = 0
65
- if "comment" not in qa_result:
66
- qa_result["comment"] = "No comment"
 
 
 
67
  return {"qa": qa_result}
68
 
69
  async def node_repair(state: State, config=None, runtime=None) -> State:
@@ -91,8 +99,8 @@ async def node_report(state: State, config=None, runtime=None) -> State:
91
 
92
  # ----- conditional guard -----
93
  def qa_guard(state: State) -> str:
94
- """Decide whether to proceed to report or repair."""
95
- qa_data = state.get("qa", {})
96
  if not isinstance(qa_data, dict):
97
  qa_data = {"score": 0, "comment": "Invalid QA format"}
98
 
@@ -105,8 +113,7 @@ def qa_guard(state: State) -> str:
105
  max_retries = int(os.environ.get("MAX_RETRIES", "2"))
106
  threshold = int(os.environ.get("QA_THRESHOLD", "85"))
107
 
108
- if os.environ.get("DEBUG_QA_GUARD", "0") == "1":
109
- print(f"[QA GUARD] score={score}, attempts={attempts}")
110
 
111
  if score >= threshold or attempts >= max_retries:
112
  return "report"
 
55
  res = await generate_ui_html(state["requirements"], reference_html)
56
  return {"html": res["html"], "attempts": state.get("attempts", 0) + 1}
57
 
58
+ a_guard functions (replace both completely)
59
  async def node_qa(state: State, config=None, runtime=None) -> State:
60
+ """Runs QA and guarantees normalized output."""
61
  qa_result = await run_ui_qa(state["html"])
62
  if not isinstance(qa_result, dict):
63
  qa_result = {"score": 0, "comment": str(qa_result)}
64
+
65
+ # Normalize values
66
+ try:
67
+ qa_result["score"] = int(qa_result.get("score", 0))
68
+ except Exception:
69
  qa_result["score"] = 0
70
+
71
+ if not isinstance(qa_result.get("comment"), str):
72
+ qa_result["comment"] = str(qa_result.get("comment", "No comment"))
73
+
74
+ print(f"[QA NODE OUTPUT] => {qa_result}") # debug log
75
  return {"qa": qa_result}
76
 
77
  async def node_repair(state: State, config=None, runtime=None) -> State:
 
99
 
100
  # ----- conditional guard -----
101
  def qa_guard(state: State) -> str:
102
+ """Route flow safely based on QA result."""
103
+ qa_data = state.get("qa") or {}
104
  if not isinstance(qa_data, dict):
105
  qa_data = {"score": 0, "comment": "Invalid QA format"}
106
 
 
113
  max_retries = int(os.environ.get("MAX_RETRIES", "2"))
114
  threshold = int(os.environ.get("QA_THRESHOLD", "85"))
115
 
116
+ print(f"[QA GUARD] score={score}, attempts={attempts}, threshold={threshold}")
 
117
 
118
  if score >= threshold or attempts >= max_retries:
119
  return "report"