Skip to main content

How to Save Your Own Types in Microsoft Agent Framework Workflow Checkpoints in C#

· 18 min read
Jagdish Kumawat
Founder @ Dewiride

When a Microsoft Agent Framework workflow saves its checkpoints as JSON, each checkpoint holds the messages on their way between steps, including messages of types you wrote yourself. CheckpointManager.CreateJson takes JSON options for those types, and a JsonSerializerContext supplies them. Here's one small workflow run three ways: as a new console app runs it, with reflection-based JSON turned off, and with a context.

Microsoft's Checkpoints guide says what a checkpoint saves: A checkpoint captures the entire state of the workflow, and that includes All pending messages in the workflow for the next superstep. When a step sends a message of your own type, a checkpoint manager made with CreateJson has to write it as JSON, and read it back when a run resumes.

Syntax​

Syntax
CheckpointManager <checkpointManager> = CheckpointManager.CreateJson(<store>, <ContextName>.Default.Options);

[JsonSerializable(typeof(<YourType>))]
internal sealed partial class <ContextName> : JsonSerializerContext;
PartWhat it is
CheckpointManager.CreateJsonCreates a new instance of the CheckpointManager that uses JSON serialization for checkpoint data.
<checkpointManager>Your variable. Pass it to InProcessExecution.RunAsync and ResumeAsync.
<store>Where the checkpoints are kept: The checkpoint store to use for persisting and retrieving checkpoint data as JSON elements. Cannot be null.
<ContextName>.Default.OptionsThe customOptions argument, documented as Optional custom JSON serializer options to use for serialization and deserialization. Must be provided if using custom types in messages or state. Default is an instance of the context type with default options, and Options are its JSON options.
[JsonSerializable(typeof(<YourType>))]Asks the System.Text.Json source generator for the JSON code of <YourType>. Add one for each type of your own.
<ContextName>Your context class. Microsoft's first step: Create a partial class that derives from JsonSerializerContext. partial lets the generator write the rest of it when you build.

The documentation says must. Step 7 shows a console app that gets by without a context anyway, and Step 9 shows where that stops.

The Example​

A console app called TicketCheckpoints runs a workflow of two steps. OpenTicket turns a title into a Ticket, a record of the app's own with a title and a priority, and sends it to DescribeTicket, which turns it back into text. The run saves its checkpoints in files, and the first checkpoint holds the Ticket on its way to DescribeTicket. The app then resumes from that checkpoint, which reads the Ticket back from JSON. It runs three times: as a new console app is set up, with reflection-based JSON turned off, and with a JSON context. 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 TicketCheckpoints
cd TicketCheckpoints
Output (first command)
The template "Console App" was created successfully.

Processing post-creation actions...
Restoring /Users/you/source/TicketCheckpoints/TicketCheckpoints.csproj:
Restore succeeded.

dotnet new console creates a console app in a new TicketCheckpoints folder, and cd moves into it. Open the folder in VS Code, or TicketCheckpoints.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/TicketCheckpoints/TicketCheckpoints.csproj'.
info : Restoring packages for /Users/you/source/TicketCheckpoints/TicketCheckpoints.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/TicketCheckpoints/TicketCheckpoints.csproj'.
info : PackageReference for package 'Microsoft.Agents.AI.Workflows' version '1.28.0' added to file '/Users/you/source/TicketCheckpoints/TicketCheckpoints.csproj'.
info : Generating MSBuild file /Users/you/source/TicketCheckpoints/obj/TicketCheckpoints.csproj.nuget.g.targets.
info : Writing assets file to disk. Path: /Users/you/source/TicketCheckpoints/obj/project.assets.json
log : Restored /Users/you/source/TicketCheckpoints/TicketCheckpoints.csproj (in 936 ms).

Microsoft.Agents.AI.Workflows has everything a workflow is made of, checkpoints included. --version keeps you on the version this guide used. The project file now references it:

TicketCheckpoints.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 a Checkpoint Manager That Writes JSON Files​

Replace everything in Program.cs with:

Program.cs
using System.Text.Json;
using Microsoft.Agents.AI.Workflows;
using Microsoft.Agents.AI.Workflows.Checkpointing;

