Proposal: A basic conversation Memory component (persistence + recall) for stdlib
Los mantenedores suelen responder en 3 días
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 15/100
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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
- Lenguaje dominante
- Python
- Estrellas
- 1.8k
- Forks
- 161
- Merge medio
- 4 d 3 h
- PR fusionados (30 d)
- 45
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de generative-computing/mellea
-
bug: `mellea.plugins.builtin_debug.generation.log_generation_post_call` shows model as unknownAbiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
generative-computing/mellea#1864 ·
Los mantenedores suelen responder en 3 días
-
bug: instruct() and react() replay tool-call turns without tool_callsPosiblemente ocupada @simonyang08 la tomó hace 21 días. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
generative-computing/mellea#1784 · 1 comentario ·
Los mantenedores suelen responder en 3 días
-
Silently mangled docstrings: lone backslash line-continuations in non-raw docstrings collapse command examplesPosiblemente ocupada @madhusudhan1260 la tomó hace 18 días. Abiertogood first issue p2
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
generative-computing/mellea#1780 · 2 comentarios · 1 asignado ·
Los mantenedores suelen responder en 3 días
-
area/telemetry enhancement p2
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
generative-computing/mellea#1210 ·
Los mantenedores suelen responder en 3 días
-
Add requirement priorityAbiertoarea/requirement area/stdlib enhancement p2
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
generative-computing/mellea#31 · 2 comentarios ·
Los mantenedores suelen responder en 3 días
Todos los issues de generative-computing/mellea
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
OpenFreeEnergy/openfe#2371 ·
Los mantenedores suelen responder en 2 días
-
HMDB's smiles file writes "None" for metabolites with an empty <smiles/> (file not currently used)Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 80/100
NCATSTranslator/Babel#1269 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 Medio día Aptitud para principiantes 80/100
Los mantenedores suelen responder en 1 día
-
404 on sample dataAbiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 64/100
bcgov/nr-hydrometric-rating-curve#443 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100