Spaces:
Sleeping
Sleeping
File size: 1,521 Bytes
0eebcd6 | 1 2 3 4 5 6 7 8 9 10 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 58 | # edges.py — Conditional edge routing for Autonomous Python Coding Agent
from langgraph.graph import END
from state import State
def route_after_ast(state: State) -> str:
if state["ast_valid"]:
return "test_generator"
if state["retries"] >= 3:
return "__end__"
return "debugger"
def route_after_test(state: State) -> str:
if state["passed"]:
return "hypothesis"
if state["retries"] >= 3:
return "hypothesis" # move forward after 3 tries
return "debugger"
def route_after_hypothesis(state: State) -> str:
return "benchmark" # never blocks pipeline
def route_after_benchmark(state: State) -> str:
error = state.get("error", "")
if "too slow" in error.lower() or "optimize" in error.lower():
if state["retries"] >= 3:
return "security"
return "debugger"
return "security"
def route_after_security(state: State) -> str:
if state["is_secure"]:
return "complexity"
if state["security_retries"] >= 2:
return "complexity" # give up, move forward
return "coder"
def route_after_complexity(state: State) -> str:
if state["is_simple"]:
return "reflection"
if state["complexity_retries"] >= 2:
return "reflection" # give up, move forward
return "coder"
def route_after_reflection(state: State) -> str:
if state["reflection_ok"]:
return "reviewer"
if state["retries"] >= 3:
return "reviewer" # ship after 3 tries
return "coder"
|