Console.WriteLine($"Reflection-based serialization: {(JsonSerializer.IsReflectionEnabledByDefault ? "on" : "off")}");

using var store = new FileSystemJsonCheckpointStore(new DirectoryInfo("checkpoints"));
CheckpointManager checkpointManager = CheckpointManager.CreateJson(store);
  • JsonSerializer.IsReflectionEnabledByDefault says whether System.Text.Json may use reflection, which works out how to write a type while the app runs: Gets a value that indicates whether unconfigured JsonSerializerOptions instances should default to the reflection-based DefaultJsonTypeInfoResolver. The app prints it first, because Step 8 turns it off.
  • FileSystemJsonCheckpointStore is the store, documented as a file system-based implementation of a JSON checkpoint store that persists checkpoint data and index information to disk using JSON files. It writes them to a checkpoints folder in the project folder, where you run the app. Its documentation adds that callers should ensure Dispose is called to release file handles and system resources when the store is no longer needed, which using does when the app ends.
  • CheckpointManager.CreateJson(store) creates the checkpoint manager, which writes each checkpoint as JSON into the store. It gets no JSON options yet: Step 10 adds them.

Step 4: Run the Workflow and Resume from Its First Checkpoint​

Add this at the end of the file:

Program.cs (add at the end)
await using Run run = await InProcessExecution.RunAsync(BuildWorkflow(), "Printer jams on page 2", checkpointManager);
PrintEvents(run.OutgoingEvents);
Console.WriteLine($"Status: {await run.GetStatusAsync()}, checkpoints saved: {run.Checkpoints.Count}");

if (run.Checkpoints.Count > 0)
{
// The first checkpoint holds the Ticket on its way to DescribeTicket. Resuming from it reads the Ticket back.
await using Run resumed = await InProcessExecution.ResumeAsync(BuildWorkflow(), run.Checkpoints[0], checkpointManager);
Console.WriteLine("Resumed from the first checkpoint:");
PrintEvents(resumed.OutgoingEvents);
}
  • InProcessExecution.RunAsync(BuildWorkflow(), "Printer jams on page 2", checkpointManager) runs the workflow on the title Printer jams on page 2, and the checkpoint manager turns checkpoints on. Microsoft's Checkpoints guide: Checkpoints are created at the end of each superstep, after all executors in that superstep have completed their execution. A superstep is one round of the run, and in this workflow each step runs in a round of its own.
  • run.GetStatusAsync() and run.Checkpoints.Count tell how the run ended and how many checkpoints it saved.
  • InProcessExecution.ResumeAsync(BuildWorkflow(), run.Checkpoints[0], checkpointManager) runs the workflow again from the first checkpoint: Resumes a non-streaming execution of the workflow from a checkpoint. It gets a newly built workflow, and the guide says what that one must keep: A rehydrated workflow must preserve the topology and executor identities of the workflow that created the checkpoint. BuildWorkflow builds the same steps with the same ids every time.
  • Resuming makes the checkpoint manager read the Ticket back from the checkpoint's JSON, so the app checks both directions: writing a Ticket and reading it.

Step 5: Print the Output or the Error​

Add this at the end of the file:

Program.cs (add at the end)
static void PrintEvents(IEnumerable<WorkflowEvent> events)
{
foreach (WorkflowEvent workflowEvent in events)
{
if (workflowEvent is WorkflowOutputEvent output)
{
Console.WriteLine($"Output: {output.Data}");
}
else if (workflowEvent is WorkflowErrorEvent error)
{
Console.WriteLine($"The run failed: {error.Exception?.GetType().Name}: {error.Exception?.Message}");
}
}
}
  • PrintEvents is a local function that the code above calls twice: for the run, and for the resumed run.
  • WorkflowOutputEvent carries the workflow's output, and the method prints its data.
  • WorkflowErrorEvent is documented as Event triggered when a workflow encounters an error. Its Exception holds what went wrong, and the method prints the exception's type and message.

Step 6: Build the Workflow and Its Own Type​

Add this at the end of the file:

