This sample demonstrates how to persist (serialize) an AgentThread to disk and later reload it to resume a conversation with the same agent type.
What it shows
- Creating an
AgentThreadand running a prompt - Serializing the thread JSON to
agent_thread.jsonin the application folder - Rehydrating the thread by deserializing the JSON and calling
agent.DeserializeThread(...) - Continuing the conversation with the resumed thread
Setup
- Configure your AI provider credentials (example using dotnet user-secrets):
cd samples/MAF/MAF-Persisting-01-Simple
dotnet user-secrets set "AzureOpenAI:Endpoint" "https://<your-endpoint>.openai.azure.com/"
dotnet user-secrets set "AzureOpenAI:Deployment" "gpt-5-mini"
# az login is required (samples use AzureCliCredential)- Build and run:
dotnet build
dotnet runNotes
- The sample relies on shared helper files (ChatClientProvider.cs, StreamConsoleHelper.cs, ResponseClientProvider.cs) that are linked into the project via
csprojcompile includes. - The saved thread file
agent_thread.jsonwill be created in the app working directory. Treat this file as sensitive — it contains conversation history.
Troubleshooting
- If you see authentication errors, verify your user-secrets or environment variables are set correctly for your chosen provider.
- If deserialization fails, ensure you are using the same agent type to deserialize the thread.
Related docs
- Lesson guide:
06-MAF/README-PersistingConversations.md - Microsoft Learn: Persisting and Resuming Agent Conversations
License: MIT