AIAgentWithOpenAIExtensions.RunStreamingAsync 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.
Runs the AI agent with a single OpenAI chat message and returns the response as collection of native OpenAI OpenAI.Chat.StreamingChatCompletionUpdate.
public static System.ClientModel.AsyncCollectionResult<OpenAI.Chat.StreamingChatCompletionUpdate> RunStreamingAsync(this Microsoft.Agents.AI.AIAgent agent, System.Collections.Generic.IEnumerable<OpenAI.Chat.ChatMessage> messages, Microsoft.Agents.AI.AgentThread? thread = default, Microsoft.Agents.AI.AgentRunOptions? options = default, System.Threading.CancellationToken cancellationToken = default);
static member RunStreamingAsync : Microsoft.Agents.AI.AIAgent * seq<OpenAI.Chat.ChatMessage> * Microsoft.Agents.AI.AgentThread * Microsoft.Agents.AI.AgentRunOptions * System.Threading.CancellationToken -> System.ClientModel.AsyncCollectionResult<OpenAI.Chat.StreamingChatCompletionUpdate>
<Extension()>
Public Function RunStreamingAsync (agent As AIAgent, messages As IEnumerable(Of ChatMessage), Optional thread As AgentThread = Nothing, Optional options As AgentRunOptions = Nothing, Optional cancellationToken As CancellationToken = Nothing) As AsyncCollectionResult(Of StreamingChatCompletionUpdate)
Parameters
- agent
- AIAgent
The AI agent to run.
- messages
- IEnumerable<OpenAI.Chat.ChatMessage>
The collection of OpenAI chat messages to send to the agent.
- thread
- AgentThread
The conversation thread to continue with this invocation. If not provided, creates a new thread. The thread will be mutated with the provided message and agent response.
- options
- AgentRunOptions
Optional parameters for agent invocation.
- cancellationToken
- CancellationToken
The CancellationToken to monitor for cancellation requests. The default is None.
Returns
A Task<TResult> representing the asynchronous operation that returns a native OpenAI OpenAI.Chat.ChatCompletion response.
Exceptions
Thrown when agent or messages is null.
Thrown when the agent's response cannot be converted to a OpenAI.Chat.ChatCompletion, typically when the underlying representation is not an OpenAI response.
Thrown when the messages type is not supported by the message conversion method.
Remarks
This method converts the OpenAI chat messages to the Microsoft Extensions AI format using the appropriate conversion method, runs the agent, and then extracts the native OpenAI OpenAI.Chat.ChatCompletion from the response using AsOpenAIChatCompletion(AgentRunResponse).