👉 Try the demo: https://github.com/LM-Kit/lm-kit-net-samples/tree/main/console_net/ai-agents/streaming/agent_streaming
Streaming Agent Responses for C# .NET Applications
🎯 Purpose of the Demo
An interactive console app that shows three streaming patterns on the same agent: pull-based IAsyncEnumerable<AgentStreamToken>, push-based IAgentStreamHandler, and a streaming-to-file recipe.
All inference runs on-device.
👥 Industry Target Audience
- App developers building chat UIs that need responsive token streaming.
- CLI tooling that streams long outputs incrementally.
- Pipelines that consume agent output as a stream (e.g., feed into a UI websocket).
- Logging / audit that wants per-token capture to disk.
🚀 Problem Solved
A chat UI that waits for full inference is a dead chat UI. Streaming tokens, reasoning, and tool calls are how production apps feel responsive. The demo pairs the pull-based IAsyncEnumerable API with the push-based callback handler so the right pattern for the right surface is one menu pick away.
💻 Application Overview
Interactive menu (no command-line arguments) with three modes:
| Mode | What it does |
|---|---|
| Stream | IAsyncEnumerable<AgentStreamToken> with typed token coloring (Content, Thinking, ToolCall, ToolResult). |
| Callback | Push-based pattern using the bundled DelegateStreamHandler.Console(). Reports status and duration. |
| Save | Stream tokens simultaneously to console and a UTF-8 text file. |
| Quit | Exit. |
✨ Key Features
StreamingAgentExecutorwithBufferSize,StreamThinking,StreamToolCallstoggles.StreamAsync(agent, input)for pull-basedawait foreach.ExecuteStreamingAsync(agent, input, IAgentStreamHandler)for push-based callbacks.AgentStreamToken.Typeenum for fine-grained token typing.
🧠 Model
qwen3.5:4b(current Qwen 3.5 dense).
🛠️ Getting Started
📋 Prerequisites
- .NET 8.0 or later
▶️ Running the Application
git clone https://github.com/LM-Kit/lm-kit-net-samples
cd lm-kit-net-samples/console_net/ai-agents/streaming/agent_streaming
dotnet run
Pick a mode from the menu.