| name | migrating-v1-postgres-agents |
| description | Migrates agents from the retired Python Letta server's PostgreSQL database into Letta Code's local backend/App Server. Use when moving legacy agents, message history, and attached memory blocks into the current local backend and converting block memory to Git-backed MemFS Markdown files. |
Migrating V1 Postgres Agents
Move active agents, their full active message history, and current attached memory blocks from the retired Python server into a stopped Letta local backend.
Before running
- Back up the PostgreSQL database and the destination local-backend directory.
- Install Bun.
- Stop every App Server or Letta Code process that uses the destination directory. The local backend has no offline-import lock.
- Choose a new destination or confirm that none of the source agent IDs already exist there. The script never overwrites an agent, conversation, or MemFS directory.
- Read references/format.md when checking message conversion, storage compatibility, or excluded data.
Preview the migration
Run a dry run first:
bun .agents/skills/migrating-v1-postgres-agents/scripts/migrate.ts \
--postgres-url "$LETTA_V1_POSTGRES_URL" \
--storage-dir "$HOME/.letta/lc-local-backend" \
--dry-run
To select agents, repeat --agent:
bun .agents/skills/migrating-v1-postgres-agents/scripts/migrate.ts \
--postgres-url "$LETTA_V1_POSTGRES_URL" \
--storage-dir "$HOME/.letta/lc-local-backend" \
--agent agent-01234567-89ab-cdef-0123-456789abcdef \
--dry-run
Inspect each result's source/imported message counts, memory files, and warnings. Resolve unexpected warnings before writing.
Write the destination
Rerun without --dry-run. Set a model handle valid for the destination App Server:
bun .agents/skills/migrating-v1-postgres-agents/scripts/migrate.ts \
--postgres-url "$LETTA_V1_POSTGRES_URL" \
--storage-dir "$HOME/.letta/lc-local-backend" \
--model "<provider/model>"
The script:
- Opens a read-only, repeatable-read PostgreSQL transaction.
- Detects available legacy tables and columns.
- Reads complete agent, block, and message rows as JSON.
- Converts attached blocks to
system/<label>.md MemFS files.
- Converts each legacy conversation to the current local transcript format.
- Builds all files in a temporary staging directory.
- Moves staged agent, conversation, and MemFS paths into the destination only after every conversion succeeds.
If a destination path already exists, choose a fresh destination. Do not delete it blindly. It may contain current local work.
Verify before resuming work
- Keep the old server and database unchanged.
- Run the migration tests:
bun test .agents/skills/migrating-v1-postgres-agents/scripts/migration.test.ts
- Inspect the imported memory repository:
git -C "$HOME/.letta/lc-local-backend/memfs/<agent-id>/memory" log --oneline
git -C "$HOME/.letta/lc-local-backend/memfs/<agent-id>/memory" status --short
- Start the current App Server against the destination.
- List the imported agent and open each migrated conversation before sending a new message.
- Compare the visible message count and the
system/*.md memory contents with the dry-run report and source server.
- Send a new message only after the read-only comparison passes.
Keep the PostgreSQL backup until every migrated agent has completed a new turn successfully.