Sure, at each node, if the cost becomes greater than the current best set of actions, it won't pursue any further branches off that node. If it reaches the end (monster dies, you're beaten up, or round is 30) and the profit is greater than the current best option, that path will replace the current best option.
I've realized I'll have to add a kind of combat simulator to the code, to build semi-accurate action trees. Which is actually surprisingly easy now to do. This also means that I'll have a "macro" option in the code, which will submit the entire action tree as a macro.