AIAgentStateManager

class AIAgentStateManager(state: AIAgentState = AIAgentState())(source)

Manages the state of an AI agent by providing thread-safe access and mechanisms to update the internal state using a locking mechanism.

This class ensures consistency across state modifications by using a mutual exclusion lock, allowing only one coroutine to access or modify the state at a time.

Note: on every withStateLock invocation, a fresh AIAgentState snapshot is created that carries over the current iteration counter, and the previous snapshot is closed. Consumers must therefore not retain references to the AIAgentState instance received inside the lock across calls.

Constructors

Link copied to clipboard
constructor(state: AIAgentState = AIAgentState())

Creates a new instance of AIAgentStateManager with the initial state, defaulting to a new AIAgentState if not provided.

Functions

Link copied to clipboard
suspend fun <T> withStateLock(block: suspend (AIAgentState) -> T): T

Executes the provided suspending block of code with exclusive access to the current state.