How to Write a Custom Checkpoint Store for Microsoft Agent Framework Workflows in C#
A Microsoft Agent Framework checkpoint manager keeps its checkpoints in a checkpoint store, and you can write your own store by deriving from JsonCheckpointStore and overriding three methods. Here's a small store that keeps checkpoints in memory and prints a line for every call, so you can see exactly when the framework saves, lists and reads checkpoints.
The interface behind every store says what a store is for: Implementations of this interface enable durable or in-memory storage of checkpoints, which can be used to resume or audit long-running processes. Agent Framework's own FileSystemJsonCheckpointStore writes checkpoints to JSON files. A store of your own decides where they live.
Syntax
internal sealed class <StoreName> : JsonCheckpointStore
{
public override ValueTask<CheckpointInfo> CreateCheckpointAsync(
string sessionId, JsonElement value, CheckpointInfo? parent = null)
{
// Save value under a new CheckpointInfo for sessionId, and return that CheckpointInfo.
}
public override ValueTask<JsonElement> RetrieveCheckpointAsync(string sessionId, CheckpointInfo key)
{
// Return the value saved under key.
}
public override ValueTask<IEnumerable<CheckpointInfo>> RetrieveIndexAsync(
string sessionId, CheckpointInfo? withParent = null)
{
// Return the session's checkpoints, oldest first.
}
}
CheckpointManager <checkpointManager> = CheckpointManager.CreateJson(new <StoreName>());
| Part | What it is |
|---|---|
<StoreName> | Your store's class. |
JsonCheckpointStore | The base class, in the Microsoft.Agents.AI.Workflows.Checkpointing namespace: An abstract base class for checkpoint stores that use JSON for serialization. |
CreateCheckpointAsync | Asynchronously creates a checkpoint for the specified session and key, associating it with the provided value and optional parent checkpoint. It returns the CheckpointInfo of the checkpoint it saved. |
sessionId | The session the checkpoint belongs to. All three methods get it. |
value | The checkpoint itself, as a JsonElement. |
parent | The optional parent checkpoint information. If specified, the new checkpoint will be linked as a child of this parent. |
RetrieveCheckpointAsync | Asynchronously retrieves a checkpoint object associated with the specified session and checkpoint key. |
key | The key identifying the specific checkpoint to retrieve. Cannot be null. |
RetrieveIndexAsync | Asynchronously retrieves the collection of checkpoint information for the specified session identifier, optionally filtered by a parent checkpoint. |
withParent | An optional parent checkpoint to filter the results. If specified, only checkpoints with the given parent are returned; otherwise, all checkpoints for the session are included. |
CheckpointManager.CreateJson(new <StoreName>()) | Creates a checkpoint manager that keeps its checkpoints in your store. Pass <checkpointManager> to InProcessExecution.RunAsync and ResumeAsync. |
The reference declares all three methods abstract, so your store has to override every one of them, with exactly these parameters and return types.
The Example
A console app called LoggedCheckpoints has a store of its own, ConsoleCheckpointStore. It keeps each session's checkpoints in a list in memory and prints a line whenever Agent Framework calls it. The workflow asks whether order 15 ships today: DescribeOrder turns the order number into the question Ship order 15 today?, a request port called AskWarehouse sends that question out of the workflow and waits for a yes or a no, and RecordAnswer turns the answer into Order ships today. or Order waits. The app runs the workflow until it stops at the question, asks the checkpoint manager for the latest checkpoint, resumes from it and answers yes. Because the store keeps everything in memory, its checkpoints are gone when the app stops, so it all happens in one run of the app. There's no AI model in it, so you don't need an Azure account.
Prerequisites
- The .NET 10 SDK.
dotnet --versionprints a version that starts with10.0.
Step 1: Create a Console App
In a terminal, in the folder where you keep your projects, create the app and move into it:
dotnet new console -o LoggedCheckpoints
cd LoggedCheckpoints
The template "Console App" was created successfully.
Processing post-creation actions...
Restoring /Users/you/source/LoggedCheckpoints/LoggedCheckpoints.csproj:
Restore succeeded.
dotnet new console creates a console app in a new LoggedCheckpoints folder, and cd moves into it. Open the folder in VS Code, or LoggedCheckpoints.csproj in Visual Studio.
Step 2: Add the Workflows Package
dotnet add package Microsoft.Agents.AI.Workflows --version 1.28.0
info : X.509 certificate chain validation will use the fallback certificate bundle at '/usr/local/share/dotnet/sdk/10.0.404/trustedroots/codesignctl.pem'.
info : X.509 certificate chain validation will use the fallback certificate bundle at '/usr/local/share/dotnet/sdk/10.0.404/trustedroots/timestampctl.pem'.
info : Adding PackageReference for package 'Microsoft.Agents.AI.Workflows' into project '/Users/you/source/LoggedCheckpoints/LoggedCheckpoints.csproj'.
info : Restoring packages for /Users/you/source/LoggedCheckpoints/LoggedCheckpoints.csproj...
info : CACHE https://api.nuget.org/v3/vulnerabilities/index.json
info : CACHE https://api.nuget.org/v3-vulnerabilities/2026.11.30.23.39.07/vulnerability.base.json
info : CACHE https://api.nuget.org/v3-vulnerabilities/2026.11.30.23.39.07/2026.12.03.05.39.24/vulnerability.update.json
info : Package 'Microsoft.Agents.AI.Workflows' is compatible with all the specified frameworks in project '/Users/you/source/LoggedCheckpoints/LoggedCheckpoints.csproj'.
info : PackageReference for package 'Microsoft.Agents.AI.Workflows' version '1.28.0' added to file '/Users/you/source/LoggedCheckpoints/LoggedCheckpoints.csproj'.
info : Generating MSBuild file /Users/you/source/LoggedCheckpoints/obj/LoggedCheckpoints.csproj.nuget.g.targets.
info : Writing assets file to disk. Path: /Users/you/source/LoggedCheckpoints/obj/project.assets.json
log : Restored /Users/you/source/LoggedCheckpoints/LoggedCheckpoints.csproj (in 885 ms).
Microsoft.Agents.AI.Workflows has everything a workflow is made of, checkpoint stores included. --version keeps you on the version this guide used. The project file now references it:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Agents.AI.Workflows" Version="1.28.0" />
</ItemGroup>
</Project>
Step 3: Create the Checkpoint Manager and Run the Workflow
Replace everything in Program.cs with:
using System.Text.Json;
using Microsoft.Agents.AI.Workflows;
using Microsoft.Agents.AI.Workflows.Checkpointing;
const string SessionId = "order-15";
var store = new ConsoleCheckpointStore();
CheckpointManager checkpointManager = CheckpointManager.CreateJson(store);
Console.WriteLine("Run the workflow:");
await using (Run run = await InProcessExecution.RunAsync(BuildWorkflow(), 15, checkpointManager, SessionId))
{
Console.WriteLine($" Status: {await run.GetStatusAsync()}");
}
- The
usinglines bring inJsonElementfromSystem.Text.Json, the workflow types, andJsonCheckpointStorefromMicrosoft.Agents.AI.Workflows.Checkpointing. SessionIdis the name of this run's session,order-15. Checkpoints belong to a session, and the app uses the same name later to find the session's latest checkpoint.new ConsoleCheckpointStore()creates the store you write in Steps 6 to 9.CheckpointManager.CreateJson(store)creates the checkpoint manager: Creates a new instance of the CheckpointManager that uses JSON serialization for checkpoint data. Every checkpoint it makes goes tostore. The workflow's messages are anint, astringand abool, none of them a type of your own, so it needs no JSON options.InProcessExecution.RunAsync(BuildWorkflow(), 15, checkpointManager, SessionId)runs the workflow on order number 15, with checkpoints on, in the sessionorder-15. The session is optional: An optional unique identifier for the session. If not provided, a new identifier will be generated. The reference adds that The workflow will run until its first halt, and here that's the question to the warehouse.run.GetStatusAsync()prints how the run stopped, andawait usingdisposes the run at the end of the block.
Step 4: Find the Latest Checkpoint, Resume and Answer
Add this at the end of the file:
Console.WriteLine("Find the latest checkpoint:");
CheckpointInfo latest = (await checkpointManager.GetLatestCheckpointAsync(SessionId))!;
Console.WriteLine("Resume from it and answer:");
await using (Run resumed = await InProcessExecution.ResumeAsync(BuildWorkflow(), latest, checkpointManager))
{
RequestInfoEvent question = resumed.OutgoingEvents.OfType<RequestInfoEvent>().Single();
await resumed.ResumeAsync([question.Request.CreateResponse(true)]);
foreach (WorkflowOutputEvent output in resumed.NewEvents.OfType<WorkflowOutputEvent>())
{
Console.WriteLine($" Output: {output.Data}");
}
}
checkpointManager.GetLatestCheckpointAsync(SessionId)asks for the session's newest checkpoint: Retrieves the most recently committed checkpoint for the specified session, or null when the session has no checkpoints. The run saved checkpoints for this session, so the!at the end tells the compiler the result isn't null. It only changes what the compiler checks: The null-forgiving operator has no effect at run time.InProcessExecution.ResumeAsync(BuildWorkflow(), latest, checkpointManager)starts a new run from that checkpoint: Resumes a non-streaming execution of the workflow from a checkpoint. It gets a newly built workflow with the same steps and ids.resumed.OutgoingEvents.OfType<RequestInfoEvent>().Single()finds the question. The checkpoint holds it as a pending request, and the resumed run emits it again as aRequestInfoEvent.question.Request.CreateResponse(true)makes the answer, yes, for that request, andresumed.ResumeAsyncsends it in: Resume execution of the workflow with the provided external responses.resumed.NewEventsholds what the workflow emitted since then: Gets all events emitted by the workflow since the last access to NewEvents. The loop prints the workflow's output.
Step 5: Build the Workflow
Add this at the end of the file:
static Workflow BuildWorkflow()
{
RequestPort askWarehouse = RequestPort.Create<string, bool>("AskWarehouse");
Func<int, string> describe = order => $"Ship order {order} today?";
Func<bool, string> record = ship => ship ? "Order ships today." : "Order waits.";
ExecutorBinding describeOrder = describe.BindAsExecutor("DescribeOrder");
ExecutorBinding recordAnswer = record.BindAsExecutor("RecordAnswer");
return new WorkflowBuilder(describeOrder)
.AddEdge(describeOrder, askWarehouse)
.AddEdge(askWarehouse, recordAnswer)
.WithOutputFrom(recordAnswer)
.Build();
}
RequestPort.Create<string, bool>("AskWarehouse")creates the request port: Creates a new RequestPort instance configured for the specified request and response types. It takes thestringquestion out of the workflow and brings aboolanswer back in.describeturns the order number into the question, andrecordturns the answer into the output.BindAsExecutormakes each function a step, with the idsDescribeOrderandRecordAnswer.- The two
AddEdgecalls put the request port between the two steps, andWithOutputFrom(recordAnswer)makes the text fromRecordAnswerthe workflow's output.
Step 6: Start the Store Class
Add this at the end of the file:
// A checkpoint store that keeps each session's checkpoints in a list, in the order they were saved,
// and writes a line for every call, so you can see when Agent Framework uses it.
internal sealed class ConsoleCheckpointStore : JsonCheckpointStore
{
private readonly Dictionary<string, List<SavedCheckpoint>> _sessions = [];
private readonly Lock _lock = new();
private static string Short(CheckpointInfo? checkpoint) => checkpoint?.CheckpointId[..8] ?? "none";
private sealed record SavedCheckpoint(CheckpointInfo Checkpoint, CheckpointInfo? Parent, JsonElement Value);
}
ConsoleCheckpointStore : JsonCheckpointStoremakes the class a checkpoint store. The project won't build yet: Steps 7, 8 and 9 add the three methods the base class declaresabstract._sessionsmaps each session's name to the list of its saved checkpoints._lockis aLockfor thelockblocks in the three methods, so two calls at once can't change_sessionstogether: Thelockstatement ensures that at most only one thread executes its body at any moment in time.Shortcuts a checkpoint ID down to its first 8 characters for the log lines, and writesnonewhen there's no checkpoint, such as a missing parent.SavedCheckpointis one saved checkpoint: itsCheckpointInfo, its parent'sCheckpointInfo, and its JSON.
Step 7: Save a Checkpoint
Add this inside the class, below the _lock field:
public override ValueTask<CheckpointInfo> CreateCheckpointAsync(
string sessionId, JsonElement value, CheckpointInfo? parent = null)
{
CheckpointInfo checkpoint = new(sessionId, Guid.NewGuid().ToString("N"));
lock (_lock)
{
if (!_sessions.TryGetValue(sessionId, out List<SavedCheckpoint>? saved))
{
saved = [];
_sessions[sessionId] = saved;
}
saved.Add(new SavedCheckpoint(checkpoint, parent, value.Clone()));
}
Console.WriteLine($" CreateCheckpointAsync: saved {Short(checkpoint)}, parent {Short(parent)}");
return ValueTask.FromResult(checkpoint);
}
new(sessionId, Guid.NewGuid().ToString("N"))makes the new checkpoint'sCheckpointInfo: Initializes a new instance of the CheckpointInfo class with the specified session and checkpoint identifiers. The store picks the checkpoint ID, here a new GUID written as 32 lowercase hexadecimal digits, and the method's result contains the CheckpointInfo object representing this stored checkpoint.TryGetValuefinds the session's list, and the first checkpoint of a session creates the list.saved.Add(...)puts the checkpoint at the end of the list, so the list keeps the order the checkpoints were saved in. It stores the parent too, andvalue.Clone()rather thanvalue, because the store keeps the JSON after the call returns:CloneGets a JsonElement that can be safely stored beyond the lifetime of the original JsonDocument.ValueTask.FromResult(checkpoint)returns theCheckpointInfoin aValueTaskthat's completed successfully with the specified result. Nothing in the method waits, so it doesn't need to beasync, and that suits thelockblock: You can't use theawaitexpression in the body of alockstatement.
Step 8: Read a Checkpoint Back
Add this inside the class, below CreateCheckpointAsync:
public override ValueTask<JsonElement> RetrieveCheckpointAsync(string sessionId, CheckpointInfo key)
{
lock (_lock)
{
SavedCheckpoint? found = _sessions.GetValueOrDefault(sessionId)?.Find(c => c.Checkpoint.Equals(key));
if (found is null)
{
throw new KeyNotFoundException($"Session {sessionId} has no checkpoint {key.CheckpointId}.");
}
Console.WriteLine($" RetrieveCheckpointAsync: read {Short(key)}");
return ValueTask.FromResult(found.Value);
}
}
_sessions.GetValueOrDefault(sessionId)?.Find(c => c.Checkpoint.Equals(key))looks through the session's list for the checkpoint saved underkey. When the session has no list,GetValueOrDefaultgivesnulland?.skips the search.c.Checkpoint.Equals(key)compares the twoCheckpointInfoobjects by value.CheckpointInfois a class that implementsIEquatable<CheckpointInfo>, which gives it anEqualsof its own. It doesn't define==, and==on a class compares references: By default, reference-type operands, excluding records, are equal if they refer to the same object. So the store usesEquals.throw new KeyNotFoundException(...)stops with a message that names the session and the checkpoint ID when there's no such checkpoint.- Otherwise the method prints a line and returns the saved JSON, which the checkpoint manager turns back into the workflow's state.
My first version of this store compared with ==. It ran, but only because Agent Framework handed back the same CheckpointInfo objects the store had created. A CheckpointInfo with the same IDs, created anywhere else, would have compared as different.
Whatever your store returns here becomes the workflow's state when it resumes. Microsoft's Checkpoints guide warns: Checkpoint storage is a trust boundary. Whether you use the built-in storage implementations or a custom one, the storage backend must be treated as trusted, private infrastructure. and Never load checkpoints from untrusted or potentially tampered sources.
Step 9: List a Session's Checkpoints, Oldest First
Add this inside the class, below RetrieveCheckpointAsync:
public override ValueTask<IEnumerable<CheckpointInfo>> RetrieveIndexAsync(
string sessionId, CheckpointInfo? withParent = null)
{
lock (_lock)
{
// Oldest first: Agent Framework takes the last one in the list as the latest.
List<CheckpointInfo> index = (_sessions.GetValueOrDefault(sessionId) ?? [])
.Where(c => withParent is null || withParent.Equals(c.Parent))
.Select(c => c.Checkpoint)
.ToList();
Console.WriteLine($" RetrieveIndexAsync: listed {index.Count} checkpoints");
return ValueTask.FromResult<IEnumerable<CheckpointInfo>>(index);
}
}
?? []starts from an empty list when the session has no checkpoints, as the reference asks: The collection is empty if no checkpoints are found.Where(c => withParent is null || withParent.Equals(c.Parent))keeps every checkpoint whenwithParentisnull, and otherwise only the checkpoints whose parent iswithParent, compared withEqualsas in Step 8. It callsEqualsonwithParent, which isn'tnullthere, rather than onc.Parent, which isnullfor a session's first checkpoint.Select(c => c.Checkpoint)keeps each checkpoint'sCheckpointInfowithout its JSON, andToList()keeps the list's order, the order the checkpoints were saved in.
That order is the part to get right. The reference of the store interface makes it a contract: Implementations must return checkpoints in the order they were committed, with the most recently committed checkpoint last. This ordering is a contract of the store: callers such as CheckpointManager rely on it to identify the latest checkpoint for a session, so a store that returns checkpoints unordered (or newest-first) will cause the wrong checkpoint to be resumed. The comment in the code says the same: oldest first, because the last one in the list counts as the latest.
Step 10: Run It
dotnet run
Run the workflow:
CreateCheckpointAsync: saved a43082a0, parent none
CreateCheckpointAsync: saved 01619678, parent a43082a0
Status: PendingRequests
Find the latest checkpoint:
RetrieveIndexAsync: listed 2 checkpoints
Resume from it and answer:
RetrieveCheckpointAsync: read 01619678
RetrieveIndexAsync: listed 2 checkpoints
CreateCheckpointAsync: saved f2627f7f, parent 01619678
CreateCheckpointAsync: saved f454e84e, parent f2627f7f
Output: Order ships today.

