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(core): transform nested block labels on git memory enable (#9339)

Sarah Wooders93e453ef8f93
diff --git a/letta/server/server.py b/letta/server/server.py
index ebe7f1901..023694ffc 100644
--- a/letta/server/server.py
+++ b/letta/server/server.py
@@ -658,7 +658,7 @@ class SyncServer(object):
if request.memory_blocks:
transformed_blocks = []
for block in request.memory_blocks:
- if "/" not in block.label:
+ if not block.label.startswith("system/"):
block = block.model_copy(update={"label": f"system/{block.label}"})
transformed_blocks.append(block)
updates["memory_blocks"] = transformed_blocks
diff --git a/letta/services/block_manager_git.py b/letta/services/block_manager_git.py
index a5acf0d4a..b1f4d161b 100644
--- a/letta/services/block_manager_git.py
+++ b/letta/services/block_manager_git.py
@@ -369,9 +369,13 @@ class GitEnabledBlockManager(BlockManager):
agent_id,
)
blocks = await self.get_blocks_by_agent_async(agent_id, actor)
- # Ensure blocks have path-based labels before creating repo
+ # Ensure blocks have path-based labels before creating repo.
+ # All existing blocks were rendered in the system prompt, so they
+ # need the system/ prefix. Check startswith (not "/" presence)
+ # because labels like "letta/letta_town" contain "/" but aren't
+ # yet in the system/ namespace.
for block in blocks:
- if "/" not in block.label:
+ if not block.label.startswith("system/"):
old_label = block.label
new_label = f"system/{block.label}"
async with db_registry.async_session() as session:
@@ -389,10 +393,12 @@ class GitEnabledBlockManager(BlockManager):
return
# Get current blocks for this agent and transform labels to path-based.
- # Flat labels (e.g. "human") become "system/human" for the git directory structure.
+ # All existing blocks were in the system prompt, so they need the system/ prefix.
+ # Use startswith check (not "/" presence) because labels like "letta/letta_town"
+ # contain "/" but aren't yet in the system/ namespace.
blocks = await self.get_blocks_by_agent_async(agent_id, actor)
for block in blocks:
- if "/" not in block.label:
+ if not block.label.startswith("system/"):
old_label = block.label
new_label = f"system/{block.label}"
logger.info(f"Transforming block label '{old_label}' -> '{new_label}' for agent {agent_id}")