Sagents.FileSystem.Persistence.Disk (Sagents v0.8.0-rc.7)

Copy Markdown

Default disk-based persistence implementation.

Stores files on the local filesystem. The storage location is specified via the :path option in storage_opts of your FileSystemConfig.

Configuration

alias Sagents.FileSystem.{FileSystemServer, FileSystemConfig}
alias Sagents.FileSystem.Persistence.Disk

{:ok, config} = FileSystemConfig.new(%{
  base_directory: "user_files",
  persistence_module: Disk,
  debounce_ms: 5000,
  storage_opts: [path: "/var/lib/langchain/agents"]
})

FileSystemServer.start_link(
  agent_id: "agent-123",
  persistence_configs: [config]
)

Multiple Directories Example

# Database storage for user files
{:ok, user_config} = FileSystemConfig.new(%{
  base_directory: "user_files",
  persistence_module: Disk,
  storage_opts: [path: "/var/data/users"]
})

# Read-only system files
{:ok, system_config} = FileSystemConfig.new(%{
  base_directory: "system",
  persistence_module: Disk,
  readonly: true,
  storage_opts: [path: "/var/data/system"]
})

FileSystemServer.start_link(
  agent_id: "agent-123",
  persistence_configs: [user_config, system_config]
)

Storage Options

  • :path - Base directory for file storage (required)
  • :base_directory - Virtual directory name (automatically added by FileSystemConfig). Not present for default configs (default: true), in which case files are stored directly under the storage path without any directory prefix stripping.

File Organization

Files are stored by stripping the base_directory from the virtual path and saving to the storage path:

<storage_path>/<file_path - base_directory>

Example with base_directory "user_files":

Virtual path: "/user_files/notes.txt"
Storage path: "/var/data/agents"
Disk path: "/var/data/agents/notes.txt"

Example with base_directory "system":

Virtual path: "/system/config.json"
Storage path: "/var/data/system"
Disk path: "/var/data/system/config.json"