Program.cs (add at the end)
static Workflow BuildWorkflow()
{
Func<string, Ticket> open = title => new Ticket(title, Priority: 2);
Func<Ticket, string> describe = ticket => $"{ticket.Title} (priority {ticket.Priority})";

ExecutorBinding openTicket = open.BindAsExecutor("OpenTicket");
ExecutorBinding describeTicket = describe.BindAsExecutor("DescribeTicket");

return new WorkflowBuilder(openTicket)
.AddEdge(openTicket, describeTicket)
.WithOutputFrom(describeTicket)
.Build();
}

// The app's own type: OpenTicket sends it to DescribeTicket.
public sealed record Ticket(string Title, int Priority);
  • open turns a title into a Ticket with priority 2, and describe turns a Ticket into text such as Printer jams on page 2 (priority 2).
  • BindAsExecutor makes each function a workflow step: Configures a function-based message handler as an executor with the specified identifier and options. The ids, OpenTicket and DescribeTicket, are how checkpoints name the steps.
  • AddEdge(openTicket, describeTicket) sends the Ticket from one step to the other, and WithOutputFrom(describeTicket) makes the text the workflow's output.
  • public sealed record Ticket(string Title, int Priority); is the app's own type, a record with a Title and a Priority. Between the two steps, a Ticket is a message waiting for DescribeTicket, and that's what the first checkpoint has to save.

Step 7: Run It​

Terminal
dotnet run
Output
Reflection-based serialization: on
Output: Printer jams on page 2 (priority 2)
Status: Idle, checkpoints saved: 2
Resumed from the first checkpoint:
Output: Printer jams on page 2 (priority 2)

macOS-style terminal window titled Terminal — TicketCheckpoints showing dotnet run printing Reflection-based serialization: on, the output Printer jams on page 2 (priority 2), Status: Idle with 2 checkpoints saved, and the same output again after resuming from the first checkpoint

Reflection is on, as it is in a new console app: the setting defaults to true if unset. The run printed its output and stopped Idle: it halted with no requests left to answer. It saved 2 checkpoints, one at the end of each superstep. Resuming from the first one printed the same output again, so the Ticket was written to JSON and read back, all without a JSON context.

The store wrote its JSON files to the checkpoints folder. In the first checkpoint, the one whose stepNumber is 0, this is the part that holds the Ticket:

Part of the first checkpoint
"queuedMessages": {
"DescribeTicket": [
{
"messageType": {
"assemblyName": "TicketCheckpoints, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null",
"typeName": "Ticket"
},
"message": {
"typeId": {
"assemblyName": "TicketCheckpoints, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null",
"typeName": "Ticket"
},
"value": {
"title": "Printer jams on page 2",
"priority": 2
}
},
"source": {
"id": "OpenTicket"
}
}
]
}

queuedMessages holds the messages waiting for the next superstep, here one for DescribeTicket from OpenTicket. It records the message's type, Ticket from the app's own assembly, TicketCheckpoints, and its value: the title and the priority. Writing that value, and reading it back, is the job of the checkpoint manager's JSON options.

Step 8: Turn Off Reflection-Based JSON​

A console app has reflection-based JSON on, but not every app does. Microsoft's source generation guide: If you don't specify this property and PublishTrimmed is enabled, reflection-based serialization is automatically disabled. Native AOT apps can't rely on it either: calling a basic serialization method can break Native AOT apps, which doesn't support all required reflection APIs. The same guide suggests turning reflection off yourself, because then breaks are easier to diagnose. Do that here. In TicketCheckpoints.csproj, add this line to the PropertyGroup:

TicketCheckpoints.csproj (add to the PropertyGroup)
<JsonSerializerIsReflectionEnabledByDefault>false</JsonSerializerIsReflectionEnabledByDefault>

JsonSerializerIsReflectionEnabledByDefault set to false turns reflection-based JSON off for the whole app, as a trimmed app has it. The project file now reads:

TicketCheckpoints.csproj
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<JsonSerializerIsReflectionEnabledByDefault>false</JsonSerializerIsReflectionEnabledByDefault>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Agents.AI.Workflows" Version="1.28.0" />
</ItemGroup>

</Project>

