Microsoft Agent Framework Agents Created: 16 Feb 2026 Updated: 16 Feb 2026

Streaming vs. Non-Streaming with Microsoft Agent Framework in .NET

The Microsoft Agent Framework provides two ways to run an agent: non-streaming and streaming. The difference is simple — non-streaming waits for the entire response before returning it, while streaming delivers the response in real-time chunks as the model generates them.

The Setup (Shared)

Both approaches use the same agent configuration. We create a ChatClientAgent with system instructions via ChatOptions.Instructions:

using Microsoft.Agents.AI;
using Microsoft.Extensions.AI;
using OpenAI;

var apiKey = Environment.GetEnvironmentVariable("OPEN_AI_KEY");

if (string.IsNullOrWhiteSpace(apiKey))
{
Console.WriteLine("Please set the OPEN_AI_KEY environment variable.");
return;
}

IChatClient chatClient = new OpenAIClient(apiKey).GetChatClient("gpt-4o").AsIChatClient();

ChatClientAgent agent = chatClient.AsAIAgent(new ChatClientAgentOptions
{
Name = "TaskOrganizer",
Description = "An AI assistant that breaks down complex activities into simple, actionable steps.",
ChatOptions = new ChatOptions
{
Instructions = """
You are an AI assistant helping to organize daily tasks.
Your task is to break down complex activities into simple,
actionable steps.
Provide only the step-by-step breakdown without any additional
explanations.
"""
}
});

Non-Streaming: RunAsync

The RunAsync method sends the user message to the model and waits for the complete response before returning. The result is an AgentResponse object whose .Text property contains the full output.

Console.WriteLine("--- Non-Streaming ---");
var response = await agent.RunAsync(
"Prepare a healthy breakfast with coffee and clean up the kitchen afterwards.");
Console.WriteLine(response.Text);

When to use: When you need the full response at once — for example, to parse it, store it, or pass it to another agent.

Streaming: RunStreamingAsync

The RunStreamingAsync method returns an IAsyncEnumerable<AgentResponseUpdate>. Each update contains a small text chunk that you can write to the console (or send to a client) immediately.

Console.WriteLine("--- Streaming ---");
await foreach (var update in agent.RunStreamingAsync(
"Prepare a healthy breakfast with coffee and clean up the kitchen afterwards."))
{
Console.Write(update);
}
Console.WriteLine();

When to use: When you want a responsive user experience — the user sees text appearing token by token instead of waiting for the full generation to finish. This is the same behavior you see in ChatGPT's web interface.

Key Differences

AspectNon-Streaming (RunAsync)Streaming (RunStreamingAsync)
Return typeAgentResponseIAsyncEnumerable<AgentResponseUpdate>
First outputAfter full generation completesAs soon as the first token arrives
Best forProcessing, storing, or chaining resultsReal-time UI, chat interfaces, long responses
Print methodConsole.WriteLine(response.Text)Console.Write(update) inside await foreach

Both methods use the same agent, the same instructions, and the same underlying model — the only difference is how the response is delivered to your code.


Share this lesson: