Skip to main content

How to Write a Custom Checkpoint Store for Microsoft Agent Framework Workflows in C#

· 21 min read
Jagdish Kumawat
Founder @ Dewiride

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​

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>());
PartWhat it is
<StoreName>Your store's class.
JsonCheckpointStoreThe base class, in the Microsoft.Agents.AI.Workflows.Checkpointing namespace: An abstract base class for checkpoint stores that use JSON for serialization.
CreateCheckpointAsyncAsynchronously 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.
sessionIdThe session the checkpoint belongs to. All three methods get it.
valueThe checkpoint itself, as a JsonElement.
parentThe optional parent checkpoint information. If specified, the new checkpoint will be linked as a child of this parent.
RetrieveCheckpointAsyncAsynchronously retrieves a checkpoint object associated with the specified session and checkpoint key.
keyThe key identifying the specific checkpoint to retrieve. Cannot be null.
RetrieveIndexAsyncAsynchronously retrieves the collection of checkpoint information for the specified session identifier, optionally filtered by a parent checkpoint.
withParentAn 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 --version prints a version that starts with 10.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:

Terminal
dotnet new console -o LoggedCheckpoints
cd LoggedCheckpoints
Output (first command)
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​

Terminal
dotnet add package Microsoft.Agents.AI.Workflows --version 1.28.0
Output
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:

LoggedCheckpoints.csproj
<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:

Program.cs
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 using lines bring in JsonElement from System.Text.Json, the workflow types, and JsonCheckpointStore from Microsoft.Agents.AI.Workflows.Checkpointing.
  • SessionId is 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 to store. The workflow's messages are an int, a string and a bool, 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 session order-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, and await using disposes 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:

Program.cs (add at the end)
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 a RequestInfoEvent.
  • question.Request.CreateResponse(true) makes the answer, yes, for that request, and resumed.ResumeAsync sends it in: Resume execution of the workflow with the provided external responses.
  • resumed.NewEvents holds 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:

Program.cs (add at the end)
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 the string question out of the workflow and brings a bool answer back in.
  • describe turns the order number into the question, and record turns the answer into the output. BindAsExecutor makes each function a step, with the ids DescribeOrder and RecordAnswer.
  • The two AddEdge calls put the request port between the two steps, and WithOutputFrom(recordAnswer) makes the text from RecordAnswer the workflow's output.

Step 6: Start the Store Class​

Add this at the end of the file:

Program.cs (add at the end)
// 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 : JsonCheckpointStore makes the class a checkpoint store. The project won't build yet: Steps 7, 8 and 9 add the three methods the base class declares abstract.
  • _sessions maps each session's name to the list of its saved checkpoints.
  • _lock is a Lock for the lock blocks in the three methods, so two calls at once can't change _sessions together: The lock statement ensures that at most only one thread executes its body at any moment in time.
  • Short cuts a checkpoint ID down to its first 8 characters for the log lines, and writes none when there's no checkpoint, such as a missing parent.
  • SavedCheckpoint is one saved checkpoint: its CheckpointInfo, its parent's CheckpointInfo, and its JSON.

Step 7: Save a Checkpoint​

Add this inside the class, below the _lock field:

Program.cs (inside ConsoleCheckpointStore)
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's CheckpointInfo: 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.
  • TryGetValue finds 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, and value.Clone() rather than value, because the store keeps the JSON after the call returns: Clone Gets a JsonElement that can be safely stored beyond the lifetime of the original JsonDocument.
  • ValueTask.FromResult(checkpoint) returns the CheckpointInfo in a ValueTask that's completed successfully with the specified result. Nothing in the method waits, so it doesn't need to be async, and that suits the lock block: You can't use the await expression in the body of a lock statement.

Step 8: Read a Checkpoint Back​

Add this inside the class, below CreateCheckpointAsync:

Program.cs (inside ConsoleCheckpointStore)
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 under key. When the session has no list, GetValueOrDefault gives null and ?. skips the search.
  • c.Checkpoint.Equals(key) compares the two CheckpointInfo objects by value. CheckpointInfo is a class that implements IEquatable<CheckpointInfo>, which gives it an Equals of 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 uses Equals.
  • 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.

warning

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:

Program.cs (inside ConsoleCheckpointStore)
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 when withParent is null, and otherwise only the checkpoints whose parent is withParent, compared with Equals as in Step 8. It calls Equals on withParent, which isn't null there, rather than on c.Parent, which is null for a session's first checkpoint.
  • Select(c => c.Checkpoint) keeps each checkpoint's CheckpointInfo without its JSON, and ToList() 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​

Terminal
dotnet run
Output
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.

macOS-style terminal window titled Terminal — LoggedCheckpoints showing dotnet run: two CreateCheckpointAsync lines and Status: PendingRequests while the workflow runs, one RetrieveIndexAsync line listing 2 checkpoints to find the latest, then RetrieveCheckpointAsync reading 01619678, another RetrieveIndexAsync, two more CreateCheckpointAsync lines and the 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. GetLatestCheckpointAsync called RetrieveIndexAsync, 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. ResumeAsync called RetrieveCheckpointAsync for 01619678, then RetrieveIndexAsync once more. Each listing returned both checkpoints, so withParent was null each 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 is 01619678, 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​

Program.cs
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:

macOS-style code window titled Program.cs — LoggedCheckpoints showing the ConsoleCheckpointStore class, which derives from JsonCheckpointStore and keeps each session's checkpoints in a list in memory: CreateCheckpointAsync saves a checkpoint under a new GUID with its parent and a clone of its JSON, RetrieveCheckpointAsync finds a checkpoint with Equals and returns its JSON, and RetrieveIndexAsync lists a session's checkpoints oldest first, keeping only the children of withParent, compared with Equals, when one is given

The project file is the one from Step 2, unchanged.

Common Mistakes​

MistakeWhat happensDo this instead
Returning the index newest first, or in no fixed orderThe checkpoint manager takes the last checkpoint in the list as the latest, so the wrong checkpoint is resumedReturn a session's checkpoints in the order they were saved, the most recent last
Ignoring withParentA call that asks for the children of one checkpoint gets every checkpoint of the sessionWhen 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 checkpointCompare 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 moreSave value.Clone()
Keeping the checkpoints only in memory, as this example doesThey're gone when the app stops, so there's nothing to resume after a restartKeep them in storage that outlives the app, such as files with FileSystemJsonCheckpointStore
Letting other services or people read or write the storeAnyone who can change a checkpoint can change the state a workflow resumes withOnly 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​