# Atlaso + LangChain

<!-- Canonical: https://www.atlaso.ai/docs/recipes/langchain -->

`pip install atlaso[langchain]` is reserved namespace today — the extra installs only `atlaso` core and emits a `FrameworkExtraReservedWarning` once per process when LangChain is detected alongside it. Until the dedicated adapter ships, wrap Atlaso into LangChain manually:

```python
from atlaso import Memory
from langchain.memory import BaseMemory

class AtlasoMemory(BaseMemory):
    memory_key: str = "history"

    def __init__(self, user_id: str, **kwargs):
        super().__init__(**kwargs)
        self._mem = Memory().for_user(user_id)

    @property
    def memory_variables(self) -> list[str]:
        return [self.memory_key]

    def load_memory_variables(self, inputs: dict) -> dict:
        hits = self._mem.recall(inputs.get("input", ""), limit=5)
        return {self.memory_key: "\n".join(h.content for h in hits if h.is_confident)}

    def save_context(self, inputs: dict, outputs: dict) -> None:
        if outputs.get("output"):
            self._mem.add(outputs["output"])

    def clear(self) -> None:
        # Atlaso has no `clear` — deposits are immutable evidence.
        # Use `m.retract(deposit_id, reason=...)` per-row instead.
        raise NotImplementedError(
            "Atlaso deposits are immutable; clear is not supported. "
            "Retract individual deposits via m.retract(...)."
        )
```

**What you lose by going through `BaseMemory`:** the dispersion fields (`is_confident`, `has_disagreement`, `agreement_score`, `conflict_peers`) don't fit `dict[str, str]`. The recipe filters on `is_confident` to avoid surfacing conflicted memories as authoritative. If your application can branch on disagreement (e.g. ask the user for confirmation), call `m.recall()` directly instead.

---

<!-- atlaso:doc-trailer -->
**Source:** <https://www.atlaso.ai/docs/recipes/langchain>  
**Edit on GitHub:** <https://github.com/imashishkh21/atlaso/tree/main/docs/recipes/langchain.md>  
**Updated:** 2026-05-12
