Share via


ChatCompletionAgent.InvokeAsync Method

Definition

Overloads

InvokeAsync(ChatHistory, KernelArguments, Kernel, CancellationToken)
Obsolete.

Invokes the assistant to respond to the provided history.

InvokeAsync(ICollection<ChatMessageContent>, AgentThread, AgentInvokeOptions, CancellationToken)

Invoke the agent with the provided message and arguments.

InvokeAsync(ChatHistory, KernelArguments, Kernel, CancellationToken)

Caution

Use InvokeAsync with AgentThread instead. This method will be removed after May 1st 2025.

Invokes the assistant to respond to the provided history.

[System.Obsolete("Use InvokeAsync with AgentThread instead. This method will be removed after May 1st 2025.")]
public override System.Collections.Generic.IAsyncEnumerable<Microsoft.SemanticKernel.ChatMessageContent> InvokeAsync(Microsoft.SemanticKernel.ChatCompletion.ChatHistory history, Microsoft.SemanticKernel.KernelArguments? arguments = default, Microsoft.SemanticKernel.Kernel? kernel = default, System.Threading.CancellationToken cancellationToken = default);
[<System.Obsolete("Use InvokeAsync with AgentThread instead. This method will be removed after May 1st 2025.")>]
override this.InvokeAsync : Microsoft.SemanticKernel.ChatCompletion.ChatHistory * Microsoft.SemanticKernel.KernelArguments * Microsoft.SemanticKernel.Kernel * System.Threading.CancellationToken -> System.Collections.Generic.IAsyncEnumerable<Microsoft.SemanticKernel.ChatMessageContent>
Public Overrides Function InvokeAsync (history As ChatHistory, Optional arguments As KernelArguments = Nothing, Optional kernel As Kernel = Nothing, Optional cancellationToken As CancellationToken = Nothing) As IAsyncEnumerable(Of ChatMessageContent)

Parameters

history
ChatHistory

The conversation history.

arguments
KernelArguments

Optional arguments to pass to the agents's invocation, including any PromptExecutionSettings.

kernel
Kernel

The Kernel containing services, plugins, and other state for use by the agent.

cancellationToken
CancellationToken

The CancellationToken to monitor for cancellation requests. The default is None.

Returns

An asynchronous enumeration of response messages.

Attributes

Applies to

InvokeAsync(ICollection<ChatMessageContent>, AgentThread, AgentInvokeOptions, CancellationToken)

Invoke the agent with the provided message and arguments.

public override System.Collections.Generic.IAsyncEnumerable<Microsoft.SemanticKernel.Agents.AgentResponseItem<Microsoft.SemanticKernel.ChatMessageContent>> InvokeAsync(System.Collections.Generic.ICollection<Microsoft.SemanticKernel.ChatMessageContent> messages, Microsoft.SemanticKernel.Agents.AgentThread? thread = default, Microsoft.SemanticKernel.Agents.AgentInvokeOptions? options = default, System.Threading.CancellationToken cancellationToken = default);
override this.InvokeAsync : System.Collections.Generic.ICollection<Microsoft.SemanticKernel.ChatMessageContent> * Microsoft.SemanticKernel.Agents.AgentThread * Microsoft.SemanticKernel.Agents.AgentInvokeOptions * System.Threading.CancellationToken -> System.Collections.Generic.IAsyncEnumerable<Microsoft.SemanticKernel.Agents.AgentResponseItem<Microsoft.SemanticKernel.ChatMessageContent>>
Public Overrides Function InvokeAsync (messages As ICollection(Of ChatMessageContent), Optional thread As AgentThread = Nothing, Optional options As AgentInvokeOptions = Nothing, Optional cancellationToken As CancellationToken = Nothing) As IAsyncEnumerable(Of AgentResponseItem(Of ChatMessageContent))

Parameters

messages
ICollection<ChatMessageContent>

The messages to pass to the agent.

thread
AgentThread

The conversation thread to continue with this invocation. If not provided, creates a new thread.

options
AgentInvokeOptions

Optional parameters for agent invocation.

cancellationToken
CancellationToken

The CancellationToken to monitor for cancellation requests. The default is None.

Returns

An async list of response items that each contain a ChatMessageContent and an AgentThread.

Applies to