Yeah, the AI in such scenario is extremely bad. The defenders are piling at the gate from the inside, attackers from the outside.. attackers archers are doing something, which looks like riverdance(they keep the line and move back and forward, well, they sometimes shoot too). Cavalry of attackers seems to be charging randomly(which means they are riding around aimlessly), eventually they end up at the gate tho, where they can be picked off. I was in the army of a nobleman, the nobleman kept barking at me orders which made no sense(we all were stuck inside the keep, and I was leading a cavarly unit, I was repeatedly ordered to charge, flank etc... while gate was closed). So that part seems to be just a loop which generates random orders during battle.
There should be a way for the defenders at least to open the gates when necessary. I had to hack through the inner gate at some point using my sword, but then there was outer gate, which was bit too tough for the sword, so I eventually had to jump over the wall to finish off the final attackers.. Even then it was also buggy, the fleeing attackers got stuck in the tents in the camp.