Agent.EnsureThreadExistsWithMessagesAsync<TThreadType> Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Ensures that the thread exists, is of the expected type, and is active, plus adds the provided message to the thread.
protected virtual System.Threading.Tasks.Task<TThreadType> EnsureThreadExistsWithMessagesAsync<TThreadType>(System.Collections.Generic.ICollection<Microsoft.SemanticKernel.ChatMessageContent> messages, Microsoft.SemanticKernel.Agents.AgentThread? thread, Func<TThreadType> constructThread, System.Threading.CancellationToken cancellationToken) where TThreadType : Microsoft.SemanticKernel.Agents.AgentThread;
abstract member EnsureThreadExistsWithMessagesAsync : System.Collections.Generic.ICollection<Microsoft.SemanticKernel.ChatMessageContent> * Microsoft.SemanticKernel.Agents.AgentThread * Func<'hreadType (requires 'hreadType :> Microsoft.SemanticKernel.Agents.AgentThread)> * System.Threading.CancellationToken -> System.Threading.Tasks.Task<'hreadType (requires 'hreadType :> Microsoft.SemanticKernel.Agents.AgentThread)> (requires 'hreadType :> Microsoft.SemanticKernel.Agents.AgentThread)
override this.EnsureThreadExistsWithMessagesAsync : System.Collections.Generic.ICollection<Microsoft.SemanticKernel.ChatMessageContent> * Microsoft.SemanticKernel.Agents.AgentThread * Func<'hreadType (requires 'hreadType :> Microsoft.SemanticKernel.Agents.AgentThread)> * System.Threading.CancellationToken -> System.Threading.Tasks.Task<'hreadType (requires 'hreadType :> Microsoft.SemanticKernel.Agents.AgentThread)> (requires 'hreadType :> Microsoft.SemanticKernel.Agents.AgentThread)
Protected Overridable Function EnsureThreadExistsWithMessagesAsync(Of TThreadType As AgentThread) (messages As ICollection(Of ChatMessageContent), thread As AgentThread, constructThread As Func(Of TThreadType), cancellationToken As CancellationToken) As Task(Of TThreadType)
Type Parameters
- TThreadType
The expected type of the thead.
Parameters
- messages
- ICollection<ChatMessageContent>
The messages to add to the thread once it is setup.
- thread
- AgentThread
The thread to create if it's null, validate it's type if not null, and start if it is not active.
- constructThread
- Func<TThreadType>
A callback to use to construct the thread if it's null.
- cancellationToken
- CancellationToken
The CancellationToken to monitor for cancellation requests. The default is None.
Returns
An async task that completes once all update are complete.