Your checkpoint IDs will differ, because the store makes a new GUID for each checkpoint. Read the log from the top:
- The run saved 2 checkpoints. Checkpoints are created at the end of each superstep, after all executors in that superstep have completed their execution. The run went through two supersteps before it stopped at the question. The first checkpoint has no parent, and the second one's parent is the first. Then the run stopped with
PendingRequests: The run has halted, and has at least one outstanding ExternalRequest. - Finding the latest checkpoint listed the index.
GetLatestCheckpointAsynccalledRetrieveIndexAsync, which listed the session's 2 checkpoints, oldest first. The latest is the last one in that list,01619678, and that's the checkpoint the resume read next. - Resuming read the checkpoint, then listed the index again.
ResumeAsynccalledRetrieveCheckpointAsyncfor01619678, thenRetrieveIndexAsynconce more. Each listing returned both checkpoints, sowithParentwasnulleach time: with a parent to filter by, the list would have been shorter. - The answer led to 2 more checkpoints. The run carried on with the answer to the output,
Order ships today., and the store saved 2 more checkpoints on the way. The first new checkpoint's parent is01619678, the checkpoint the run resumed from, and the second one's parent is the first new one. Each checkpoint names the one before it, and a resumed run carries on from the checkpoint it resumed from.
The Complete File
using System.Text.Json;
using Microsoft.Agents.AI.Workflows;
using Microsoft.Agents.AI.Workflows.Checkpointing;
const string SessionId = "order-15";
var store = new ConsoleCheckpointStore();
CheckpointManager checkpointManager = CheckpointManager.CreateJson(store);
Console.WriteLine("Run the workflow:");
await using (Run run = await InProcessExecution.RunAsync(BuildWorkflow(), 15, checkpointManager, SessionId))
{
Console.WriteLine($" Status: {await run.GetStatusAsync()}");
}
Console.WriteLine("Find the latest checkpoint:");
CheckpointInfo latest = (await checkpointManager.GetLatestCheckpointAsync(SessionId))!;
Console.WriteLine("Resume from it and answer:");
await using (Run resumed = await InProcessExecution.ResumeAsync(BuildWorkflow(), latest, checkpointManager))
{
RequestInfoEvent question = resumed.OutgoingEvents.OfType<RequestInfoEvent>().Single();
await resumed.ResumeAsync([question.Request.CreateResponse(true)]);
foreach (WorkflowOutputEvent output in resumed.NewEvents.OfType<WorkflowOutputEvent>())
{
Console.WriteLine($" Output: {output.Data}");
}
}
static Workflow BuildWorkflow()
{
RequestPort askWarehouse = RequestPort.Create<string, bool>("AskWarehouse");
Func<int, string> describe = order => $"Ship order {order} today?";
Func<bool, string> record = ship => ship ? "Order ships today." : "Order waits.";
ExecutorBinding describeOrder = describe.BindAsExecutor("DescribeOrder");
ExecutorBinding recordAnswer = record.BindAsExecutor("RecordAnswer");
return new WorkflowBuilder(describeOrder)
.AddEdge(describeOrder, askWarehouse)
.AddEdge(askWarehouse, recordAnswer)
.WithOutputFrom(recordAnswer)
.Build();
}
// A checkpoint store that keeps each session's checkpoints in a list, in the order they were saved,
// and writes a line for every call, so you can see when Agent Framework uses it.
internal sealed class ConsoleCheckpointStore : JsonCheckpointStore
{
private readonly Dictionary<string, List<SavedCheckpoint>> _sessions = [];
private readonly Lock _lock = new();
public override ValueTask<CheckpointInfo> CreateCheckpointAsync(
string sessionId, JsonElement value, CheckpointInfo? parent = null)
{
CheckpointInfo checkpoint = new(sessionId, Guid.NewGuid().ToString("N"));
lock (_lock)
{
if (!_sessions.TryGetValue(sessionId, out List<SavedCheckpoint>? saved))
{
saved = [];
_sessions[sessionId] = saved;
}
saved.Add(new SavedCheckpoint(checkpoint, parent, value.Clone()));
}
Console.WriteLine($" CreateCheckpointAsync: saved {Short(checkpoint)}, parent {Short(parent)}");
return ValueTask.FromResult(checkpoint);
}
public override ValueTask<JsonElement> RetrieveCheckpointAsync(string sessionId, CheckpointInfo key)
{
lock (_lock)
{
SavedCheckpoint? found = _sessions.GetValueOrDefault(sessionId)?.Find(c => c.Checkpoint.Equals(key));
if (found is null)
{
throw new KeyNotFoundException($"Session {sessionId} has no checkpoint {key.CheckpointId}.");
}
Console.WriteLine($" RetrieveCheckpointAsync: read {Short(key)}");
return ValueTask.FromResult(found.Value);
}
}
public override ValueTask<IEnumerable<CheckpointInfo>> RetrieveIndexAsync(
string sessionId, CheckpointInfo? withParent = null)
{
lock (_lock)
{
// Oldest first: Agent Framework takes the last one in the list as the latest.
List<CheckpointInfo> index = (_sessions.GetValueOrDefault(sessionId) ?? [])
.Where(c => withParent is null || withParent.Equals(c.Parent))
.Select(c => c.Checkpoint)
.ToList();
Console.WriteLine($" RetrieveIndexAsync: listed {index.Count} checkpoints");
return ValueTask.FromResult<IEnumerable<CheckpointInfo>>(index);
}
}
private static string Short(CheckpointInfo? checkpoint) => checkpoint?.CheckpointId[..8] ?? "none";
private sealed record SavedCheckpoint(CheckpointInfo Checkpoint, CheckpointInfo? Parent, JsonElement Value);
}
The part of the file that makes it a checkpoint store is the ConsoleCheckpointStore class:

