feat: add Moss-backed archival memory package for Letta#406
Open
rohanshrma222 wants to merge 2 commits into
Open
feat: add Moss-backed archival memory package for Letta#406rohanshrma222 wants to merge 2 commits into
rohanshrma222 wants to merge 2 commits into
Conversation
Contributor
There was a problem hiding this comment.
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
MossLettaMemoryadapter 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 (forupsert_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 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 |
Contributor
There was a problem hiding this comment.
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 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. | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request Checklist
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:
MossLettaMemorywraps the Moss SDK with insert/search/delete/get/list operations, exposed through two integration surfaces plain async functions forclient.tools.upsert_from_function(), and a FastMCP server for out-of-process use. No code in thelettapackage is touched. Users opt in withinclude_base_tools=Falseat agent creation.Fixes #339
Type of Change
Testing
MossClient; 1 credential-gated test skips in CI.ruff checkpasses clean.mosspackage.