ProviderSessionState<TState> Class

Definition

Provides strongly-typed state management for providers, enabling reading and writing of provider-specific state to and from an AgentSession's AgentSessionStateBag.

public class ProviderSessionState<TState> where TState : class
type ProviderSessionState<'State (requires 'State : null)> = class
Public Class ProviderSessionState(Of TState)

Type Parameters

TState

The type of the state to be maintained. Must be a reference type.

Inheritance
ProviderSessionState<TState>

Remarks

This class encapsulates the logic for initializing, retrieving, and persisting provider state in the session's StateBag using a configurable key and JSON serialization options. It is intended to be used as a composed field within provider implementations (e.g., AIContextProvider or ChatHistoryProvider subclasses) to avoid duplicating state management logic across provider type hierarchies.

State is stored in the StateBag using the StateKey property as the key, enabling multiple providers to maintain independent state within the same session.

Constructors

Name Description
ProviderSessionState<TState>(Func<AgentSession,TState>, String, JsonSerializerOptions)

Initializes a new instance of the ProviderSessionState<TState> class.

Properties

Name Description
StateKey

Gets the key used to store the provider state in the StateBag.

Methods

Name Description
GetOrInitializeState(AgentSession)

Gets the state from the session's StateBag, or initializes it using the state initializer if not present.

SaveState(AgentSession, TState)

Saves the specified state to the session's StateBag using the configured state key and JSON serializer options. If the session is null, this method does nothing.

Applies to