This simple sample demonstrates background responses (continuation tokens) using a minimal console app. It shows how to start streaming a response, capture a continuation token, stop the stream, and later resume the generation using that token.
What it shows
- Enabling background responses via
AgentRunOptions.AllowBackgroundResponses. - Streaming partial responses using
RunStreamingAsync. - Capturing a continuation token and stopping the stream.
- Resuming generation with the previously captured token and combining streamed fragments into readable output.
Files of interest
Program.cs– demo flow and streaming logicStreamConsoleHelper.cs– helper for formatting and accumulating token fragmentsResponseClientProvider.cs– obtains the response client configured for your environment
Run
-
Configure your provider credentials (user-secrets or environment variables) as described in the top-level lesson
06-MAF/readme.md. -
Build and run:
cd samples/MAF/MAF-BackgroundResponses-01-Simple
dotnet build
dotnet runRelated
- Lesson guide:
06-MAF/README-BackgroundResponses.md - Persisted conversation samples:
../MAF-Persisting-01-Simple/and../MAF-Persisting-02-Menu/
License: MIT