Proposal: A basic conversation Memory component (persistence + recall) for stdlib
维护者通常 3 天内回复
还没有人认领这个 Issue。
评估
调研方向
This is a design proposal, not a ready task. Read ChatContext and the instruct() grounding_context parameter in mellea.stdlib.components.chat to see the injection seam, and the RichDocument save/load idiom the issue cites. Do not start a patch until a maintainer decides whether it belongs in stdlib or mellea-contribs and whether V1 is explicit+heuristic only or includes LLM extraction. Done means that decision is recorded on the issue.
由索引模型根据 Issue 内容生成。
描述
Summary
I'd like to contribute a small, dependency-free conversation memory component, and I'm opening
this issue first to get your direction on scope and placement (stdlib vs. mellea-contribs) before
sending a PR.
This is the familiar flat-file "user memory" pattern (similar to what assistant products expose
as persistent memory): a small, human-readable store of durable facts about the user that
survives restarts and is recalled into context when relevant. Today a Mellea session keeps recent
turns in ChatContext(window_size=N), but there's no built-in way to (1) persist durable facts
across process restarts, or (2) recall a relevant fact from earlier than the context window. This
proposal adds both, in pure Python, behind a small interface designed so richer backends can swap in
later without changing the API.
Motivation / the gaps
- No cross-session persistence. When the process exits, everything the session learned is gone —
there's nosave()/load()for durable user facts. (RichDocument has a save/load idiom, but
nothing equivalent for user memory.) - No selective recall.
ChatContextis a recency window; once a turn slides out, it's
unrecoverable, even if it's exactly the fact the next prompt needs.
Proposed design
A stable Memory Protocol + a built-in MarkdownMemory implementation. Durable user-facts are the
primary store (a human-readable Markdown file); extracting facts from a conversation is a secondary
helper. retrieve() returns a mapping that drops directly into instruct(grounding_context=...) —
the existing injection seam.
@runtime_checkable
class Memory(Protocol):
# primary: durable user-facts
def remember(self, fact: str, *, metadata: dict | None = None) -> None: ...
def forget(self, fact: str) -> None: ...
def facts(self) -> list[str]: ...
def retrieve(self, query: str, *, k: int = 5) -> dict[str, str | CBlock | Component]: ...
# secondary helper: extract facts from a conversation (extractor pluggable — see design question)
def ingest_context(self, ctx: Context, *, extractor: "FactExtractor | None" = None) -> None: ...
# persistence
def save(self, path: str | Path) -> None: ... # writes <path>.md + <path>.meta.json
@classmethod
def load(cls, path: str | Path) -> "Memory": ...
class MarkdownMemory: # V1 default: Markdown store + JSON sidecar, keyword+recency recall, no deps
...
Storage is a human-readable Markdown file (the source of truth) plus a small JSON sidecar for
metadata (timestamps/scores), so the .md stays hand-editable:
# User Memory
- User prefers uv over pip.
- User's name is Alice.
Usage (instruct-only, since grounding_context is an instruct() parameter):
mem = MarkdownMemory.load(p) if p.exists() else MarkdownMemory()
mem.remember("User prefers uv over pip.") # durable fact
with start_session("ollama", context_type="chat") as s:
out = s.instruct(user_msg, grounding_context=mem.retrieve(user_msg)) # recall
mem.ingest_context(s.ctx) # OPTIONAL: extract facts
mem.save(p) # persist (.md + .meta.json)
Scope (intentionally minimal for a first PR)
- In: durable user-facts (
remember/forget/facts),save/load(Markdown + JSON sidecar,
versioned), keyword+recencyretrieve()returning agrounding_contextmapping, optional
ingest_context()fact-extraction viaas_chat_history(), unit tests (no LLM), one backend-free example. - Out / future: embeddings/semantic retrieval, active LLM-driven memory (via
@mify/MObject),
auto-persist via aSESSION_CLEANUPhook, and KV-cache-aware retrieval forLocalHFBackend. The
retrieve()method is deliberately the single pluggable seam so these can land as follow-ups
without breaking the API.
Key design question: how are facts extracted? (your call for V1)
The hardest scoping decision is who decides what becomes a stored fact. There's a spectrum, and
the choice determines whether V1 stays dependency-free or takes an LLM/backend dependency. The
interface is identical at every point on the spectrum — only what sits behind ingest_context()
changes — so we'd like your steer on where V1 should land:
| Level | Who extracts | LLM/backend needed? | Behaves like |
|---|---|---|---|
| A. Explicit | App/user calls remember("…") |
No | CLAUDE.md — deliberate writes |
| B. Heuristic | Rule-based scan of turns ("remember that…", "my name is…") | No | Lightweight auto-capture |
| C. LLM-extracted | A model reads the exchange and infers durable facts, dedupes/merges | Yes | ChatGPT / Anthropic-style auto-memory |
We can ship A+B with zero dependencies today (deterministic, unit-testable, works on every
backend). C is the "feels magic" version but requires a model call per ingestion — i.e. memory
would depend on a backend, and tests become qualitative.
Questions:
- Do you want V1 to be the clean, dependency-free A+B, with C added later behind the same
ingest_context()seam (e.g. an opt-inextractor=that defaults to heuristics but accepts an
LLM-backed extractor)? - Or do you consider LLM-extracted memory (C) essential to V1, accepting the backend dependency
and qualitative tests? If so, should the extractor use the session's existing backend, or be a
pluggable component?
Either way the public API is the same — this is purely about how much intelligence ships inside V1
vs. arrives as a follow-up. We're glad to build to your preference; we just don't want to assume.
Dependencies
Levels A+B: none — pure stdlib (json, pathlib, re), pyproject.toml unchanged. Level C
would add an LLM call via the session's backend (no new package, but a runtime/backend dependency
and qualitative tests) — included only if you want it in V1.
Compatibility
No changes to existing Mellea APIs or behavior. The component is additive and self-contained
(imports only mellea.core and mellea.stdlib.components.chat).
The question for maintainers
- Does this belong in
mellea/stdlib, or would you prefer it start in mellea-contribs? - Any preference on naming (
Memory/MarkdownMemoryvs. e.g.UserMemory)? And is Markdown +
JSON-sidecar the storage you'd want, or a single JSON file? - Is the Protocol + swappable-backend shape the right altitude, or do you prefer a single concrete
class for now?
Happy to follow whichever direction you prefer — the design is self-contained so relocating between
stdlib and contribs is a file move, not a rewrite. I'll open the PR once you've weighed in.
@HendrikStrobelt @nrfulton
- 主要语言
- Python
- 星标
- 1.8k
- 派生
- 161
- 平均合并
- 4 天 3 小时
- 30 天内合并 PR
- 45
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
generative-computing/mellea 的其他 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 72/100
generative-computing/mellea#1864 ·
维护者通常 3 天内回复
-
bug: instruct() and react() replay tool-call turns without tool_calls可能已有人在做 @simonyang08 于 21 天前认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 85/100
generative-computing/mellea#1784 · 1 条评论 ·
维护者通常 3 天内回复
-
Silently mangled docstrings: lone backslash line-continuations in non-raw docstrings collapse command examples可能已有人在做 @madhusudhan1260 于 18 天前认领。 未关闭good first issue p2
难度 2/5 1-3 小时 新手友好度 82/100
generative-computing/mellea#1780 · 2 条评论 · 已指派 1 人 ·
维护者通常 3 天内回复
-
area/telemetry enhancement p2
难度 2/5 1-3 小时 新手友好度 66/100
generative-computing/mellea#1210 ·
维护者通常 3 天内回复
-
area/requirement area/stdlib enhancement p2
难度 2/5 1-3 小时 新手友好度 62/100
generative-computing/mellea#31 · 2 条评论 ·
维护者通常 3 天内回复
查看 generative-computing/mellea 的全部 Issue
相似的 Issue
-
flaky: test_fire_returns_thread_per_http_entry_on_head waits 5 s per dispatch worker on busy shards未关闭status/accepted type/bug
难度 2/5 1-3 小时 新手友好度 74/100
维护者通常 1 天内回复
-
bug vector-store
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 74/100
EverMind-AI/Raven#1413 ·
维护者通常 1 天内回复
-
Tests: parallel pyinstallcheck runs oversubscribe the machine through nested TBB and BLAS pools可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 86/100
ACCESS-NRI/containerised-environments-infra#143 ·
维护者通常 2 天内回复