How to Resume a Microsoft Agent Framework Workflow from the Checkpoint Where It Waits for an Answer in C#
When a step fails after someone has answered a Microsoft Agent Framework workflow, the answer has to go in again, and the session's latest checkpoint is the wrong place to give it: nothing waits there any more. Keep the checkpoint where the run waits for its answer, and resume from that one as often as you need. This guide shows both in a C# article review whose publish step fails on the first try.
Syntax
// When the run stops at its question: keep the checkpoint where it waits.
CheckpointInfo <waiting> = <run>.LastCheckpoint!;
// Its two IDs, to keep where your app keeps its data.
string <sessionId> = <waiting>.SessionId;
string <checkpointId> = <waiting>.CheckpointId;
// Later, even in a new process: the same CheckpointInfo, from the two IDs.
CheckpointInfo <checkpoint> = new CheckpointInfo(<sessionId>, <checkpointId>);
// Answer from it, as many times as you need.
await using Run <resumed> = await InProcessExecution.ResumeAsync(<workflow>, <checkpoint>, <checkpointManager>);
| Part | What it is |
|---|---|
<run>.LastCheckpoint | Gets the most recent checkpoint information. Read it when the run has stopped at its question: the most recent checkpoint is then the one where the run waits. |
! | LastCheckpoint is declared as CheckpointInfo?, a value that may be null. A run with a checkpoint manager has saved its checkpoints by the time it stops at the question, and ! tells the compiler the value isn't null. |
<waiting>.SessionId | Gets the unique identifier for the current session. |
<waiting>.CheckpointId | The unique identifier for the checkpoint. |
new CheckpointInfo(<sessionId>, <checkpointId>) | Initializes a new instance of the CheckpointInfo class with the specified session and checkpoint identifiers. Neither ID may be null or empty. |
InProcessExecution.ResumeAsync | Loads the checkpoint into a new run of <workflow>, which has to be built the same way as the workflow that saved it. The question comes back as a RequestInfoEvent, ready for an answer. |
Microsoft's human-in-the-loop guide explains why that checkpoint is the one to keep: When a checkpoint is created, pending requests are also saved as part of the checkpoint state. And on the way back: When you restore from a checkpoint, any pending requests will be re-emitted as RequestInfoEvent objects, allowing you to capture and respond to them. A resumed run goes on saving checkpoints in the same session, so once an answer has gone in, the session's newest checkpoints come from after the answer.
The Example
A console app called ArticleReview asks an editor whether to publish an article. Its workflow has three steps: DescribeArticle turns the title into a question, the request port AskEditor waits for a yes or a no, and PublishArticle publishes the article when the answer is yes.
To show a step that fails after the answer, the publish step depends on a stand-in for a publishing service: a static flag, Publisher.Online. While it's true, PublishArticle returns Published.. While it's false, PublishArticle throws an InvalidOperationException with the message The publishing service is down..
The program starts the run with the title Ten tips for faster builds, keeps the checkpoint where the run waits, and then answers yes three times, each time in a new run resumed from a checkpoint:
- From the checkpoint where the run waits, while
Publisher.Onlineisfalse. - From the session's latest checkpoint.
- From the checkpoint where the run waits again, with
Publisher.Onlineback totrue.
Everything happens in one run of the program, with the checkpoints in memory, so you see the three answers side by side. 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; this guide used 10.0.404.
Step 1: Create a Console App
In a terminal, in the folder where you keep your projects, create a console app, move into it and add Agent Framework's workflows package:
dotnet new console -o ArticleReview
cd ArticleReview
dotnet add package Microsoft.Agents.AI.Workflows --version 1.28.0
dotnet new console -o ArticleReviewcreates a console app in a newArticleReviewfolder, andcdmoves into it.dotnet add packageadds Microsoft.Agents.AI.Workflows, which has the workflow types and the checkpoint manager.--versionkeeps you on the version this guide used.
The template "Console App" was created successfully.
Processing post-creation actions...
Restoring /Users/you/source/ArticleReview/ArticleReview.csproj:
Restore succeeded.
…
info : PackageReference for package 'Microsoft.Agents.AI.Workflows' version '1.28.0' added to file '/Users/you/source/ArticleReview/ArticleReview.csproj'.
info : Generating MSBuild file /Users/you/source/ArticleReview/obj/ArticleReview.csproj.nuget.g.targets.
info : Writing assets file to disk. Path: /Users/you/source/ArticleReview/obj/project.assets.json
log : Restored /Users/you/source/ArticleReview/ArticleReview.csproj (in 750 ms).
The project file now has the package:
<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 2: Create the Checkpoint Manager
Replace everything in Program.cs with:
using Microsoft.Agents.AI.Workflows;
const string SessionId = "article-7";
CheckpointManager checkpointManager = CheckpointManager.CreateInMemory();
SessionIdis the session the run's checkpoints are saved under.CheckpointManager.CreateInMemory()creates a checkpoint manager that keeps the checkpoints in the program's memory. That's enough here, because every answer comes in the same run of the program.
Step 3: Build a Workflow Whose Last Step Can Fail
Add the method that builds the workflow, and the Publisher class after it, at the end of the file:
static Workflow BuildWorkflow()
{
RequestPort askEditor = RequestPort.Create<string, bool>("AskEditor");
Func<string, string> describe = title => $"Publish \"{title}\"?";
Func<bool, string> publish = approved =>
!approved ? "Not published."
: Publisher.Online ? "Published."
: throw new InvalidOperationException("The publishing service is down.");
ExecutorBinding describeArticle = describe.BindAsExecutor("DescribeArticle");
ExecutorBinding publishArticle = publish.BindAsExecutor("PublishArticle");
return new WorkflowBuilder(describeArticle)
.AddEdge(describeArticle, askEditor)
.AddEdge(askEditor, publishArticle)
.WithOutputFrom(publishArticle)
.Build();
}
static class Publisher
{
public static bool Online { get; set; } = true;
}
RequestPort.Create<string, bool>("AskEditor")is the request port: the workflow sends it a question as astringand waits for aboolanswer. How to Pause a Microsoft Agent Framework Workflow Until a Person Answers in C# explains request ports step by step.describeturns the title into the question.\"puts a double quote inside the string, so the question shows the title in quotes.publishhandles the answer with two conditional operators:a ? b : cgivesbwhenais true, andcotherwise. A no givesNot published.. A yes givesPublished.whilePublisher.Onlineistrue, and otherwise thethrowexpression throws theInvalidOperationException.BindAsExecutorturns each function into a step with a fixed ID,DescribeArticleandPublishArticle, and the edges connect the first step to the port and the port to the second step.Publisheris a static class with one property,Online, which starts astrue. It stands in for a real publishing service, so the program can turn the service off and back on.
Step 4: Start the Run and Keep the Checkpoint Where It Waits
Add this below the checkpoint manager:
// Start the run. It asks the editor and waits: keep the checkpoint where it waits.
CheckpointInfo waiting;
await using (Run run = await InProcessExecution.RunAsync(BuildWorkflow(), "Ten tips for faster builds", checkpointManager, SessionId))
{
Console.WriteLine($"Started: {await run.GetStatusAsync()}");
waiting = run.LastCheckpoint!;
}
CheckpointInfo waiting;declares the variable before the block, so it's still there after the block ends.InProcessExecution.RunAsyncruns the workflow with the title as its input, the checkpoint manager and the session ID. It returns at the run's first halt: the question.await using (...) { ... }disposes of the run at the closing brace. Its checkpoints stay in the checkpoint manager.run.LastCheckpoint!is the run's most recent checkpoint. The run has just stopped at the question, so this is the checkpoint where it waits, andwaitingkeeps it.
Step 5: Answer Three Times
Add this below the run's block:
// The editor approves while the publishing service is down.
Publisher.Online = false;
Console.WriteLine("Answer 1, from the checkpoint where the run waits:");
await AnswerAsync(waiting);
// Continuing from the latest checkpoint instead:
CheckpointInfo latest = (await checkpointManager.GetLatestCheckpointAsync(SessionId))!;
Console.WriteLine("Answer 2, from the latest checkpoint:");
await AnswerAsync(latest);
// The service is back. Continue from the checkpoint where the run waits again.
Publisher.Online = true;
Console.WriteLine("Answer 3, from the checkpoint where the run waits:");
await AnswerAsync(waiting);
- Answer 1 turns the publishing service off by setting
Publisher.Onlinetofalse, then answers fromwaiting. - Answer 2 answers from the session's latest checkpoint instead.
GetLatestCheckpointAsyncreturns it, ornullwhen the session has no checkpoints, and!tells the compiler the session has some. - Answer 3 turns the service back on and answers from
waitingagain. AnswerAsyncdoes the answering. You write it in the next step.
Step 6: Answer from a Checkpoint
Add this below the three answers:
async Task AnswerAsync(CheckpointInfo checkpoint)
{
await using Run run = await InProcessExecution.ResumeAsync(BuildWorkflow(), checkpoint, checkpointManager);
RequestInfoEvent? question = run.OutgoingEvents.OfType<RequestInfoEvent>().SingleOrDefault();
if (question is null)
{
Console.WriteLine($" Nothing is waiting for an answer. Status: {await run.GetStatusAsync()}");
return;
}
await run.ResumeAsync([question.Request.CreateResponse(true)]);
foreach (WorkflowEvent workflowEvent in run.NewEvents)
{
if (workflowEvent is WorkflowOutputEvent output)
{
Console.WriteLine($" Output: {output.Data}");
}
else if (workflowEvent is ExecutorFailedEvent failed)
{
Console.WriteLine($" {failed.ExecutorId} failed: {failed.Data?.Message}");
}
}
}
async Task AnswerAsync(CheckpointInfo checkpoint)is a local function: a method written among the program's top-level statements, which can usecheckpointManagerfrom above.InProcessExecution.ResumeAsync(BuildWorkflow(), checkpoint, checkpointManager)loads the checkpoint into a new run of a workflow built the same way as the first, and runs it until its first halt.await usingdisposes of the run when the method ends.SingleOrDefault()gives the oneRequestInfoEventamong the run's outgoing events, ornullwhen there's none. Withnull, nothing waits in that checkpoint: the method prints the run's status and returns.CreateResponse(true)answers yes, andResumeAsyncsends the answer into the run, which goes on toPublishArticle.- The loop goes through
NewEvents, which on its first read holds every event the run has emitted, and picks out two kinds. AWorkflowOutputEventcarries the workflow's output. AnExecutorFailedEventnames the failed step inExecutorIdand carries its exception inData, and?.guards against that exception beingnull. How to Handle a Failed Step in a Microsoft Agent Framework Workflow in C# explains these events.
Step 7: Run the App
dotnet run
Started: PendingRequests
Answer 1, from the checkpoint where the run waits:
PublishArticle failed: The publishing service is down.
Answer 2, from the latest checkpoint:
Nothing is waiting for an answer. Status: Ended
Answer 3, from the checkpoint where the run waits:
Output: Published.

