FileMemoryProvider Class

Definition

An AIContextProvider that provides file-based memory tools to an agent for storing, retrieving, modifying, listing, deleting, and searching files.

public sealed class FileMemoryProvider : Microsoft.Agents.AI.AIContextProvider, IDisposable
type FileMemoryProvider = class
    inherit AIContextProvider
    interface IDisposable
Public NotInheritable Class FileMemoryProvider
Inherits AIContextProvider
Implements IDisposable
Inheritance
FileMemoryProvider
Implements

Remarks

The FileMemoryProvider enables agents to persist information across interactions using a file-based storage model. Each memory is stored as an individual file with a meaningful name. For large files, a companion description file (suffixed with _description.md) can be stored alongside the main file to provide a summary.

File access is mediated through a AgentFileStore abstraction, allowing pluggable backends (in-memory, local file system, remote blob storage, etc.).

This provider exposes the following tools to the agent:

  • file_memory_write — Write a memory file with the given name, content, and an optional description.
  • file_memory_read — Read the content of a file by name.
  • file_memory_delete — Delete a file by name.
  • file_memory_ls — List all files with their descriptions (if available).
  • file_memory_grep — Search file contents using a regular expression pattern.
  • file_memory_replace — Replace occurrences of a substring within a memory file.
  • file_memory_replace_lines — Replace whole lines within a memory file.

Constructors

Name Description
FileMemoryProvider(AgentFileStore, Func<AgentSession,FileMemoryState>, FileMemoryProviderOptions)

Initializes a new instance of the FileMemoryProvider class.

Fields

Name Description
DeleteFileToolName

The name of the tool that deletes a memory file.

GrepToolName

The name of the tool that searches memory file contents.

LsToolName

The name of the tool that lists the memory files.

ReadFileToolName

The name of the tool that reads a memory file.

ReplaceLinesToolName

The name of the tool that replaces whole lines within a memory file.

ReplaceToolName

The name of the tool that replaces occurrences of a substring within a memory file.

WriteToolName

The name of the tool that writes a memory file.

Properties

Name Description
ProvideInputMessageFilter

Gets the filter function to apply to input messages before providing context via ProvideAIContextAsync(AIContextProvider+InvokingContext, CancellationToken).

(Inherited from AIContextProvider)
StateKeys

Gets the set of keys used to store the provider state in the StateBag.

StoreInputRequestMessageFilter

Gets the filter function to apply to request messages before storing context via StoreAIContextAsync(AIContextProvider+InvokedContext, CancellationToken).

(Inherited from AIContextProvider)
StoreInputResponseMessageFilter

Gets the filter function to apply to response messages before storing context via StoreAIContextAsync(AIContextProvider+InvokedContext, CancellationToken).

(Inherited from AIContextProvider)

Methods

Name Description
Dispose()

Releases the resources used by the FileMemoryProvider.

GetService(Type, Object)

Asks the AIContextProvider for an object of the specified type serviceType.

(Inherited from AIContextProvider)
GetService<TService>(Object)

Asks the AIContextProvider for an object of type TService.

(Inherited from AIContextProvider)
InvokedAsync(AIContextProvider+InvokedContext, CancellationToken)

Called at the end of the agent invocation to process the invocation results.

(Inherited from AIContextProvider)
InvokedCoreAsync(AIContextProvider+InvokedContext, CancellationToken)

Called at the end of the agent invocation to process the invocation results.

(Inherited from AIContextProvider)
InvokingAsync(AIContextProvider+InvokingContext, CancellationToken)

Called at the start of agent invocation to provide additional context.

(Inherited from AIContextProvider)
InvokingCoreAsync(AIContextProvider+InvokingContext, CancellationToken)

Called at the start of agent invocation to provide additional context.

(Inherited from AIContextProvider)
ProvideAIContextAsync(AIContextProvider+InvokingContext, CancellationToken)

When overridden in a derived class, provides additional AI context to be merged with the input context for the current invocation.

(Inherited from AIContextProvider)
StoreAIContextAsync(AIContextProvider+InvokedContext, CancellationToken)

When overridden in a derived class, processes invocation results at the end of the agent invocation.

(Inherited from AIContextProvider)

Applies to