writeSession
Executes a write session on the AIAgentLLMContext, suspending until all other active write and read sessions on this context complete, then running block under exclusive access. At the end of the session, prompt, tools and model are overwritten with the values mutated inside the session.
Concurrency caveats:
The underlying lock is not reentrant. Do not call writeSession, readSession, withPrompt or copy on the same context from inside block — doing so will deadlock (see RWLock).
block runs while holding the write lock; keep it as short as possible and avoid launching long-running child coroutines that need to re-acquire this lock.
Cancellation inside block is propagated; partial mutations made on the session before cancellation will not be committed to the outer context.