Step 9: Run It Again​

Terminal
dotnet run
Output
Reflection-based serialization: off
The run failed: InvalidOperationException: No JSON type info is available for type 'Ticket'.
Status: Ended, checkpoints saved: 0

macOS-style terminal window titled Terminal — TicketCheckpoints showing dotnet run printing Reflection-based serialization: off, then The run failed: InvalidOperationException: No JSON type info is available for type 'Ticket', and Status: Ended with 0 checkpoints saved

Nothing in Program.cs changed, and the run failed. With reflection off, the checkpoint manager's JSON options had no code for writing a Ticket, and the error names that type. There's no output, the run Ended, and it saved no checkpoints, so the app had nothing to resume from. Not even the first checkpoint was saved: that's the one that has to write the Ticket, at the end of the first superstep, and DescribeTicket never printed its output.

This is the case the documentation of CreateJson warns about: the JSON options Must be provided if using custom types in messages or state.

Step 10: Give the Checkpoint Manager a JSON Context​

Three changes in Program.cs. Add a using line below using System.Text.Json;:

Program.cs (below using System.Text.Json;)
using System.Text.Json.Serialization;

Replace the CreateJson line with these two lines:

Program.cs (in place of the CreateJson line)
// TicketJsonContext gives the checkpoint manager the JSON code for this app's own types.
CheckpointManager checkpointManager = CheckpointManager.CreateJson(store, TicketJsonContext.Default.Options);

And add the context at the end of the file:

Program.cs (add at the end)
// The source generator writes the JSON code for every type listed here when you build.
[JsonSerializable(typeof(Ticket))]
internal sealed partial class TicketJsonContext : JsonSerializerContext;
  • System.Text.Json.Serialization is the namespace of JsonSerializable and JsonSerializerContext.
  • [JsonSerializable(typeof(Ticket))] asks the source generator for the JSON code of Ticket. The generator runs while the project builds, so that code is part of the app before it starts, and it needs no reflection.
  • internal sealed partial class TicketJsonContext : JsonSerializerContext; declares the context. partial lets the generator write its members.
  • TicketJsonContext.Default.Options are the JSON options of the context, the run-time specified options of the context. Passed to CreateJson, they're what the checkpoint manager now uses to write and read a Ticket.

Step 11: Run It with the Context​

Terminal
dotnet run
Output
Reflection-based serialization: off
Output: Printer jams on page 2 (priority 2)
Status: Idle, checkpoints saved: 2
Resumed from the first checkpoint:
Output: Printer jams on page 2 (priority 2)

macOS-style terminal window titled Terminal — TicketCheckpoints showing dotnet run with reflection-based serialization off printing the output Printer jams on page 2 (priority 2), Status: Idle with 2 checkpoints saved, and the same output again after resuming from the first checkpoint

Reflection is still off, and everything works again: the output, 2 checkpoints, and the resume, which read the Ticket back. The JSON code for Ticket now comes from the context, built with the app, so the checkpoints no longer depend on reflection.

The Complete File​

Program.cs
using System.Text.Json;
using System.Text.Json.Serialization;
using Microsoft.Agents.AI.Workflows;
using Microsoft.Agents.AI.Workflows.Checkpointing;

Console.WriteLine($"Reflection-based serialization: {(JsonSerializer.IsReflectionEnabledByDefault ? "on" : "off")}");

using var store = new FileSystemJsonCheckpointStore(new DirectoryInfo("checkpoints"));
// TicketJsonContext gives the checkpoint manager the JSON code for this app's own types.
CheckpointManager checkpointManager = CheckpointManager.CreateJson(store, TicketJsonContext.Default.Options);

await using Run run = await InProcessExecution.RunAsync(BuildWorkflow(), "Printer jams on page 2", checkpointManager);
PrintEvents(run.OutgoingEvents);
Console.WriteLine($"Status: {await run.GetStatusAsync()}, checkpoints saved: {run.Checkpoints.Count}");

