Skip to content

armgit / letta

Public Imported from GitHub
0

Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.

allow empty /load

cpacker2f60ede75c28
diff --git a/main.py b/main.py
index cb3a12b8f..fcddd267b 100644
--- a/main.py
+++ b/main.py
@@ -1,6 +1,7 @@
import asyncio
from absl import app, flags
import logging
+import glob
import os
import sys
import pickle
@@ -174,15 +175,29 @@ async def main():
except Exception as e:
print(f"Loading {filename} failed with: {e}")
else:
- print(f"/load error: no checkpoint specified")
+ # Load the latest file
+ print(f"/load warning: no checkpoint specified, loading most recent checkpoint instead")
+ json_files = glob.glob("saved_state/*.json") # This will list all .json files in the current directory.
+
+ # Check if there are any json files.
+ if not json_files:
+ print(f"/load error: no .json checkpoint files found")
+ else:
+ # Sort files based on modified timestamp, with the latest file being the first.
+ filename = max(json_files, key=os.path.getmtime)
+ try:
+ memgpt_agent.load_from_json_file_inplace(filename)
+ print(f"Loaded checkpoint {filename}")
+ except Exception as e:
+ print(f"Loading {filename} failed with: {e}")
# need to load persistence manager too
filename = filename.replace('.json', '.persistence.pickle')
try:
memgpt_agent.persistence_manager = InMemoryStateManager.load(filename) # TODO(fixme):for different types of persistence managers that require different load/save methods
- print(f"Loaded persistence manager from: {filename}")
+ print(f"Loaded persistence manager from {filename}")
except Exception as e:
- print(f"/load error: loading persistence manager from {filename} failed with: {e}")
+ print(f"/load warning: loading persistence manager from {filename} failed with: {e}")
continue