# Updated section of create_agent to use single conditional def create_agent() -> StateGraph: """Build and return the LangGraph StateGraph.""" graph = StateGraph() graph.add_node("execute_task", execute_task) graph.add_node("verify_result", verify_result) graph.add_node("handle_error", handle_error) # Entry point graph.set_entry_point("execute_task") # After execution, decide whether to verify or end due to max attempts def check_max(state: AgentState): return "max_attempts" if state["attempts"] >= state["max_attempts"] else "verify_result" graph.add_conditional_edges("execute_task", check_max, {"max_attempts": END, "verify_result": "verify_result"}) # After verification, either finish or retry graph.add_conditional_edges( "verify_result", lambda x: x["status"], { "success": END, "failed": "handle_error", }, ) # Retry path graph.add_edge("handle_error", "execute_task") return graph