if (run.Checkpoints.Count > 0)
{
// The first checkpoint holds the Ticket on its way to DescribeTicket. Resuming from it reads the Ticket back.
await using Run resumed = await InProcessExecution.ResumeAsync(BuildWorkflow(), run.Checkpoints[0], checkpointManager);
Console.WriteLine("Resumed from the first checkpoint:");
PrintEvents(resumed.OutgoingEvents);
}

static void PrintEvents(IEnumerable<WorkflowEvent> events)
{
foreach (WorkflowEvent workflowEvent in events)
{
if (workflowEvent is WorkflowOutputEvent output)
{
Console.WriteLine($"Output: {output.Data}");
}
else if (workflowEvent is WorkflowErrorEvent error)
{
Console.WriteLine($"The run failed: {error.Exception?.GetType().Name}: {error.Exception?.Message}");
}
}
}

static Workflow BuildWorkflow()
{
Func<string, Ticket> open = title => new Ticket(title, Priority: 2);
Func<Ticket, string> describe = ticket => $"{ticket.Title} (priority {ticket.Priority})";

ExecutorBinding openTicket = open.BindAsExecutor("OpenTicket");
ExecutorBinding describeTicket = describe.BindAsExecutor("DescribeTicket");

return new WorkflowBuilder(openTicket)
.AddEdge(openTicket, describeTicket)
.WithOutputFrom(describeTicket)
.Build();
}

// The app's own type: OpenTicket sends it to DescribeTicket.
public sealed record Ticket(string Title, int Priority);

// The source generator writes the JSON code for every type listed here when you build.
[JsonSerializable(typeof(Ticket))]
internal sealed partial class TicketJsonContext : JsonSerializerContext;

macOS-style code window titled Program.cs — TicketCheckpoints showing a FileSystemJsonCheckpointStore and a CheckpointManager created with CreateJson and TicketJsonContext.Default.Options, a run of the workflow on Printer jams on page 2 that resumes from its first checkpoint, a PrintEvents function for outputs and errors, a BuildWorkflow function with the OpenTicket and DescribeTicket steps, the Ticket record, and the TicketJsonContext class marked JsonSerializable for Ticket

The project file keeps reflection-based JSON off, so a type you forget to list fails while you develop, and not only in a trimmed build:

TicketCheckpoints.csproj
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<JsonSerializerIsReflectionEnabledByDefault>false</JsonSerializerIsReflectionEnabledByDefault>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Agents.AI.Workflows" Version="1.28.0" />
</ItemGroup>

</Project>

Common Mistakes​

MistakeWhat happensDo this instead
Leaving the context out because the app works without itIt works only while reflection-based JSON is on. With it off, as in a trimmed app, the run fails with No JSON type info is available for type 'Ticket'. and saves no checkpointsPass a context's options to CreateJson from the start
Testing only with reflection onA type you forgot to list fails only later, in a trimmed or Native AOT buildSet JsonSerializerIsReflectionEnabledByDefault to false while you develop
Listing only the types that travel in messagesA type of your own kept in the workflow's state goes into the checkpoint tooAdd [JsonSerializable] for every type of your own in messages or in the state

FAQ​

Why did the first run work without a context?​

Because reflection-based JSON was on. Microsoft's comparison of the two approaches: By default, JsonSerializer collects metadata at runtime by using reflection. With reflection, System.Text.Json works out how to write a Ticket the first time it meets one. With reflection off, only types whose JSON code was generated when the app was built can be written, and the context is what generates it.

Do the types of my type's properties need their own attribute?​

No, with one exception. Microsoft's source generation guide says the types of a listed type's members don't need [JsonSerializable] attributes of their own, except members declared as object, whose types at run time have to be listed.

What else does a checkpoint hold?​

The Checkpoints guide lists the current state of all executors, all pending messages for the next superstep, pending requests and responses, and shared states. A type of your own in any of them goes through the same JSON options.

Conclusion​

A checkpoint saves the messages between a workflow's steps as JSON, and with them every type of your own. Give CheckpointManager.CreateJson the options of a JsonSerializerContext that lists those types with [JsonSerializable]. A console app with reflection-based JSON on gets by without one, but a trimmed app, or one that turns reflection off, fails as this run did, with No JSON type info is available for type 'Ticket'., and saves no checkpoints.

Additional Resources​