memharness 0.1.0__tar.gz
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.
- memharness-0.1.0/.gitignore +74 -0
- memharness-0.1.0/LICENSE +21 -0
- memharness-0.1.0/PKG-INFO +239 -0
- memharness-0.1.0/README.md +188 -0
- memharness-0.1.0/pyproject.toml +125 -0
- memharness-0.1.0/src/memharness/__init__.py +39 -0
- memharness-0.1.0/src/memharness/agents/__init__.py +34 -0
- memharness-0.1.0/src/memharness/agents/base.py +215 -0
- memharness-0.1.0/src/memharness/agents/consolidator.py +481 -0
- memharness-0.1.0/src/memharness/agents/entity_extractor.py +604 -0
- memharness-0.1.0/src/memharness/agents/gc.py +453 -0
- memharness-0.1.0/src/memharness/agents/scheduler.py +522 -0
- memharness-0.1.0/src/memharness/agents/summarizer.py +367 -0
- memharness-0.1.0/src/memharness/backends/__init__.py +97 -0
- memharness-0.1.0/src/memharness/backends/memory.py +153 -0
- memharness-0.1.0/src/memharness/backends/postgres.py +1613 -0
- memharness-0.1.0/src/memharness/backends/protocol.py +65 -0
- memharness-0.1.0/src/memharness/backends/sqlite.py +410 -0
- memharness-0.1.0/src/memharness/config/__init__.py +104 -0
- memharness-0.1.0/src/memharness/config/loader.py +518 -0
- memharness-0.1.0/src/memharness/config/models.py +286 -0
- memharness-0.1.0/src/memharness/core/__init__.py +9 -0
- memharness-0.1.0/src/memharness/core/embedding.py +45 -0
- memharness-0.1.0/src/memharness/core/harness.py +2227 -0
- memharness-0.1.0/src/memharness/exceptions.py +35 -0
- memharness-0.1.0/src/memharness/integrations/__init__.py +43 -0
- memharness-0.1.0/src/memharness/integrations/langchain.py +407 -0
- memharness-0.1.0/src/memharness/integrations/langgraph.py +562 -0
- memharness-0.1.0/src/memharness/py.typed +0 -0
- memharness-0.1.0/src/memharness/registry.py +731 -0
- memharness-0.1.0/src/memharness/tools/__init__.py +46 -0
- memharness-0.1.0/src/memharness/tools/definitions.py +367 -0
- memharness-0.1.0/src/memharness/tools/executor.py +776 -0
- memharness-0.1.0/src/memharness/types.py +154 -0
- memharness-0.1.0/tests/__init__.py +1 -0
- memharness-0.1.0/tests/conftest.py +294 -0
- memharness-0.1.0/tests/integration/__init__.py +1 -0
- memharness-0.1.0/tests/integration/test_agents.py +584 -0
- memharness-0.1.0/tests/integration/test_memory_harness.py +732 -0
- memharness-0.1.0/tests/integration/test_sqlite_backend.py +551 -0
- memharness-0.1.0/tests/unit/__init__.py +1 -0
- memharness-0.1.0/tests/unit/test_config.py +509 -0
- memharness-0.1.0/tests/unit/test_registry.py +448 -0
- memharness-0.1.0/tests/unit/test_types.py +377 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
*.egg-info/
|
|
24
|
+
.installed.cfg
|
|
25
|
+
*.egg
|
|
26
|
+
|
|
27
|
+
# Unit test / coverage reports
|
|
28
|
+
htmlcov/
|
|
29
|
+
.tox/
|
|
30
|
+
.nox/
|
|
31
|
+
.coverage
|
|
32
|
+
.coverage.*
|
|
33
|
+
.cache
|
|
34
|
+
nosetests.xml
|
|
35
|
+
coverage.xml
|
|
36
|
+
*.cover
|
|
37
|
+
*.py,cover
|
|
38
|
+
.hypothesis/
|
|
39
|
+
.pytest_cache/
|
|
40
|
+
|
|
41
|
+
# Environments
|
|
42
|
+
.env
|
|
43
|
+
.venv
|
|
44
|
+
env/
|
|
45
|
+
venv/
|
|
46
|
+
ENV/
|
|
47
|
+
|
|
48
|
+
# mypy
|
|
49
|
+
.mypy_cache/
|
|
50
|
+
|
|
51
|
+
# Ruff
|
|
52
|
+
.ruff_cache/
|
|
53
|
+
|
|
54
|
+
# IDE
|
|
55
|
+
.idea/
|
|
56
|
+
.vscode/
|
|
57
|
+
*.swp
|
|
58
|
+
*~
|
|
59
|
+
|
|
60
|
+
# OS
|
|
61
|
+
.DS_Store
|
|
62
|
+
Thumbs.db
|
|
63
|
+
|
|
64
|
+
# SQLite databases
|
|
65
|
+
*.db
|
|
66
|
+
*.sqlite
|
|
67
|
+
*.sqlite3
|
|
68
|
+
|
|
69
|
+
# Docusaurus
|
|
70
|
+
docs/node_modules/
|
|
71
|
+
docs/.docusaurus/
|
|
72
|
+
docs/build/
|
|
73
|
+
dist/
|
|
74
|
+
dist/
|
memharness-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ayush Sonuu
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: memharness
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Framework-agnostic memory infrastructure for AI agents
|
|
5
|
+
Project-URL: Homepage, https://github.com/AyushSonuu/memharness
|
|
6
|
+
Project-URL: Documentation, https://ayushsonuu.github.io/memharness
|
|
7
|
+
Project-URL: Repository, https://github.com/AyushSonuu/memharness
|
|
8
|
+
Project-URL: Issues, https://github.com/AyushSonuu/memharness/issues
|
|
9
|
+
Author-email: Ayush Sonuu <sonuayush55@gmail.com>
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: agents,ai,langchain,llm,memory,rag,vector-database
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
19
|
+
Requires-Python: <4.0,>=3.13
|
|
20
|
+
Requires-Dist: aiosqlite>=0.20.0
|
|
21
|
+
Requires-Dist: numpy>=2.0.0
|
|
22
|
+
Requires-Dist: pydantic>=2.10.0
|
|
23
|
+
Requires-Dist: pyyaml>=6.0.2
|
|
24
|
+
Provides-Extra: all
|
|
25
|
+
Requires-Dist: anthropic>=0.86.0; extra == 'all'
|
|
26
|
+
Requires-Dist: asyncpg>=0.31.0; extra == 'all'
|
|
27
|
+
Requires-Dist: langchain-core>=0.3.0; extra == 'all'
|
|
28
|
+
Requires-Dist: langchain>=1.2.13; extra == 'all'
|
|
29
|
+
Requires-Dist: openai>=2.29.0; extra == 'all'
|
|
30
|
+
Requires-Dist: pgvector>=0.4.2; extra == 'all'
|
|
31
|
+
Requires-Dist: sentence-transformers>=5.3.0; extra == 'all'
|
|
32
|
+
Provides-Extra: anthropic
|
|
33
|
+
Requires-Dist: anthropic>=0.86.0; extra == 'anthropic'
|
|
34
|
+
Provides-Extra: dev
|
|
35
|
+
Requires-Dist: mypy>=1.15.0; extra == 'dev'
|
|
36
|
+
Requires-Dist: pytest-asyncio>=0.24.0; extra == 'dev'
|
|
37
|
+
Requires-Dist: pytest-cov>=6.0.0; extra == 'dev'
|
|
38
|
+
Requires-Dist: pytest>=8.0.0; extra == 'dev'
|
|
39
|
+
Requires-Dist: ruff>=0.9.0; extra == 'dev'
|
|
40
|
+
Provides-Extra: embeddings
|
|
41
|
+
Requires-Dist: sentence-transformers>=5.3.0; extra == 'embeddings'
|
|
42
|
+
Provides-Extra: langchain
|
|
43
|
+
Requires-Dist: langchain-core>=0.3.0; extra == 'langchain'
|
|
44
|
+
Requires-Dist: langchain>=1.2.13; extra == 'langchain'
|
|
45
|
+
Provides-Extra: openai
|
|
46
|
+
Requires-Dist: openai>=2.29.0; extra == 'openai'
|
|
47
|
+
Provides-Extra: postgres
|
|
48
|
+
Requires-Dist: asyncpg>=0.31.0; extra == 'postgres'
|
|
49
|
+
Requires-Dist: pgvector>=0.4.2; extra == 'postgres'
|
|
50
|
+
Description-Content-Type: text/markdown
|
|
51
|
+
|
|
52
|
+
# memharness
|
|
53
|
+
|
|
54
|
+
> Framework-agnostic memory infrastructure for AI agents
|
|
55
|
+
|
|
56
|
+
[](https://badge.fury.io/py/memharness)
|
|
57
|
+
[](https://www.python.org/downloads/)
|
|
58
|
+
[](https://opensource.org/licenses/MIT)
|
|
59
|
+
[](https://github.com/AyushSonuu/memharness/actions/workflows/test.yml)
|
|
60
|
+
|
|
61
|
+
## Overview
|
|
62
|
+
|
|
63
|
+
**memharness** is a complete memory infrastructure layer for AI agents. It provides:
|
|
64
|
+
|
|
65
|
+
- **10 Memory Types**: Conversational, Knowledge Base, Entity, Workflow, Toolbox, Summary, Tool Log, Skills, File, Persona
|
|
66
|
+
- **Multiple Backends**: PostgreSQL + pgvector, SQLite + sqlite-vss, In-memory
|
|
67
|
+
- **Framework Agnostic**: Works with LangChain, LangGraph, CrewAI, or any custom agent
|
|
68
|
+
- **Deterministic + AI Operations**: Simple ops are deterministic, complex ops use embedded agents
|
|
69
|
+
- **Self-Exploration Tools**: Agents can explore and manage their own memory
|
|
70
|
+
- **Fully Configurable**: All thresholds, schedules, TTLs configurable via YAML or code
|
|
71
|
+
|
|
72
|
+
## Installation
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
# Core (SQLite backend)
|
|
76
|
+
pip install memharness
|
|
77
|
+
|
|
78
|
+
# With PostgreSQL support
|
|
79
|
+
pip install memharness[postgres]
|
|
80
|
+
|
|
81
|
+
# With embedding support
|
|
82
|
+
pip install memharness[embeddings]
|
|
83
|
+
|
|
84
|
+
# Everything
|
|
85
|
+
pip install memharness[all]
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Quick Start
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
from memharness import MemoryHarness
|
|
92
|
+
|
|
93
|
+
# Initialize with SQLite (development)
|
|
94
|
+
memory = MemoryHarness("sqlite:///memory.db")
|
|
95
|
+
|
|
96
|
+
# Or PostgreSQL (production)
|
|
97
|
+
memory = MemoryHarness("postgresql://user:pass@localhost/db")
|
|
98
|
+
|
|
99
|
+
# Write conversational memory (deterministic)
|
|
100
|
+
await memory.add_conversational(
|
|
101
|
+
thread_id="chat_001",
|
|
102
|
+
role="user",
|
|
103
|
+
content="How do I deploy to Kubernetes?"
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
# Write knowledge base (deterministic)
|
|
107
|
+
await memory.add_knowledge(
|
|
108
|
+
content="Kubernetes deployment guide...",
|
|
109
|
+
source="k8s-docs",
|
|
110
|
+
metadata={"category": "devops"}
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
# Search knowledge base (semantic search)
|
|
114
|
+
results = await memory.search_knowledge(
|
|
115
|
+
query="container orchestration",
|
|
116
|
+
k=5
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
# Get curated context for LLM
|
|
120
|
+
context = await memory.assemble_context(
|
|
121
|
+
query="deploy my app",
|
|
122
|
+
thread_id="chat_001",
|
|
123
|
+
max_tokens=4000
|
|
124
|
+
)
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Memory Types
|
|
128
|
+
|
|
129
|
+
| Type | Storage | Purpose |
|
|
130
|
+
|------|---------|---------|
|
|
131
|
+
| **Conversational** | SQL | Chat history per thread |
|
|
132
|
+
| **Knowledge Base** | Vector | Documents, facts, reference material |
|
|
133
|
+
| **Entity** | Vector | People, organizations, systems, concepts |
|
|
134
|
+
| **Workflow** | Vector | Reusable step-by-step patterns |
|
|
135
|
+
| **Toolbox** | Vector | Tool definitions with VFS discovery |
|
|
136
|
+
| **Summary** | Vector | Compressed conversations (expandable) |
|
|
137
|
+
| **Tool Log** | SQL | Tool execution audit trail |
|
|
138
|
+
| **Skills** | Vector | Learned agent capabilities |
|
|
139
|
+
| **File** | Hybrid | Document references |
|
|
140
|
+
| **Persona** | Vector | Agent identity blocks |
|
|
141
|
+
|
|
142
|
+
## Embedded Agents
|
|
143
|
+
|
|
144
|
+
memharness includes specialized agents for complex memory operations:
|
|
145
|
+
|
|
146
|
+
```python
|
|
147
|
+
from memharness import MemoryHarness
|
|
148
|
+
from memharness.agents import AgentConfig
|
|
149
|
+
|
|
150
|
+
memory = MemoryHarness(
|
|
151
|
+
backend="postgresql://...",
|
|
152
|
+
llm=your_llm, # Optional: for AI-powered operations
|
|
153
|
+
agents=AgentConfig(
|
|
154
|
+
summarizer={"enabled": True, "triggers": [{"condition": "age > 7d"}]},
|
|
155
|
+
entity_extractor={"enabled": True, "on_write": True},
|
|
156
|
+
consolidator={"enabled": True, "schedule": "0 3 * * *"},
|
|
157
|
+
gc={"enabled": True, "schedule": "0 4 * * 0"},
|
|
158
|
+
)
|
|
159
|
+
)
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## Memory Tools (Self-Exploration)
|
|
163
|
+
|
|
164
|
+
Agents can explore their own memory using built-in tools:
|
|
165
|
+
|
|
166
|
+
```python
|
|
167
|
+
# Get tools for your agent
|
|
168
|
+
tools = memory.get_memory_tools()
|
|
169
|
+
|
|
170
|
+
# Tools include:
|
|
171
|
+
# - memory_search: Search across memory types
|
|
172
|
+
# - memory_read: Read specific memory by ID
|
|
173
|
+
# - memory_write: Write new memory
|
|
174
|
+
# - memory_stats: Get memory statistics
|
|
175
|
+
# - toolbox_tree: Explore tool VFS
|
|
176
|
+
# - toolbox_grep: Search tools by pattern
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
## Configuration
|
|
180
|
+
|
|
181
|
+
```yaml
|
|
182
|
+
# memharness.yaml
|
|
183
|
+
backend: postgresql://localhost/memharness
|
|
184
|
+
|
|
185
|
+
summarization:
|
|
186
|
+
enabled: true
|
|
187
|
+
triggers:
|
|
188
|
+
- condition: "age > 7d"
|
|
189
|
+
memory_type: conversational
|
|
190
|
+
keep_originals: true
|
|
191
|
+
originals_ttl: 365d
|
|
192
|
+
|
|
193
|
+
consolidation:
|
|
194
|
+
enabled: true
|
|
195
|
+
schedule: "0 3 * * *"
|
|
196
|
+
similarity_threshold: 0.9
|
|
197
|
+
|
|
198
|
+
gc:
|
|
199
|
+
enabled: true
|
|
200
|
+
schedule: "0 4 * * 0"
|
|
201
|
+
archive_after: 90d
|
|
202
|
+
delete_after: 365d
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
```python
|
|
206
|
+
memory = MemoryHarness.from_config("memharness.yaml")
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
## Framework Integrations
|
|
210
|
+
|
|
211
|
+
### LangChain
|
|
212
|
+
|
|
213
|
+
```python
|
|
214
|
+
from memharness.integrations.langchain import MemharnessMemory
|
|
215
|
+
|
|
216
|
+
memory = MemharnessMemory(backend="postgresql://...")
|
|
217
|
+
chain = ConversationChain(llm=llm, memory=memory)
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
### LangGraph
|
|
221
|
+
|
|
222
|
+
```python
|
|
223
|
+
from memharness.integrations.langgraph import MemharnessCheckpointer
|
|
224
|
+
|
|
225
|
+
checkpointer = MemharnessCheckpointer(backend="postgresql://...")
|
|
226
|
+
graph = builder.compile(checkpointer=checkpointer)
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
## Documentation
|
|
230
|
+
|
|
231
|
+
Full documentation: [https://ayushsonuu.github.io/memharness](https://ayushsonuu.github.io/memharness)
|
|
232
|
+
|
|
233
|
+
## License
|
|
234
|
+
|
|
235
|
+
MIT License - see [LICENSE](LICENSE) for details.
|
|
236
|
+
|
|
237
|
+
## Contributing
|
|
238
|
+
|
|
239
|
+
Contributions welcome! Please read our [Contributing Guide](CONTRIBUTING.md).
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
# memharness
|
|
2
|
+
|
|
3
|
+
> Framework-agnostic memory infrastructure for AI agents
|
|
4
|
+
|
|
5
|
+
[](https://badge.fury.io/py/memharness)
|
|
6
|
+
[](https://www.python.org/downloads/)
|
|
7
|
+
[](https://opensource.org/licenses/MIT)
|
|
8
|
+
[](https://github.com/AyushSonuu/memharness/actions/workflows/test.yml)
|
|
9
|
+
|
|
10
|
+
## Overview
|
|
11
|
+
|
|
12
|
+
**memharness** is a complete memory infrastructure layer for AI agents. It provides:
|
|
13
|
+
|
|
14
|
+
- **10 Memory Types**: Conversational, Knowledge Base, Entity, Workflow, Toolbox, Summary, Tool Log, Skills, File, Persona
|
|
15
|
+
- **Multiple Backends**: PostgreSQL + pgvector, SQLite + sqlite-vss, In-memory
|
|
16
|
+
- **Framework Agnostic**: Works with LangChain, LangGraph, CrewAI, or any custom agent
|
|
17
|
+
- **Deterministic + AI Operations**: Simple ops are deterministic, complex ops use embedded agents
|
|
18
|
+
- **Self-Exploration Tools**: Agents can explore and manage their own memory
|
|
19
|
+
- **Fully Configurable**: All thresholds, schedules, TTLs configurable via YAML or code
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
# Core (SQLite backend)
|
|
25
|
+
pip install memharness
|
|
26
|
+
|
|
27
|
+
# With PostgreSQL support
|
|
28
|
+
pip install memharness[postgres]
|
|
29
|
+
|
|
30
|
+
# With embedding support
|
|
31
|
+
pip install memharness[embeddings]
|
|
32
|
+
|
|
33
|
+
# Everything
|
|
34
|
+
pip install memharness[all]
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Quick Start
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
from memharness import MemoryHarness
|
|
41
|
+
|
|
42
|
+
# Initialize with SQLite (development)
|
|
43
|
+
memory = MemoryHarness("sqlite:///memory.db")
|
|
44
|
+
|
|
45
|
+
# Or PostgreSQL (production)
|
|
46
|
+
memory = MemoryHarness("postgresql://user:pass@localhost/db")
|
|
47
|
+
|
|
48
|
+
# Write conversational memory (deterministic)
|
|
49
|
+
await memory.add_conversational(
|
|
50
|
+
thread_id="chat_001",
|
|
51
|
+
role="user",
|
|
52
|
+
content="How do I deploy to Kubernetes?"
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
# Write knowledge base (deterministic)
|
|
56
|
+
await memory.add_knowledge(
|
|
57
|
+
content="Kubernetes deployment guide...",
|
|
58
|
+
source="k8s-docs",
|
|
59
|
+
metadata={"category": "devops"}
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
# Search knowledge base (semantic search)
|
|
63
|
+
results = await memory.search_knowledge(
|
|
64
|
+
query="container orchestration",
|
|
65
|
+
k=5
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
# Get curated context for LLM
|
|
69
|
+
context = await memory.assemble_context(
|
|
70
|
+
query="deploy my app",
|
|
71
|
+
thread_id="chat_001",
|
|
72
|
+
max_tokens=4000
|
|
73
|
+
)
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Memory Types
|
|
77
|
+
|
|
78
|
+
| Type | Storage | Purpose |
|
|
79
|
+
|------|---------|---------|
|
|
80
|
+
| **Conversational** | SQL | Chat history per thread |
|
|
81
|
+
| **Knowledge Base** | Vector | Documents, facts, reference material |
|
|
82
|
+
| **Entity** | Vector | People, organizations, systems, concepts |
|
|
83
|
+
| **Workflow** | Vector | Reusable step-by-step patterns |
|
|
84
|
+
| **Toolbox** | Vector | Tool definitions with VFS discovery |
|
|
85
|
+
| **Summary** | Vector | Compressed conversations (expandable) |
|
|
86
|
+
| **Tool Log** | SQL | Tool execution audit trail |
|
|
87
|
+
| **Skills** | Vector | Learned agent capabilities |
|
|
88
|
+
| **File** | Hybrid | Document references |
|
|
89
|
+
| **Persona** | Vector | Agent identity blocks |
|
|
90
|
+
|
|
91
|
+
## Embedded Agents
|
|
92
|
+
|
|
93
|
+
memharness includes specialized agents for complex memory operations:
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
from memharness import MemoryHarness
|
|
97
|
+
from memharness.agents import AgentConfig
|
|
98
|
+
|
|
99
|
+
memory = MemoryHarness(
|
|
100
|
+
backend="postgresql://...",
|
|
101
|
+
llm=your_llm, # Optional: for AI-powered operations
|
|
102
|
+
agents=AgentConfig(
|
|
103
|
+
summarizer={"enabled": True, "triggers": [{"condition": "age > 7d"}]},
|
|
104
|
+
entity_extractor={"enabled": True, "on_write": True},
|
|
105
|
+
consolidator={"enabled": True, "schedule": "0 3 * * *"},
|
|
106
|
+
gc={"enabled": True, "schedule": "0 4 * * 0"},
|
|
107
|
+
)
|
|
108
|
+
)
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## Memory Tools (Self-Exploration)
|
|
112
|
+
|
|
113
|
+
Agents can explore their own memory using built-in tools:
|
|
114
|
+
|
|
115
|
+
```python
|
|
116
|
+
# Get tools for your agent
|
|
117
|
+
tools = memory.get_memory_tools()
|
|
118
|
+
|
|
119
|
+
# Tools include:
|
|
120
|
+
# - memory_search: Search across memory types
|
|
121
|
+
# - memory_read: Read specific memory by ID
|
|
122
|
+
# - memory_write: Write new memory
|
|
123
|
+
# - memory_stats: Get memory statistics
|
|
124
|
+
# - toolbox_tree: Explore tool VFS
|
|
125
|
+
# - toolbox_grep: Search tools by pattern
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Configuration
|
|
129
|
+
|
|
130
|
+
```yaml
|
|
131
|
+
# memharness.yaml
|
|
132
|
+
backend: postgresql://localhost/memharness
|
|
133
|
+
|
|
134
|
+
summarization:
|
|
135
|
+
enabled: true
|
|
136
|
+
triggers:
|
|
137
|
+
- condition: "age > 7d"
|
|
138
|
+
memory_type: conversational
|
|
139
|
+
keep_originals: true
|
|
140
|
+
originals_ttl: 365d
|
|
141
|
+
|
|
142
|
+
consolidation:
|
|
143
|
+
enabled: true
|
|
144
|
+
schedule: "0 3 * * *"
|
|
145
|
+
similarity_threshold: 0.9
|
|
146
|
+
|
|
147
|
+
gc:
|
|
148
|
+
enabled: true
|
|
149
|
+
schedule: "0 4 * * 0"
|
|
150
|
+
archive_after: 90d
|
|
151
|
+
delete_after: 365d
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
```python
|
|
155
|
+
memory = MemoryHarness.from_config("memharness.yaml")
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
## Framework Integrations
|
|
159
|
+
|
|
160
|
+
### LangChain
|
|
161
|
+
|
|
162
|
+
```python
|
|
163
|
+
from memharness.integrations.langchain import MemharnessMemory
|
|
164
|
+
|
|
165
|
+
memory = MemharnessMemory(backend="postgresql://...")
|
|
166
|
+
chain = ConversationChain(llm=llm, memory=memory)
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### LangGraph
|
|
170
|
+
|
|
171
|
+
```python
|
|
172
|
+
from memharness.integrations.langgraph import MemharnessCheckpointer
|
|
173
|
+
|
|
174
|
+
checkpointer = MemharnessCheckpointer(backend="postgresql://...")
|
|
175
|
+
graph = builder.compile(checkpointer=checkpointer)
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
## Documentation
|
|
179
|
+
|
|
180
|
+
Full documentation: [https://ayushsonuu.github.io/memharness](https://ayushsonuu.github.io/memharness)
|
|
181
|
+
|
|
182
|
+
## License
|
|
183
|
+
|
|
184
|
+
MIT License - see [LICENSE](LICENSE) for details.
|
|
185
|
+
|
|
186
|
+
## Contributing
|
|
187
|
+
|
|
188
|
+
Contributions welcome! Please read our [Contributing Guide](CONTRIBUTING.md).
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "memharness"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Framework-agnostic memory infrastructure for AI agents"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
requires-python = ">=3.13,<4.0"
|
|
12
|
+
authors = [
|
|
13
|
+
{ name = "Ayush Sonuu", email = "sonuayush55@gmail.com" }
|
|
14
|
+
]
|
|
15
|
+
keywords = [
|
|
16
|
+
"ai",
|
|
17
|
+
"agents",
|
|
18
|
+
"memory",
|
|
19
|
+
"llm",
|
|
20
|
+
"langchain",
|
|
21
|
+
"vector-database",
|
|
22
|
+
"rag",
|
|
23
|
+
]
|
|
24
|
+
classifiers = [
|
|
25
|
+
"Development Status :: 4 - Beta",
|
|
26
|
+
"Intended Audience :: Developers",
|
|
27
|
+
"License :: OSI Approved :: MIT License",
|
|
28
|
+
"Programming Language :: Python :: 3",
|
|
29
|
+
"Programming Language :: Python :: 3.13",
|
|
30
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
31
|
+
]
|
|
32
|
+
dependencies = [
|
|
33
|
+
"pydantic>=2.10.0",
|
|
34
|
+
"aiosqlite>=0.20.0",
|
|
35
|
+
"numpy>=2.0.0",
|
|
36
|
+
"pyyaml>=6.0.2",
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
[project.optional-dependencies]
|
|
40
|
+
postgres = [
|
|
41
|
+
"asyncpg>=0.31.0",
|
|
42
|
+
"pgvector>=0.4.2",
|
|
43
|
+
]
|
|
44
|
+
embeddings = [
|
|
45
|
+
"sentence-transformers>=5.3.0",
|
|
46
|
+
]
|
|
47
|
+
openai = [
|
|
48
|
+
"openai>=2.29.0",
|
|
49
|
+
]
|
|
50
|
+
anthropic = [
|
|
51
|
+
"anthropic>=0.86.0",
|
|
52
|
+
]
|
|
53
|
+
langchain = [
|
|
54
|
+
"langchain>=1.2.13",
|
|
55
|
+
"langchain-core>=0.3.0",
|
|
56
|
+
]
|
|
57
|
+
all = [
|
|
58
|
+
"asyncpg>=0.31.0",
|
|
59
|
+
"pgvector>=0.4.2",
|
|
60
|
+
"sentence-transformers>=5.3.0",
|
|
61
|
+
"openai>=2.29.0",
|
|
62
|
+
"anthropic>=0.86.0",
|
|
63
|
+
"langchain>=1.2.13",
|
|
64
|
+
"langchain-core>=0.3.0",
|
|
65
|
+
]
|
|
66
|
+
dev = [
|
|
67
|
+
"pytest>=8.0.0",
|
|
68
|
+
"pytest-asyncio>=0.24.0",
|
|
69
|
+
"pytest-cov>=6.0.0",
|
|
70
|
+
"ruff>=0.9.0",
|
|
71
|
+
"mypy>=1.15.0",
|
|
72
|
+
]
|
|
73
|
+
|
|
74
|
+
[project.urls]
|
|
75
|
+
Homepage = "https://github.com/AyushSonuu/memharness"
|
|
76
|
+
Documentation = "https://ayushsonuu.github.io/memharness"
|
|
77
|
+
Repository = "https://github.com/AyushSonuu/memharness"
|
|
78
|
+
Issues = "https://github.com/AyushSonuu/memharness/issues"
|
|
79
|
+
|
|
80
|
+
[tool.hatch.build.targets.wheel]
|
|
81
|
+
packages = ["src/memharness"]
|
|
82
|
+
|
|
83
|
+
[tool.hatch.build.targets.sdist]
|
|
84
|
+
include = [
|
|
85
|
+
"/src",
|
|
86
|
+
"/tests",
|
|
87
|
+
"/README.md",
|
|
88
|
+
"/LICENSE",
|
|
89
|
+
]
|
|
90
|
+
|
|
91
|
+
[tool.pytest.ini_options]
|
|
92
|
+
asyncio_mode = "auto"
|
|
93
|
+
testpaths = ["tests"]
|
|
94
|
+
addopts = "-v --cov=memharness --cov-report=term-missing"
|
|
95
|
+
|
|
96
|
+
[tool.ruff]
|
|
97
|
+
target-version = "py313"
|
|
98
|
+
line-length = 100
|
|
99
|
+
|
|
100
|
+
[tool.ruff.lint]
|
|
101
|
+
select = [
|
|
102
|
+
"E", # pycodestyle errors
|
|
103
|
+
"W", # pycodestyle warnings
|
|
104
|
+
"F", # pyflakes
|
|
105
|
+
"I", # isort
|
|
106
|
+
"B", # flake8-bugbear
|
|
107
|
+
"C4", # flake8-comprehensions
|
|
108
|
+
"UP", # pyupgrade
|
|
109
|
+
]
|
|
110
|
+
ignore = [
|
|
111
|
+
"E501", # line too long
|
|
112
|
+
"B008", # do not perform function calls in argument defaults
|
|
113
|
+
"B017", # do not assert blind exception
|
|
114
|
+
"UP042", # prefer StrEnum (keep str, Enum for 3.10 compat docs)
|
|
115
|
+
]
|
|
116
|
+
|
|
117
|
+
[tool.mypy]
|
|
118
|
+
python_version = "3.13"
|
|
119
|
+
warn_return_any = true
|
|
120
|
+
warn_unused_ignores = true
|
|
121
|
+
disallow_untyped_defs = true
|
|
122
|
+
|
|
123
|
+
[tool.black]
|
|
124
|
+
line-length = 100
|
|
125
|
+
target-version = ["py313"]
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# memharness - Framework-agnostic memory infrastructure for AI agents
|
|
2
|
+
# Copyright (c) 2026 Ayush Sonuu
|
|
3
|
+
# Licensed under MIT License
|
|
4
|
+
|
|
5
|
+
"""
|
|
6
|
+
memharness - Framework-agnostic memory infrastructure for AI agents.
|
|
7
|
+
|
|
8
|
+
This package provides a complete memory layer for AI agents with:
|
|
9
|
+
- 10 memory types (Conversational, KB, Entity, Workflow, Toolbox, Summary, ToolLog, Skills, File, Persona)
|
|
10
|
+
- Multiple backends (PostgreSQL, SQLite, In-memory)
|
|
11
|
+
- Embedded AI agents for complex operations
|
|
12
|
+
- Self-exploration tools for agents
|
|
13
|
+
- Full configurability
|
|
14
|
+
|
|
15
|
+
Quick Start:
|
|
16
|
+
from memharness import MemoryHarness
|
|
17
|
+
|
|
18
|
+
memory = MemoryHarness("sqlite:///memory.db")
|
|
19
|
+
await memory.add_conversational(thread_id="t1", role="user", content="Hello")
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
from memharness.config import Config, MemharnessConfig
|
|
23
|
+
from memharness.core.harness import MemoryHarness
|
|
24
|
+
from memharness.registry import MemoryTypeRegistry
|
|
25
|
+
from memharness.types import MemoryType, MemoryUnit
|
|
26
|
+
|
|
27
|
+
__version__ = "0.1.0"
|
|
28
|
+
__author__ = "Ayush Sonuu"
|
|
29
|
+
__license__ = "MIT"
|
|
30
|
+
|
|
31
|
+
__all__ = [
|
|
32
|
+
"MemoryHarness",
|
|
33
|
+
"MemoryUnit",
|
|
34
|
+
"MemoryType",
|
|
35
|
+
"Config",
|
|
36
|
+
"MemharnessConfig",
|
|
37
|
+
"MemoryTypeRegistry",
|
|
38
|
+
"__version__",
|
|
39
|
+
]
|