Documentation - v1.2.0-alpha.3
    Preparing search index...

    Manages the state of an Agent across turns in a conversation.

    AgentState provides functionality to persist and retrieve state data using a storage provider. It handles caching state in the turn context for performance, calculating change hashes to detect modifications, and managing property accessors for typed access to state properties.

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    storage: Storage

    The storage provider used to persist state between turns

    storageKey: StorageKeyFactory

    A factory function that generates keys for storing state data

    Methods

    • Clears the state by setting it to an empty object in the turn context.

      Parameters

      • context: TurnContext

        The turn context containing the state to clear

      Returns Promise<void>

      A promise that resolves when the clear operation is complete

      This does not remove the state from storage, it only clears the in-memory representation. Call saveChanges() after this to persist the empty state to storage.

    • Loads the state from storage into the turn context.

      Parameters

      • context: TurnContext

        The turn context to load state into

      • force: boolean = false

        If true, forces a reload from storage even if state is cached

      • OptionalcustomKey: CustomKey

        Optional custom storage key to use instead of the default

      Returns Promise<any>

      A promise that resolves to the loaded state object

      If state is already cached in the turn context and force is not set, the cached version will be used.

    • Saves the state to storage if it has changed since it was loaded.

      Parameters

      • context: TurnContext

        The turn context containing the state to save

      • force: boolean = false

        If true, forces a save to storage even if no changes are detected

      • OptionalcustomKey: CustomKey

        Optional custom storage key to use instead of the default

      Returns Promise<void>

      A promise that resolves when the save operation is complete

      Change detection uses a hash of the state object to determine if saving is necessary.