Line by line:
Started: PendingRequests— the run stopped at the question, andwaitingholds the checkpoint saved there.- Answer 1 — the question came back from
waiting, the yes went in, andPublishArticlethrew because the service was off. The article isn't published. - Answer 2 — the latest checkpoint has no question in it:
Nothing is waiting for an answer., and the resumed run's status isEnded, which Agent Framework's documentation describes as No further events will be emitted, and no messages can be sent to it. - Answer 3 —
waitingstill had the question. The same yes, with the service back on, gaveOutput: Published..
Why the Latest Checkpoint Has Nothing Waiting
Answer 1's run didn't end at the question. It took the answer and ran PublishArticle, and a run saves checkpoints in its session as it goes: Microsoft's checkpoints guide says Checkpoints are created at the end of each superstep, after all executors in that superstep have completed their execution. So the latest checkpoint wasn't waiting any more. It came from answer 1's run, after the answer had gone in, and no question waits in it.
Saving newer checkpoints didn't change the older one. Answer 3 resumed from waiting after answers 1 and 2, and the question came back as it did the first time. That's the checkpoint to answer from, however many times an answer has to go in.
:::warning A finished run is worse
After a run that has finished with the status Idle, the latest checkpoint isn't only empty: InProcessExecution.ResumeAsync from it doesn't return. Fixed: InProcessExecution.ResumeAsync Never Returns When a Microsoft Agent Framework Workflow Has Already Finished shows that hang and how keeping the waiting checkpoint avoids it.
:::
Keep the Waiting Checkpoint Across a Restart
Here waiting lives in a variable, because all three answers come in one run of the program. When the answer comes after a restart, the variable is gone. Keep the waiting checkpoint's two IDs, waiting.SessionId and waiting.CheckpointId, where your app keeps its data, and on the next start build the same CheckpointInfo from them with new CheckpointInfo(sessionId, checkpointId), as in the Syntax section. The checkpoints themselves have to outlive the program too: How to Resume a Microsoft Agent Framework Workflow from a Checkpoint After a Restart in C# keeps them in files, and the fixes post above writes the waiting checkpoint's ID to a file, with the session ID fixed in its code.
The Complete File
using Microsoft.Agents.AI.Workflows;
const string SessionId = "article-7";
CheckpointManager checkpointManager = CheckpointManager.CreateInMemory();
// Start the run. It asks the editor and waits: keep the checkpoint where it waits.
CheckpointInfo waiting;
await using (Run run = await InProcessExecution.RunAsync(BuildWorkflow(), "Ten tips for faster builds", checkpointManager, SessionId))
{
Console.WriteLine($"Started: {await run.GetStatusAsync()}");
waiting = run.LastCheckpoint!;
}
// The editor approves while the publishing service is down.
Publisher.Online = false;
Console.WriteLine("Answer 1, from the checkpoint where the run waits:");
await AnswerAsync(waiting);
// Continuing from the latest checkpoint instead:
CheckpointInfo latest = (await checkpointManager.GetLatestCheckpointAsync(SessionId))!;
Console.WriteLine("Answer 2, from the latest checkpoint:");
await AnswerAsync(latest);
// The service is back. Continue from the checkpoint where the run waits again.
Publisher.Online = true;
Console.WriteLine("Answer 3, from the checkpoint where the run waits:");
await AnswerAsync(waiting);
async Task AnswerAsync(CheckpointInfo checkpoint)
{
await using Run run = await InProcessExecution.ResumeAsync(BuildWorkflow(), checkpoint, checkpointManager);
RequestInfoEvent? question = run.OutgoingEvents.OfType<RequestInfoEvent>().SingleOrDefault();
if (question is null)
{
Console.WriteLine($" Nothing is waiting for an answer. Status: {await run.GetStatusAsync()}");
return;
}
await run.ResumeAsync([question.Request.CreateResponse(true)]);
foreach (WorkflowEvent workflowEvent in run.NewEvents)
{
if (workflowEvent is WorkflowOutputEvent output)
{
Console.WriteLine($" Output: {output.Data}");
}
else if (workflowEvent is ExecutorFailedEvent failed)
{
Console.WriteLine($" {failed.ExecutorId} failed: {failed.Data?.Message}");
}
}
}
static Workflow BuildWorkflow()
{
RequestPort askEditor = RequestPort.Create<string, bool>("AskEditor");
Func<string, string> describe = title => $"Publish \"{title}\"?";
Func<bool, string> publish = approved =>
!approved ? "Not published."
: Publisher.Online ? "Published."
: throw new InvalidOperationException("The publishing service is down.");
ExecutorBinding describeArticle = describe.BindAsExecutor("DescribeArticle");
ExecutorBinding publishArticle = publish.BindAsExecutor("PublishArticle");
return new WorkflowBuilder(describeArticle)
.AddEdge(describeArticle, askEditor)
.AddEdge(askEditor, publishArticle)
.WithOutputFrom(publishArticle)
.Build();
}
static class Publisher
{
public static bool Online { get; set; } = true;
}

Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
| Answering again from the latest checkpoint after a step failed | Nothing waits there: the example printed Nothing is waiting for an answer. Status: Ended | Answer from the checkpoint where the run waits |
Reading LastCheckpoint after the answer has gone in | It gives a newer checkpoint, saved after the answer | Read it when the run has stopped at the question |
| Resuming from the latest checkpoint of a run that has finished | ResumeAsync doesn't return | Resume only from the checkpoint where the run waits, while it waits |
Using CheckpointManager.CreateInMemory() when the answer comes after a restart | The checkpoints live in the program's memory and end with it | Keep them in a store that lasts, such as files |
FAQ
Can I resume the same checkpoint more than once?
Yes. The example resumed waiting twice, for answers 1 and 3, and the question came back both times. Each resume starts a new run from the same saved state.
Can I go back to the waiting checkpoint on the run I already have?
Microsoft's checkpoints guide shows that too: You can resume a workflow from a specific checkpoint directly on the same run. Its example calls RestoreCheckpointAsync on the run. This guide starts a new run for each answer with InProcessExecution.ResumeAsync instead.
How do I see which step failed?
From the ExecutorFailedEvent: its ExecutorId names the step, and its Data holds the exception. In the example, that's PublishArticle failed: The publishing service is down..
Conclusion
Read run.LastCheckpoint when a run stops at its question, and keep it: it's the checkpoint where the run waits, and every resume from it brings the question back. Don't rely on the session's latest checkpoint to answer again, because once an answer has gone in, newer checkpoints have nothing waiting. In the example, the first yes failed with The publishing service is down., the latest checkpoint had nothing waiting, and the same yes from the waiting checkpoint gave Published..
Additional Resources
- Checkpoints — when checkpoints are saved, and resuming from them on a new run or the same one.
- Human-in-the-loop (HITL) — request ports, and pending requests in checkpoints.
- CheckpointableRunBase.LastCheckpoint property — the run's most recent checkpoint in the API reference.
- CheckpointInfo class — a checkpoint's session ID and checkpoint ID, and its constructor.
Related
- How to Resume a Microsoft Agent Framework Workflow from a Checkpoint After a Restart in C#
- How to Pause a Microsoft Agent Framework Workflow Until a Person Answers in C#
- How to Handle a Failed Step in a Microsoft Agent Framework Workflow in C#
- Fixed: InProcessExecution.ResumeAsync Never Returns When a Microsoft Agent Framework Workflow Has Already Finished
