langchain-memtether 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4 @@
1
+ from .memory import MemTetherMemory
2
+
3
+ __all__ = ["MemTetherMemory"]
4
+ __version__ = "0.1.0"
@@ -0,0 +1,74 @@
1
+ """LangChain Memory backend backed by MemTether's governed SQLite store."""
2
+
3
+ from typing import Any, Dict, List, Optional
4
+ from pydantic import BaseModel, Field
5
+
6
+ try:
7
+ from langchain_core.memory import BaseMemory
8
+ except ImportError:
9
+ from langchain.schema import BaseMemory
10
+
11
+
12
+ class MemTetherMemory(BaseMemory):
13
+ """LangChain Memory backend backed by MemTether.
14
+
15
+ Adds to standard LangChain memory:
16
+ - Hash-chained audit log (tamper-evident)
17
+ - Source attribution on every write
18
+ - Bi-temporal supersession (corrections never delete)
19
+ - Conflict gate (contradictory writes flagged)
20
+ """
21
+
22
+ source: str = Field(default="langchain-agent")
23
+ search_limit: int = Field(default=5)
24
+
25
+ class Config:
26
+ arbitrary_types_allowed = True
27
+
28
+ def __init__(self, **kwargs):
29
+ super().__init__(**kwargs)
30
+ import memtether
31
+ self._mt = memtether
32
+ import gateway
33
+ self._gw = gateway
34
+
35
+ @property
36
+ def memory_variables(self) -> List[str]:
37
+ return ["history", "context"]
38
+
39
+ def load_memory_variables(self, inputs: Dict[str, Any]) -> Dict[str, Any]:
40
+ query = ""
41
+ for v in inputs.values():
42
+ if isinstance(v, str) and len(v) > len(query):
43
+ query = v
44
+ if not query:
45
+ return {"history": "", "context": ""}
46
+ try:
47
+ results = self._mt.search(query, limit=self.search_limit)
48
+ hits = results.get("results", [])
49
+ history = "\n".join(
50
+ f"[{h.get('source','?')}] {h.get('content','')}"
51
+ for h in hits if h.get("status") == "active"
52
+ )
53
+ return {"history": history, "context": history}
54
+ except Exception:
55
+ return {"history": "", "context": ""}
56
+
57
+ def save_context(self, inputs: Dict[str, Any], outputs: Dict[str, str]) -> None:
58
+ input_text = ""
59
+ output_text = ""
60
+ for v in inputs.values():
61
+ if isinstance(v, str) and len(v) > len(input_text):
62
+ input_text = v
63
+ for v in outputs.values():
64
+ if isinstance(v, str) and len(v) > len(output_text):
65
+ output_text = v
66
+ if output_text.strip():
67
+ try:
68
+ self._mt.remember(output_text[:500], type="fact", source=self.source)
69
+ except Exception:
70
+ pass
71
+
72
+ def clear(self) -> None:
73
+ """MemTether never deletes — this is intentional."""
74
+ pass
@@ -0,0 +1,41 @@
1
+ Metadata-Version: 2.4
2
+ Name: langchain-memtether
3
+ Version: 0.1.0
4
+ Summary: LangChain Memory backend backed by MemTether governed SQLite store (audit chain, bi-temporal, source attribution)
5
+ License: Apache-2.0
6
+ Project-URL: Repository, https://github.com/MemTether/MemTether
7
+ Keywords: langchain,memory,memtether,audit,agent,governance
8
+ Requires-Python: >=3.10
9
+ Description-Content-Type: text/markdown
10
+ Requires-Dist: memtether>=0.1.0a83
11
+ Requires-Dist: langchain-core>=0.1.0
12
+
13
+ # langchain-memtether
14
+
15
+ LangChain Memory backend backed by [MemTether](https://github.com/MemTether/MemTether) — governed memory with audit chain, bi-temporal supersession, and source attribution.
16
+
17
+ ## Install
18
+
19
+ ```bash
20
+ pip install langchain-memtether
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ ```python
26
+ from langchain_memtether import MemTetherMemory
27
+
28
+ memory = MemTetherMemory(source="my-agent")
29
+ # Use as any LangChain Memory backend
30
+ ```
31
+
32
+ ## Why MemTether instead of standard LangChain memory?
33
+
34
+ | Feature | MemTetherMemory | ConversationBufferMemory | ConversationSummaryMemory |
35
+ |---|---|---|---|
36
+ | Audit hash chain | ✅ | ❌ | ❌ |
37
+ | Tamper-evident | ✅ | ❌ | ❌ |
38
+ | Cross-session persistence | ✅ | ❌ | ⚠️ |
39
+ | Source attribution | ✅ | ❌ | ❌ |
40
+ | Conflict gate | ✅ | ❌ | ❌ |
41
+ | Bi-temporal queries | ✅ | ❌ | ❌ |
@@ -0,0 +1,6 @@
1
+ langchain_memtether/__init__.py,sha256=a6pSw6FHg9e-8uoQQktDatni3EpYjOzF5-T9PdHTOPA,93
2
+ langchain_memtether/memory.py,sha256=u06aSQ5TC7-Dhsi-DXPoYF9VgJRrJ3mA8Z2qIapjnSA,2558
3
+ langchain_memtether-0.1.0.dist-info/METADATA,sha256=uNYQeuX_eEYMy9YPaJug0wHW3h72eVbbYfPTypYl7vA,1325
4
+ langchain_memtether-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
5
+ langchain_memtether-0.1.0.dist-info/top_level.txt,sha256=Typzns3_YKYBzsVOYXzOHIrM0DNJeOqDJSQfEfQMVVw,20
6
+ langchain_memtether-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ langchain_memtether