AIAgent.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.
Overloads
| RunStreamingAsync(AgentThread, AgentRunOptions, CancellationToken) |
Runs the agent in streaming mode without providing new input messages, relying on existing context and instructions. |
| RunStreamingAsync(ChatMessage, AgentThread, AgentRunOptions, CancellationToken) |
Runs the agent in streaming mode with a single chat message. |
| RunStreamingAsync(IEnumerable<ChatMessage>, AgentThread, AgentRunOptions, CancellationToken) |
Runs the agent in streaming mode with a collection of chat messages, providing the core streaming invocation logic. |
| RunStreamingAsync(String, AgentThread, AgentRunOptions, CancellationToken) |
Runs the agent in streaming mode with a text message from the user. |
RunStreamingAsync(AgentThread, AgentRunOptions, CancellationToken)
Runs the agent in streaming mode without providing new input messages, relying on existing context and instructions.
public System.Collections.Generic.IAsyncEnumerable<Microsoft.Agents.AI.AgentRunResponseUpdate> RunStreamingAsync(Microsoft.Agents.AI.AgentThread? thread = default, Microsoft.Agents.AI.AgentRunOptions? options = default, System.Threading.CancellationToken cancellationToken = default);
member this.RunStreamingAsync : Microsoft.Agents.AI.AgentThread * Microsoft.Agents.AI.AgentRunOptions * System.Threading.CancellationToken -> System.Collections.Generic.IAsyncEnumerable<Microsoft.Agents.AI.AgentRunResponseUpdate>
Public Function RunStreamingAsync (Optional thread As AgentThread = Nothing, Optional options As AgentRunOptions = Nothing, Optional cancellationToken As CancellationToken = Nothing) As IAsyncEnumerable(Of AgentRunResponseUpdate)
Parameters
- thread
- AgentThread
The conversation thread to use for this invocation. If null, a new thread will be created.
The thread will be updated with any response messages generated during invocation.
- options
- AgentRunOptions
Optional configuration parameters for controlling the agent's invocation behavior.
- cancellationToken
- CancellationToken
The CancellationToken to monitor for cancellation requests. The default is None.
Returns
An asynchronous enumerable of AgentRunResponseUpdate instances representing the streaming response.
Applies to
RunStreamingAsync(ChatMessage, AgentThread, AgentRunOptions, CancellationToken)
Runs the agent in streaming mode with a single chat message.
public System.Collections.Generic.IAsyncEnumerable<Microsoft.Agents.AI.AgentRunResponseUpdate> RunStreamingAsync(Microsoft.Extensions.AI.ChatMessage message, Microsoft.Agents.AI.AgentThread? thread = default, Microsoft.Agents.AI.AgentRunOptions? options = default, System.Threading.CancellationToken cancellationToken = default);
member this.RunStreamingAsync : Microsoft.Extensions.AI.ChatMessage * Microsoft.Agents.AI.AgentThread * Microsoft.Agents.AI.AgentRunOptions * System.Threading.CancellationToken -> System.Collections.Generic.IAsyncEnumerable<Microsoft.Agents.AI.AgentRunResponseUpdate>
Public Function RunStreamingAsync (message As ChatMessage, Optional thread As AgentThread = Nothing, Optional options As AgentRunOptions = Nothing, Optional cancellationToken As CancellationToken = Nothing) As IAsyncEnumerable(Of AgentRunResponseUpdate)
Parameters
- message
- ChatMessage
The chat message to send to the agent.
- thread
- AgentThread
The conversation thread to use for this invocation. If null, a new thread will be created.
The thread will be updated with the input message and any response messages generated during invocation.
- options
- AgentRunOptions
Optional configuration parameters for controlling the agent's invocation behavior.
- cancellationToken
- CancellationToken
The CancellationToken to monitor for cancellation requests. The default is None.
Returns
An asynchronous enumerable of AgentRunResponseUpdate instances representing the streaming response.
Exceptions
message is null.
Applies to
RunStreamingAsync(IEnumerable<ChatMessage>, AgentThread, AgentRunOptions, CancellationToken)
Runs the agent in streaming mode with a collection of chat messages, providing the core streaming invocation logic.
public abstract System.Collections.Generic.IAsyncEnumerable<Microsoft.Agents.AI.AgentRunResponseUpdate> RunStreamingAsync(System.Collections.Generic.IEnumerable<Microsoft.Extensions.AI.ChatMessage> messages, Microsoft.Agents.AI.AgentThread? thread = default, Microsoft.Agents.AI.AgentRunOptions? options = default, System.Threading.CancellationToken cancellationToken = default);
abstract member RunStreamingAsync : seq<Microsoft.Extensions.AI.ChatMessage> * Microsoft.Agents.AI.AgentThread * Microsoft.Agents.AI.AgentRunOptions * System.Threading.CancellationToken -> System.Collections.Generic.IAsyncEnumerable<Microsoft.Agents.AI.AgentRunResponseUpdate>
Public MustOverride Function RunStreamingAsync (messages As IEnumerable(Of ChatMessage), Optional thread As AgentThread = Nothing, Optional options As AgentRunOptions = Nothing, Optional cancellationToken As CancellationToken = Nothing) As IAsyncEnumerable(Of AgentRunResponseUpdate)
Parameters
- messages
- IEnumerable<ChatMessage>
The collection of messages to send to the agent for processing.
- thread
- AgentThread
The conversation thread to use for this invocation. If null, a new thread will be created.
The thread will be updated with the input messages and any response updates generated during invocation.
- options
- AgentRunOptions
Optional configuration parameters for controlling the agent's invocation behavior.
- cancellationToken
- CancellationToken
The CancellationToken to monitor for cancellation requests. The default is None.
Returns
An asynchronous enumerable of AgentRunResponseUpdate instances representing the streaming response.
Remarks
This is the primary streaming invocation method that implementations must override. It provides real-time updates as the agent processes the input and generates its response, enabling more responsive user experiences.
Each AgentRunResponseUpdate represents a portion of the complete response, allowing consumers to display partial results, implement progressive loading, or provide immediate feedback to users.
Applies to
RunStreamingAsync(String, AgentThread, AgentRunOptions, CancellationToken)
Runs the agent in streaming mode with a text message from the user.
public System.Collections.Generic.IAsyncEnumerable<Microsoft.Agents.AI.AgentRunResponseUpdate> RunStreamingAsync(string message, Microsoft.Agents.AI.AgentThread? thread = default, Microsoft.Agents.AI.AgentRunOptions? options = default, System.Threading.CancellationToken cancellationToken = default);
member this.RunStreamingAsync : string * Microsoft.Agents.AI.AgentThread * Microsoft.Agents.AI.AgentRunOptions * System.Threading.CancellationToken -> System.Collections.Generic.IAsyncEnumerable<Microsoft.Agents.AI.AgentRunResponseUpdate>
Public Function RunStreamingAsync (message As String, Optional thread As AgentThread = Nothing, Optional options As AgentRunOptions = Nothing, Optional cancellationToken As CancellationToken = Nothing) As IAsyncEnumerable(Of AgentRunResponseUpdate)
Parameters
- message
- String
The user message to send to the agent.
- thread
- AgentThread
The conversation thread to use for this invocation. If null, a new thread will be created.
The thread will be updated with the input message and any response messages generated during invocation.
- options
- AgentRunOptions
Optional configuration parameters for controlling the agent's invocation behavior.
- cancellationToken
- CancellationToken
The CancellationToken to monitor for cancellation requests. The default is None.
Returns
An asynchronous enumerable of AgentRunResponseUpdate instances representing the streaming response.
Exceptions
message is null, empty, or contains only whitespace.
Remarks
The provided text will be wrapped in a ChatMessage with the User role. Streaming invocation provides real-time updates as the agent generates its response.