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.

fix: server memory leak (#1751)

Charles Packer8cf08e0245e8
diff --git a/memgpt/server/rest_api/app.py b/memgpt/server/rest_api/app.py
index b4d08ef9e..c635f96e5 100644
--- a/memgpt/server/rest_api/app.py
+++ b/memgpt/server/rest_api/app.py
@@ -38,7 +38,7 @@ from memgpt.settings import settings
# TODO(ethan)
# NOTE(charles): @ethan I had to add this to get the global as the bottom to work
interface: StreamingServerInterface = StreamingServerInterface
-server: SyncServer = SyncServer(default_interface_factory=lambda: interface())
+server: SyncServer = None
# TODO(ethan): eventuall remove
if password := settings.server_pass:
@@ -57,6 +57,8 @@ OPENAI_API_PREFIX = "/openai"
def create_application() -> "FastAPI":
"""the application start routine"""
+ global server
+ server = SyncServer(default_interface_factory=lambda: interface())
app = FastAPI(
swagger_ui_parameters={"docExpansion": "none"},
diff --git a/memgpt/server/rest_api/utils.py b/memgpt/server/rest_api/utils.py
index fdbccdc70..bd416e534 100644
--- a/memgpt/server/rest_api/utils.py
+++ b/memgpt/server/rest_api/utils.py
@@ -58,7 +58,10 @@ async def sse_async_generator(generator: AsyncGenerator, finish_message=True):
# TODO: why does this double up the interface?
def get_memgpt_server() -> SyncServer:
- server = SyncServer(default_interface_factory=lambda: StreamingServerInterface())
+ # Check if a global server is already instantiated
+ from memgpt.server.rest_api.app import server
+
+ assert isinstance(server, SyncServer)
return server