from praisonai.train.agents.storage import TrainingStoragefrom praisonaiagents.storage import FileBackendwith TrainingStorage( session_id="train-123", backend=FileBackend(storage_dir="~/.praisonai/train"),) as storage: storage.save_iteration(...)# .close() is a safe no-op for FileBackend — the with block keeps usage consistent
BaseJSONStore.save() writes atomically: on success the staging .tmp is renamed over the real file; on serialization or encoding failure the original error propagates, the previous store is left intact, and the staging file is cleaned up. See Thread Safety → BaseJSONStore atomic save.
TrainingStorage is a context manager. FileBackend holds no open connection, so
.close() is a safe no-op here — but using with keeps the pattern identical to the
SQLite and Redis backends, where closing releases a file or network handle (essential
on Windows and for long-running processes).
FileBackend.load() returns None on corrupted files (invalid UTF-8, malformed JSON, unreadable) and leaves the bytes untouched on disk. The same instance then refuses an ordinary save() on that key until you call backend.delete(key), the source is removed, or a subsequent load() succeeds — so a transient-looking fallback never silently overwrites forensic evidence. See Error Handling and Save-side guard for details.
# Training with file backend (default)praisonai train agents --input "Hello" --storage-backend file --storage-path ~/.praisonai/train# Session list with file backendpraisonai session list --storage-backend file --storage-path ~/.praisonai/sessions