withStateLock
Executes the provided suspending block of code with exclusive access to the current state.
After block completes, the current AIAgentState snapshot is closed and replaced with a new snapshot carrying the updated iteration counter. The AIAgentState passed to block must not be retained outside of the block.
Return
The result of block.