mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
2015f0dc09
* feat: Support Checkpoint Serialization * Implements serialization roundtripping for checkpoints. * Adds support for JSON serialization * Adds FileSystem-based checkpoint persistence * fix: Executor State does not deserialize correctly The StateManager was not properly handling delay-deserialized values. * Fix PortableValue handling in StateManager (this makes it delegate to PortableValue the uwnrapping) * Fix UnitTest to actually test checkpoint serialization * Additional review comment fixes --------- Co-authored-by: Chris <66376200+crickman@users.noreply.github.com>
41 lines
1.1 KiB
C#
41 lines
1.1 KiB
C#
// Copyright (c) Microsoft. All rights reserved.
|
|
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics.CodeAnalysis;
|
|
|
|
namespace Microsoft.Agents.Workflows.Checkpointing;
|
|
|
|
internal sealed class RunCheckpointCache<TStoreObject>
|
|
{
|
|
private readonly HashSet<CheckpointInfo> _checkpointIndex = new();
|
|
private readonly Dictionary<CheckpointInfo, TStoreObject> _cache = new();
|
|
|
|
public IEnumerable<CheckpointInfo> Index => this._checkpointIndex;
|
|
|
|
public bool IsInIndex(CheckpointInfo key) => this._checkpointIndex.Contains(key);
|
|
public bool TryGet(CheckpointInfo key, [MaybeNullWhen(false)] out TStoreObject value) => this._cache.TryGetValue(key, out value);
|
|
|
|
public CheckpointInfo Add(string runId, TStoreObject value)
|
|
{
|
|
CheckpointInfo key;
|
|
|
|
do
|
|
{
|
|
key = new(runId);
|
|
} while (!this.Add(key, value));
|
|
|
|
return key;
|
|
}
|
|
|
|
public bool Add(CheckpointInfo key, TStoreObject value)
|
|
{
|
|
bool added = this._checkpointIndex.Add(key);
|
|
if (added)
|
|
{
|
|
this._cache[key] = value;
|
|
}
|
|
|
|
return added;
|
|
}
|
|
}
|