Table of Contents

Class TurnState

Namespace
Microsoft.Agents.Builder.State
Assembly
Microsoft.Agents.Builder.dll

Manages a collection of AgentState and provides ability to load and save in parallel.

public class TurnState : ITurnState
Inheritance
TurnState
Implements
Inherited Members

Constructors

TurnState(params IAgentState[])

Initializes a new instance of the TurnState class.

public TurnState(params IAgentState[] agentStates)

Parameters

agentStates IAgentState[]

initial list of AgentState objects to manage.

TurnState(IStorage, params IAgentState[])

Creates AgentStateSet with default ConversationState and UserState

public TurnState(IStorage storage, params IAgentState[] agentStates)

Parameters

storage IStorage
agentStates IAgentState[]

Additional list of AgentState objects to manage.

Properties

Conversation

public ConversationState Conversation { get; }

Property Value

ConversationState

Private

public PrivateConversationState Private { get; }

Property Value

PrivateConversationState

Temp

public TempState Temp { get; }

Property Value

TempState

User

public UserState User { get; }

Property Value

UserState

Methods

Add(IAgentState)

public TurnState Add(IAgentState agentState)

Parameters

agentState IAgentState

Returns

TurnState

ClearState(string)

Clears the state.

public void ClearState(string scope)

Parameters

scope string

The scope name. eg "conversation", etc...

Remarks

This method clears the state cache. Call SaveChangesAsync(ITurnContext, bool, CancellationToken) to persist this change in the storage layer.

DeleteValue(string)

Delete a property.

public void DeleteValue(string path)

Parameters

path string

The full path to the property: {scope}.{name}

GetScope(string)

public IAgentState GetScope(string scope)

Parameters

scope string

Returns

IAgentState

GetScope<T>()

public T GetScope<T>()

Returns

T

Type Parameters

T

GetValue<T>(string, Func<T>)

Get a property value.

public T GetValue<T>(string name, Func<T> defaultValueFactory = null)

Parameters

name string
defaultValueFactory Func<T>

Defines the default value. Invoked when no value been set for the requested state property. If defaultValueFactory is defined as null in that case, the method returns null.

Returns

T

Type Parameters

T

HasValue(string)

Checks for the existence of a property.

public bool HasValue(string path)

Parameters

path string

The full path to the property: {scope}.{name}

Returns

bool

LoadStateAsync(ITurnContext, bool, CancellationToken)

Load all AgentState records in parallel.

public Task LoadStateAsync(ITurnContext turnContext, bool force = false, CancellationToken cancellationToken = default)

Parameters

turnContext ITurnContext

turn context.

force bool

should data be forced into cache.

cancellationToken CancellationToken

A cancellation token that can be used by other objects or threads to receive notice of cancellation.

Returns

Task

A task that represents the work queued to execute.

SaveStateAsync(ITurnContext, bool, CancellationToken)

Save All AgentState changes in parallel.

public Task SaveStateAsync(ITurnContext turnContext, bool force = false, CancellationToken cancellationToken = default)

Parameters

turnContext ITurnContext

turn context.

force bool

should data be forced to save even if no change were detected.

cancellationToken CancellationToken

A cancellation token that can be used by other objects or threads to receive notice of cancellation.

Returns

Task

A task that represents the work queued to execute.

SetValue(string, object)

Set a property value.

public void SetValue(string path, object value)

Parameters

path string

The full path to the property: {scope}.{name}

value object

The property value.

TryGetScope<T>(out T)

public bool TryGetScope<T>(out T value)

Parameters

value T

Returns

bool

Type Parameters

T