Actually the AI was working great at the beginning. After it got to be about 2 to 3 thousand lines of codes, the AIs started getting confused; Now we are around 20K lines. They are still good for well defined tasks like writing a specific function.
I believe that code lacks modularity and eventually came out as a spaghetti

That is why focus on efficiency and modularity especially when working with AIs with limited memory.
But man.. 20k lines? are you building a spaceship?