JsonFileChatInteractionStore

Models & Types · AiDotNet.Agentic.Pipeline

A durable, crash-safe IChatInteractionStore backed by one JSON file.

Implements: IChatInteractionStore

For Beginners

This saves what the AI said, in a file, so you can play it back later without calling the AI again. Point it at a path, record once, and then switch your client to replay: your tests run instantly, offline, and give the same answers every time. Only fingerprints of your prompts are written, so the file is safe to commit alongside your code.

How It Works

This is what turns a model-driven experiment into a repeatable one. Record a run once against a real provider, commit the resulting file, and every later run replays the identical answers with no network access, no API key, and no cost — in a unit test, on a build server, on a reviewer’s laptop, a year later. A benchmark whose model calls are recorded can be re-derived by anyone; one whose calls are live cannot, which is precisely the gap between a reproducible result and an anecdote. The reference OpenEvolve implementation logs prompts into its program database for inspection but never replays them, so its runs cannot be reproduced at all.

Writes are atomic in the same way JsonEvolutionCheckpointStore is: the whole file is serialized to a temporary file in the same directory, flushed to disk, and swapped into place, keeping the previous version beside it. A crash therefore leaves either the old file or the new one, never a half-written one.

Requests are recorded under the SHA-256 of their canonical key, not under the key itself, so the file holds no prompt text, no conversation content, and no credentials — only fingerprints and the answers they map to. Set storeRequestKeys when you are debugging a replay miss and accept that the file will then contain the prompts.

Constructors

Constructor Summary
JsonFileChatInteractionStore(string filePath, bool autoFlush, bool storeRequestKeys, long maxBytes) Initializes a file-backed store, loading any interactions the file already holds.

Properties

Property Summary
bool HasUnsavedChanges { get; } Gets whether interactions have been saved that the file does not yet contain.
int Count { get; }
string FilePath { get; } Gets the full path of the file this store reads and writes.

Methods

Method Summary
bool TryGet(string key, ChatResponse response)
string ToString() Returns a description that names the file and the entry count but no recorded content.
void Clear() Removes every interaction from memory and from the file.
void Flush() Writes any pending interactions to the file.
void Save(string key, ChatResponse response)

Fields

Field Summary
int SchemaVersion The schema version written into every file.