Creates an instance of StateManager.
The repository for persisting state.
Optionalstrategy: StateSavingStrategy = 'explicit'The state saving strategy to use.
Clears the internal context cache. Useful if the underlying storage is manipulated externally during an agent's processing cycle, though this is generally not recommended. Or for testing purposes.
Disables specific tools for a conversation thread by removing them from the thread's enabled tools list. This method loads the current thread configuration, updates the enabledTools array, and persists the changes. Cache is invalidated to ensure fresh data on next load.
The unique identifier of the thread.
Array of tool names to disable for this thread.
A promise that resolves when the tools are disabled.
Enables specific tools for a conversation thread by adding them to the thread's enabled tools list. This method loads the current thread configuration, updates the enabledTools array, and persists the changes. Cache is invalidated to ensure fresh data on next load.
The unique identifier of the thread.
Array of tool names to enable for this thread.
A promise that resolves when the tools are enabled.
Gets the list of currently enabled tools for a specific thread. This is a convenience method that loads the thread context and returns the enabledTools array.
The unique identifier of the thread.
A promise that resolves to an array of enabled tool names, or empty array if no tools are enabled.
Retrieves a specific value from the thread's configuration (ThreadConfig).
Loads the context first (which might come from cache in implicit mode).
The expected type of the configuration value.
The ID of the thread.
The top-level configuration key.
A promise resolving to the configuration value, or undefined.
Checks if a specific tool is permitted for use within a given thread.
It loads the thread's context and checks the enabledTools array in the configuration.
The ID of the thread.
The name of the tool to check.
A promise resolving to true if the tool is listed in the thread's enabledTools config, false otherwise or if the context/config cannot be loaded.
Loads the complete context (ThreadConfig and AgentState) for a specific thread.
If in 'implicit' state saving strategy, it caches the loaded context and a snapshot
of its AgentState for later comparison in saveStateIfModified.
The unique identifier for the thread.
Optional_userId: stringOptional user identifier (currently unused).
A promise resolving to the ThreadContext object.
Persists the thread's AgentState if it has been modified.
Behavior depends on the stateSavingStrategy:
AgentState persistence and logs a warning.AgentState (from the cached ThreadContext modified by the agent)
with the snapshot taken during loadThreadContext. If different, saves the state
to the repository and updates the snapshot.The ID of the thread whose state might need saving.
A promise that resolves when the state is saved or the operation is skipped.
Explicitly sets or updates the AgentState for a specific thread by calling the underlying state repository.
If in 'implicit' mode, this also updates the cached snapshot to prevent saveStateIfModified
from re-saving the same state immediately.
The unique identifier of the thread.
The AgentState object to save. Must not be undefined or null.
A promise that resolves when the state is saved.
Sets or completely replaces the configuration (ThreadConfig) for a specific thread
by calling the underlying state repository. This also clears any cached context for the thread.
The ID of the thread.
The complete ThreadConfig object.
A promise that resolves when the configuration is saved.
Manages thread-specific configuration (ThreadConfig) and state (AgentState) using an underlying StateRepository. Supports explicit and implicit state saving strategies.