The project file is the one from Step 2, unchanged.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
| Returning the index newest first, or in no fixed order | The checkpoint manager takes the last checkpoint in the list as the latest, so the wrong checkpoint is resumed | Return a session's checkpoints in the order they were saved, the most recent last |
Ignoring withParent | A call that asks for the children of one checkpoint gets every checkpoint of the session | When withParent isn't null, return only the checkpoints whose parent it is |
Comparing CheckpointInfo objects with == | == compares references, so a CheckpointInfo with the same IDs that was created anywhere else doesn't match, and the store can't find its checkpoint | Compare with Equals |
Saving value without Clone() | If the JsonElement belongs to a JsonDocument that's disposed later, the saved checkpoint can't be read any more | Save value.Clone() |
| Keeping the checkpoints only in memory, as this example does | They're gone when the app stops, so there's nothing to resume after a restart | Keep them in storage that outlives the app, such as files with FileSystemJsonCheckpointStore |
| Letting other services or people read or write the store | Anyone who can change a checkpoint can change the state a workflow resumes with | Only authorized services and users should have read or write access to checkpoint data. |
FAQ
Which checkpoint counts as the latest?
The last one in the list your store's RetrieveIndexAsync returns. The reference of GetLatestCheckpointAsync says it Retrieves the most recently committed checkpoint for the specified session, or null when the session has no checkpoints. The run above shows how it finds that one: it listed the session's 2 checkpoints, and the resume read the second one saved, 01619678.
Who picks a checkpoint's ID?
Your store. CreateCheckpointAsync returns the CheckpointInfo of the checkpoint it saved, which holds the session's name in SessionId and the checkpoint's own ID in CheckpointId. The example uses a new GUID for each one.
Can a store wait for a database or a file?
The three methods return a ValueTask, so they can be async methods that wait. The example's lock can't stay around such a wait, though, and Microsoft's guide on async coordination explains why: The C# lock statement and Lock (.NET 9+) don't work across await boundaries because they're thread-affine. For code that waits, it suggests: Use SemaphoreSlim with a count of 1 instead.
Can I resume from this store after the app restarts?
No. It keeps everything in memory, so its checkpoints end with the app. To resume after a restart, keep the checkpoints in storage that outlives the app, such as the JSON files of FileSystemJsonCheckpointStore in How to Resume a Microsoft Agent Framework Workflow from a Checkpoint After a Restart in C#.
Conclusion
A checkpoint store is a class that derives from JsonCheckpointStore and overrides CreateCheckpointAsync, RetrieveCheckpointAsync and RetrieveIndexAsync. The logging store showed when Agent Framework calls each one: it saves a checkpoint at the end of every superstep, with the previous checkpoint as its parent, lists the index to find the latest checkpoint, and reads a checkpoint back to resume. Return the index oldest first, compare checkpoints with Equals, clone the JSON you keep, and keep the storage private, because every checkpoint you load becomes a workflow's state.
Additional Resources
- Checkpoints — when checkpoints are created, resuming from one, and the security note on checkpoint storage.
- JsonCheckpointStore class — the base class and its three abstract methods.
- ICheckpointStore interface — the interface every checkpoint store implements.
- CheckpointInfo class — the session ID and checkpoint ID a store returns.
- JsonElement.Clone — why the store keeps a clone of each checkpoint's JSON.
- The lock statement — how the store lets one call at a time change its lists.
- Equality operators — why
==on a class compares references unless the class defines its own==.
