Krishp1/Autonomous-Coding-Agent
0
1# edges.py — Conditional edge routing for Autonomous Python Coding Agent2 3from langgraph.graph import END4from state import State5 6 7def route_after_ast(state: State) -> str:8 if state["ast_valid"]:9 return "test_generator"10 if state["retries"] >= 3:11 return "__end__"12 return "debugger"13 14 15def route_after_test(state: State) -> str:16 if state["passed"]:17 return "hypothesis"18 if state["retries"] >= 3:19 return "hypothesis" # move forward after 3 tries20 return "debugger"21 22 23def route_after_hypothesis(state: State) -> str:24 return "benchmark" # never blocks pipeline25 26 27def route_after_benchmark(state: State) -> str:28 error = state.get("error", "")29 if "too slow" in error.lower() or "optimize" in error.lower():30 if state["retries"] >= 3:31 return "security"32 return "debugger"33 return "security"34 35 36def route_after_security(state: State) -> str:37 if state["is_secure"]:38 return "complexity"39 if state["security_retries"] >= 2:40 return "complexity" # give up, move forward41 return "coder"42 43 44def route_after_complexity(state: State) -> str:45 if state["is_simple"]:46 return "reflection"47 if state["complexity_retries"] >= 2:48 return "reflection" # give up, move forward49 return "coder"50 51 52def route_after_reflection(state: State) -> str:53 if state["reflection_ok"]:54 return "reviewer"55 # Own counter — "retries" is only incremented by the debugger node,56 # which this loop never visits, so it would never advance and could57 # bounce coder<->reflection until LangGraph's recursion_limit crashes.58 if state.get("reflection_retries", 0) >= 3:59 return "reviewer" # ship after 3 tries60 return "coder"61 