mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
c73bd87503
* [BREAKING] refactor: Decouple Checkpointing and Execution APIs With this change, Checkpointing becomes an property of an IWorkflowExecutionEnvironment. This lets environments that are tightly-coupled to their CheckpointManager avoid needing to present APIs that would not work (e.g. taking in an InMemory CheckpointManager for Durable Tasks, for example) * refactor: Normalize IsCheckpointingEnabled naming
50 lines
1.6 KiB
C#
50 lines
1.6 KiB
C#
// Copyright (c) Microsoft. All rights reserved.
|
|
|
|
using System.Collections.Generic;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.Agents.AI.Workflows.Checkpointing;
|
|
|
|
namespace Microsoft.Agents.AI.Workflows;
|
|
|
|
/// <summary>
|
|
/// Represents a base object for a workflow run that may support checkpointing.
|
|
/// </summary>
|
|
public abstract class CheckpointableRunBase
|
|
{
|
|
// TODO: Rename Context?
|
|
private readonly ICheckpointingHandle _checkpointingHandle;
|
|
|
|
internal CheckpointableRunBase(ICheckpointingHandle checkpointingHandle)
|
|
{
|
|
this._checkpointingHandle = checkpointingHandle;
|
|
}
|
|
|
|
/// <inheritdoc cref="ICheckpointingHandle.IsCheckpointingEnabled"/>
|
|
public bool IsCheckpointingEnabled => this._checkpointingHandle.IsCheckpointingEnabled;
|
|
|
|
/// <inheritdoc cref="ICheckpointingHandle.Checkpoints"/>
|
|
public IReadOnlyList<CheckpointInfo> Checkpoints => this._checkpointingHandle.Checkpoints ?? [];
|
|
|
|
/// <summary>
|
|
/// Gets the most recent checkpoint information.
|
|
/// </summary>
|
|
public CheckpointInfo? LastCheckpoint
|
|
{
|
|
get
|
|
{
|
|
if (!this.IsCheckpointingEnabled)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
var checkpoints = this.Checkpoints;
|
|
return checkpoints.Count > 0 ? checkpoints[checkpoints.Count - 1] : null;
|
|
}
|
|
}
|
|
|
|
/// <inheritdoc cref="ICheckpointingHandle.RestoreCheckpointAsync"/>
|
|
public ValueTask RestoreCheckpointAsync(CheckpointInfo checkpointInfo, CancellationToken cancellationToken = default)
|
|
=> this._checkpointingHandle.RestoreCheckpointAsync(checkpointInfo, cancellationToken);
|
|
}
|