teff.memory.tool¶
teff.memory.tool
¶
Agent-facing tool for long-term memory (remember / recall / forget).
Classes:
| Name | Description |
|---|---|
MemoryTool |
Tool that lets an agent read and write long-term memory. |
Functions:
| Name | Description |
|---|---|
memory_from_config |
Build a :class: |
MemoryTool
¶
Bases: Tool
Tool that lets an agent read and write long-term memory.
Usage::
memory = MemoryTool(
store=SQLiteVectorStore(path="./memory.db", dim=768),
embedder=Embedder(provider="ollama", model="nomic-embed-text"),
namespace=("users", "u1"),
)
await memory.arun(action="remember", text="prefers email over Slack")
result = await memory.arun(action="recall", query="how to reach them?")
Actions (passed as action):
remember— upsert a fact (textplus optionalmetadata). Whensimilarity_thresholdis set and a semantically close item already exists in the namespace, the new text overwrites that item instead of creating a duplicate.recall— return top-k memories for aquery(or the most recent if no query is given), formatted for a prompt.forget— delete the memory atkey.list— enumerate stored keys.
Can be built from a config dict (e.g. a tools: entry in a
workflow YAML)::
{
"name": "memory",
"store": {"type": "sqlite", "path": "./memory.db", "dim": 768},
"embedder": {"provider": "ollama", "model": "nomic-embed-text"},
"namespace": ["users", "${USER_ID}"],
"default_k": 5,
"similarity_threshold": 0.6,
}
Supported store types match RAGTool: in_memory (default),
sqlite, chroma, qdrant, pgvector, faiss, lance,
milvus, weaviate, pinecone.
Methods:
| Name | Description |
|---|---|
arun |
Run a memory operation and return a human-readable result. |
Source code in teff/memory/tool.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | |
arun
async
¶
arun(action='recall', key='', text='', value=None, query='', metadata=None, k=None)
Run a memory operation and return a human-readable result.
The namespace is fixed at construction time and can never be
overridden by the caller — an agent cannot address another owner's
memories by passing a namespace. Per-owner isolation is achieved by
building one tool per owner (namespace=("users", owner)).
Source code in teff/memory/tool.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | |
memory_from_config
¶
memory_from_config(config, *, default_ttl=None, providers=None, default_provider=None)
Build a :class:MemoryStore from a config dict.
Mirrors RAGTool / MemoryTool config: {"store": {...},
"embedder": {...}, "ttl": ...}. Used by workflow YAML loading and
by :class:~teff.node.agent.ReActAgent context injection.
providers (a registry) lets the embedder inherit a provider's
base_url / api_key_env when the config does not set them
explicitly.
Source code in teff/memory/tool.py
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | |