Skip to content

feat: add Moss-backed archival memory package for Letta#406

Open
rohanshrma222 wants to merge 2 commits into
usemoss:mainfrom
rohanshrma222:Letta
Open

feat: add Moss-backed archival memory package for Letta#406
rohanshrma222 wants to merge 2 commits into
usemoss:mainfrom
rohanshrma222:Letta

Conversation

@rohanshrma222

@rohanshrma222 rohanshrma222 commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Pull Request Checklist

  • I have read the CONTRIBUTING guide.
  • I have updated the documentation (if applicable).
  • My code follows the style guidelines of this project.
  • I have performed a self-review of my own code.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.

Description

Adds packages/letta-moss/, a Python package that backs Letta (MemGPT) archival memory with a Moss index.

Letta removed its old pluggable storage-backend abstraction for archival memory today it's hardcoded to Postgres/pgvector, Turbopuffer, or Pinecone with no public extension point to register a fourth backend without forking Letta. Letta's own docs recommend "External RAG through custom tools or MCP" as the sanctioned path for exactly this case.

This PR follows that pattern: MossLettaMemory wraps the Moss SDK with insert/search/delete/get/list operations, exposed through two integration surfaces plain async functions for client.tools.upsert_from_function(), and a FastMCP server for out-of-process use. No code in the letta package is touched. Users opt in with include_base_tools=False at agent creation.

Fixes #339

Type of Change

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update, adding README + AGENTS.md row

Testing

  • 37 unit tests, all mocking MossClient; 1 credential-gated test skips in CI.
  • ruff check passes clean.
  • Verified install against the real published moss package.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new Python integration package packages/letta-moss/ that exposes Moss as a Letta (MemGPT) archival-memory provider via (1) in-sandbox custom tools and (2) an out-of-process FastMCP server, without modifying Letta itself.

Changes:

  • Introduces MossLettaMemory adapter with insert/search/delete/get/list operations backed by a Moss index, including metadata (typed) round-tripping and tag post-filtering.
  • Adds two integration surfaces: plain async moss_memory_* functions (for upsert_from_function) and a FastMCP app factory (create_mcp_app).
  • Adds a full unit test suite (mocked client) plus a credential-gated MCP roundtrip test, and documents usage in README.md + AGENTS.md.

Reviewed changes

Copilot reviewed 11 out of 12 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
packages/letta-moss/src/letta_moss/memory.py Implements the Moss-backed archival memory adapter and metadata/tag handling logic.
packages/letta-moss/src/letta_moss/tools.py Adds plain async tool functions with a lazy singleton memory instance for Letta tool execution.
packages/letta-moss/src/letta_moss/mcp_app.py Exposes the memory adapter via a FastMCP server with tool wrappers.
packages/letta-moss/src/letta_moss/init.py Defines the package’s public API surface.
packages/letta-moss/tests/test_memory.py Unit-tests the adapter behaviors (create/load/query/get/list + metadata roundtrip).
packages/letta-moss/tests/test_tools.py Unit-tests lazy singleton construction and tool function delegation/shape.
packages/letta-moss/tests/test_mcp_app.py Unit-tests MCP tool registration, error mapping, and a credential-gated roundtrip.
packages/letta-moss/tests/init.py Marks the tests package.
packages/letta-moss/README.md Documents install, both integration options, and API/behavior notes.
packages/letta-moss/pyproject.toml Declares the new package metadata, dependencies, and test/lint config.
packages/letta-moss/LICENSE Adds package-level BSD-2-Clause license file.
AGENTS.md Registers the new package in the repository’s agent guidance index.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/letta-moss/src/letta_moss/tools.py
Comment thread packages/letta-moss/src/letta_moss/memory.py Outdated
Comment thread packages/letta-moss/src/letta_moss/mcp_app.py Outdated
Comment thread packages/letta-moss/src/letta_moss/mcp_app.py
Comment on lines +61 to +65
"""Delete a memory from Moss-backed archival storage by id."""
try:
await memory.delete_memory(memory_id)
except Exception as e:
raise RuntimeError(f"Moss memory delete failed: {e}") from e

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 12 changed files in this pull request and generated 4 comments.

Comments suppressed due to low confidence (1)

packages/letta-moss/src/letta_moss/tools.py:43

  • _get_memory() reads MOSS_INDEX_NAME via os.environ["MOSS_INDEX_NAME"], which raises a KeyError with a poor message if the env var is missing. Since this is user configuration, fail with a clear ValueError explaining how to configure it.
    async with _memory_lock:
        if _memory is None:
            memory = MossLettaMemory(index_name=os.environ["MOSS_INDEX_NAME"])
            await memory.load_index()
            _memory = memory

Comment on lines +50 to +57
@app.tool(name=tools.moss_memory_search.__name__)
async def _search(query: str, top_k: int = 5) -> list[dict]:
"""Search Moss-backed archival storage for memories relevant to a query."""
try:
items = await memory.search_memory(query, top_k=top_k)
except Exception as e:
raise RuntimeError(f"Moss memory search failed: {e}") from e
return [dataclasses.asdict(item) for item in items]
Comment thread packages/letta-moss/README.md
Comment on lines +62 to +75
async def moss_memory_search(query: str, top_k: int = 5) -> list[dict]:
"""Search Moss-backed archival storage for memories relevant to a query.

Args:
query: Natural-language query to search for.
top_k: Maximum number of results to return.

Returns:
A list of matching memories, each with ``id``, ``content``, ``tags``,
``metadata``, and ``score`` fields.
"""
memory = await _get_memory()
items = await memory.search_memory(query, top_k=top_k)
return [dataclasses.asdict(item) for item in items]
Comment on lines +69 to +73
| `MossLettaMemory(*, project_id=None, project_key=None, index_name, top_k=5, alpha=0.8)` | class | Core adapter; `async load_index()`, `async insert_memory(content, tags=, metadata=) -> str`, `async search_memory(query, top_k=, tags=) -> list[ArchivalMemoryItem]`, `async delete_memory(memory_id)`, `async get_memory(memory_id) -> ArchivalMemoryItem \| None`, `async list_memories(limit=) -> list[ArchivalMemoryItem]`. Falls back to `MOSS_PROJECT_ID`/`MOSS_PROJECT_KEY` env vars when credentials are omitted. |
| `moss_memory_insert(content, tags=None) -> str` | async function | Custom-tool wrapper; insert a memory, return its id. |
| `moss_memory_search(query, top_k=5) -> list[dict]` | async function | Custom-tool wrapper; search memories, return dicts. |
| `moss_memory_delete(memory_id) -> None` | async function | Custom-tool wrapper; delete a memory by id. |
| `create_mcp_app(memory) -> FastMCP` | function | Returns a FastMCP server exposing `moss_memory_insert`/`moss_memory_search`/`moss_memory_delete`; runs `memory.load_index()` in its lifespan. |
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Letta (MemGPT) archival-memory backend

2 participants