alma-memory 0.5.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.
Files changed (81) hide show
  1. alma_memory-0.5.0/PKG-INFO +905 -0
  2. alma_memory-0.5.0/README.md +849 -0
  3. alma_memory-0.5.0/alma/__init__.py +194 -0
  4. alma_memory-0.5.0/alma/confidence/__init__.py +47 -0
  5. alma_memory-0.5.0/alma/confidence/engine.py +540 -0
  6. alma_memory-0.5.0/alma/confidence/types.py +351 -0
  7. alma_memory-0.5.0/alma/config/__init__.py +5 -0
  8. alma_memory-0.5.0/alma/config/loader.py +157 -0
  9. alma_memory-0.5.0/alma/consolidation/__init__.py +23 -0
  10. alma_memory-0.5.0/alma/consolidation/engine.py +678 -0
  11. alma_memory-0.5.0/alma/consolidation/prompts.py +84 -0
  12. alma_memory-0.5.0/alma/core.py +322 -0
  13. alma_memory-0.5.0/alma/domains/__init__.py +30 -0
  14. alma_memory-0.5.0/alma/domains/factory.py +359 -0
  15. alma_memory-0.5.0/alma/domains/schemas.py +448 -0
  16. alma_memory-0.5.0/alma/domains/types.py +272 -0
  17. alma_memory-0.5.0/alma/events/__init__.py +75 -0
  18. alma_memory-0.5.0/alma/events/emitter.py +284 -0
  19. alma_memory-0.5.0/alma/events/storage_mixin.py +246 -0
  20. alma_memory-0.5.0/alma/events/types.py +126 -0
  21. alma_memory-0.5.0/alma/events/webhook.py +425 -0
  22. alma_memory-0.5.0/alma/exceptions.py +49 -0
  23. alma_memory-0.5.0/alma/extraction/__init__.py +31 -0
  24. alma_memory-0.5.0/alma/extraction/auto_learner.py +264 -0
  25. alma_memory-0.5.0/alma/extraction/extractor.py +420 -0
  26. alma_memory-0.5.0/alma/graph/__init__.py +81 -0
  27. alma_memory-0.5.0/alma/graph/backends/__init__.py +18 -0
  28. alma_memory-0.5.0/alma/graph/backends/memory.py +236 -0
  29. alma_memory-0.5.0/alma/graph/backends/neo4j.py +417 -0
  30. alma_memory-0.5.0/alma/graph/base.py +159 -0
  31. alma_memory-0.5.0/alma/graph/extraction.py +198 -0
  32. alma_memory-0.5.0/alma/graph/store.py +860 -0
  33. alma_memory-0.5.0/alma/harness/__init__.py +35 -0
  34. alma_memory-0.5.0/alma/harness/base.py +386 -0
  35. alma_memory-0.5.0/alma/harness/domains.py +705 -0
  36. alma_memory-0.5.0/alma/initializer/__init__.py +37 -0
  37. alma_memory-0.5.0/alma/initializer/initializer.py +418 -0
  38. alma_memory-0.5.0/alma/initializer/types.py +250 -0
  39. alma_memory-0.5.0/alma/integration/__init__.py +62 -0
  40. alma_memory-0.5.0/alma/integration/claude_agents.py +432 -0
  41. alma_memory-0.5.0/alma/integration/helena.py +423 -0
  42. alma_memory-0.5.0/alma/integration/victor.py +471 -0
  43. alma_memory-0.5.0/alma/learning/__init__.py +86 -0
  44. alma_memory-0.5.0/alma/learning/forgetting.py +1446 -0
  45. alma_memory-0.5.0/alma/learning/heuristic_extractor.py +390 -0
  46. alma_memory-0.5.0/alma/learning/protocols.py +374 -0
  47. alma_memory-0.5.0/alma/learning/validation.py +346 -0
  48. alma_memory-0.5.0/alma/mcp/__init__.py +45 -0
  49. alma_memory-0.5.0/alma/mcp/__main__.py +156 -0
  50. alma_memory-0.5.0/alma/mcp/resources.py +122 -0
  51. alma_memory-0.5.0/alma/mcp/server.py +591 -0
  52. alma_memory-0.5.0/alma/mcp/tools.py +511 -0
  53. alma_memory-0.5.0/alma/progress/__init__.py +21 -0
  54. alma_memory-0.5.0/alma/progress/tracker.py +607 -0
  55. alma_memory-0.5.0/alma/progress/types.py +250 -0
  56. alma_memory-0.5.0/alma/py.typed +0 -0
  57. alma_memory-0.5.0/alma/retrieval/__init__.py +53 -0
  58. alma_memory-0.5.0/alma/retrieval/cache.py +1061 -0
  59. alma_memory-0.5.0/alma/retrieval/embeddings.py +202 -0
  60. alma_memory-0.5.0/alma/retrieval/engine.py +366 -0
  61. alma_memory-0.5.0/alma/retrieval/scoring.py +344 -0
  62. alma_memory-0.5.0/alma/session/__init__.py +19 -0
  63. alma_memory-0.5.0/alma/session/manager.py +399 -0
  64. alma_memory-0.5.0/alma/session/types.py +288 -0
  65. alma_memory-0.5.0/alma/storage/__init__.py +61 -0
  66. alma_memory-0.5.0/alma/storage/azure_cosmos.py +1048 -0
  67. alma_memory-0.5.0/alma/storage/base.py +525 -0
  68. alma_memory-0.5.0/alma/storage/chroma.py +1443 -0
  69. alma_memory-0.5.0/alma/storage/file_based.py +619 -0
  70. alma_memory-0.5.0/alma/storage/pinecone.py +1080 -0
  71. alma_memory-0.5.0/alma/storage/postgresql.py +1452 -0
  72. alma_memory-0.5.0/alma/storage/qdrant.py +1306 -0
  73. alma_memory-0.5.0/alma/storage/sqlite_local.py +1358 -0
  74. alma_memory-0.5.0/alma/types.py +264 -0
  75. alma_memory-0.5.0/alma_memory.egg-info/PKG-INFO +905 -0
  76. alma_memory-0.5.0/alma_memory.egg-info/SOURCES.txt +79 -0
  77. alma_memory-0.5.0/alma_memory.egg-info/dependency_links.txt +1 -0
  78. alma_memory-0.5.0/alma_memory.egg-info/requires.txt +43 -0
  79. alma_memory-0.5.0/alma_memory.egg-info/top_level.txt +1 -0
  80. alma_memory-0.5.0/pyproject.toml +154 -0
  81. alma_memory-0.5.0/setup.cfg +4 -0
@@ -0,0 +1,905 @@
1
+ Metadata-Version: 2.4
2
+ Name: alma-memory
3
+ Version: 0.5.0
4
+ Summary: Agent Learning Memory Architecture - Persistent memory for AI agents
5
+ Author-email: RBKunnela <aiagentsprompt@gmail.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/RBKunnela/ALMA-memory
8
+ Project-URL: Documentation, https://github.com/RBKunnela/ALMA-memory/tree/main/docs
9
+ Project-URL: Repository, https://github.com/RBKunnela/ALMA-memory
10
+ Project-URL: Issues, https://github.com/RBKunnela/ALMA-memory/issues
11
+ Keywords: ai,agents,memory,learning,llm,azure,claude
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
20
+ Requires-Python: >=3.10
21
+ Description-Content-Type: text/markdown
22
+ Requires-Dist: pyyaml>=6.0
23
+ Requires-Dist: python-dotenv>=1.0.0
24
+ Provides-Extra: local
25
+ Requires-Dist: sentence-transformers>=2.2.0; extra == "local"
26
+ Requires-Dist: faiss-cpu>=1.7.4; extra == "local"
27
+ Provides-Extra: azure
28
+ Requires-Dist: azure-cosmos>=4.5.0; extra == "azure"
29
+ Requires-Dist: azure-identity>=1.15.0; extra == "azure"
30
+ Requires-Dist: azure-keyvault-secrets>=4.7.0; extra == "azure"
31
+ Requires-Dist: openai>=1.0.0; extra == "azure"
32
+ Provides-Extra: postgres
33
+ Requires-Dist: psycopg[binary,pool]>=3.1.0; extra == "postgres"
34
+ Requires-Dist: numpy>=1.24.0; extra == "postgres"
35
+ Provides-Extra: qdrant
36
+ Requires-Dist: qdrant-client>=1.7.0; extra == "qdrant"
37
+ Provides-Extra: chroma
38
+ Requires-Dist: chromadb>=0.4.0; extra == "chroma"
39
+ Provides-Extra: pinecone
40
+ Requires-Dist: pinecone>=3.0.0; extra == "pinecone"
41
+ Provides-Extra: mcp
42
+ Requires-Dist: pydantic>=2.0.0; extra == "mcp"
43
+ Requires-Dist: aiohttp>=3.9.0; extra == "mcp"
44
+ Provides-Extra: dev
45
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
46
+ Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
47
+ Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
48
+ Requires-Dist: pytest-benchmark>=4.0.0; extra == "dev"
49
+ Requires-Dist: mypy>=1.0.0; extra == "dev"
50
+ Requires-Dist: ruff>=0.1.0; extra == "dev"
51
+ Requires-Dist: black>=24.0.0; extra == "dev"
52
+ Requires-Dist: bandit[toml]>=1.7.0; extra == "dev"
53
+ Requires-Dist: numpy>=1.24.0; extra == "dev"
54
+ Provides-Extra: all
55
+ Requires-Dist: alma-memory[azure,chroma,dev,local,mcp,pinecone,postgres,qdrant]; extra == "all"
56
+
57
+ # ALMA - Agent Learning Memory Architecture
58
+
59
+ [![PyPI version](https://badge.fury.io/py/alma-memory.svg)](https://pypi.org/project/alma-memory/)
60
+ [![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
61
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
62
+ [![CI](https://github.com/RBKunnela/ALMA-memory/actions/workflows/ci.yml/badge.svg)](https://github.com/RBKunnela/ALMA-memory/actions/workflows/ci.yml)
63
+ [![Code style: ruff](https://img.shields.io/badge/code%20style-ruff-000000.svg)](https://github.com/astral-sh/ruff)
64
+
65
+ > Persistent memory for AI agents that learn and improve over time - without model weight updates.
66
+
67
+ ---
68
+
69
+ ## Why ALMA? Key Differentiators
70
+
71
+ ALMA isn't just another memory framework. Here's what sets it apart from alternatives like Mem0:
72
+
73
+ | Feature | ALMA | Mem0 | Why It Matters |
74
+ |---------|------|------|----------------|
75
+ | **Memory Scoping** | `can_learn` / `cannot_learn` per agent | Basic user/session isolation | Prevents agents from learning outside their domain |
76
+ | **Anti-Pattern Learning** | Explicit with `why_bad` + `better_alternative` | None | Agents learn what NOT to do |
77
+ | **Multi-Agent Sharing** | `inherit_from` + `share_with` scopes | None | Agents can share knowledge hierarchically |
78
+ | **Memory Consolidation** | LLM-powered deduplication | Basic | Intelligent merge of similar memories |
79
+ | **Event System** | Webhooks + in-process callbacks | None | React to memory changes in real-time |
80
+ | **TypeScript SDK** | Full-featured client library | None | First-class JavaScript/TypeScript support |
81
+ | **Vector DB Support** | 6 backends (PostgreSQL, Qdrant, Pinecone, Chroma, SQLite, Azure) | Limited | Deploy anywhere |
82
+ | **Graph Memory** | Pluggable backends (Neo4j, In-memory) | Limited | Entity relationship tracking |
83
+ | **Harness Pattern** | Decouples agent from domain memory | None | Reusable agent architecture |
84
+ | **MCP Integration** | Native stdio/HTTP server | None | Direct Claude Code integration |
85
+ | **Domain Memory Factory** | 6 pre-built schemas | None | Instant setup for any domain |
86
+ | **Multi-Factor Scoring** | Similarity + Recency + Success + Confidence | Primarily vector + recency | More nuanced retrieval |
87
+
88
+ **Bottom line:** ALMA is purpose-built for AI agents that need to learn, remember, and improve - not just store and retrieve.
89
+
90
+ ---
91
+
92
+ ## What's New in v0.5.0
93
+
94
+ ### Phase 2: Vector Database Backends
95
+
96
+ - **Qdrant Backend** (`alma/storage/qdrant.py`)
97
+ - Full StorageBackend implementation with vector similarity search
98
+ - Metadata filtering for all queries
99
+ - Optimized `MatchAny` queries for multi-agent memory sharing
100
+
101
+ - **Pinecone Backend** (`alma/storage/pinecone.py`)
102
+ - Namespace-based organization per memory type
103
+ - Serverless spec support for automatic scaling
104
+ - Environment variable expansion in configuration
105
+
106
+ - **Chroma Backend** (`alma/storage/chroma.py`)
107
+ - Persistent, client-server, and ephemeral modes
108
+ - Native embedding storage and similarity search
109
+ - Lightweight local development option
110
+
111
+ - **Graph Database Abstraction** (`alma/graph/`)
112
+ - Pluggable `GraphBackend` interface
113
+ - Neo4j backend for production
114
+ - In-memory backend for testing
115
+ - Factory function `create_graph_backend()` for easy setup
116
+
117
+ ### Phase 1: Core Features
118
+
119
+ - **Memory Consolidation Engine** (`alma/consolidation/`)
120
+ - LLM-powered deduplication that merges similar memories
121
+ - Cosine similarity-based grouping with configurable thresholds
122
+ - Provenance tracking (merged_from metadata)
123
+ - Dry-run mode for safety
124
+
125
+ - **Event System** (`alma/events/`)
126
+ - In-process callbacks via `EventEmitter`
127
+ - Webhook delivery with HMAC signatures
128
+ - Event types: CREATED, UPDATED, DELETED, ACCESSED, CONSOLIDATED
129
+ - Retry logic with exponential backoff
130
+
131
+ - **TypeScript/JavaScript SDK** (`packages/alma-memory-js/`)
132
+ - Full API coverage: retrieve, learn, addPreference, addKnowledge, forget
133
+ - Type-safe with comprehensive TypeScript definitions
134
+ - Error hierarchy matching Python SDK
135
+ - Automatic retry with configurable backoff
136
+
137
+ - **Multi-Agent Memory Sharing**
138
+ - `inherit_from`: Read memories from other agents
139
+ - `share_with`: Make your memories readable by others
140
+ - Origin tracking via `metadata['shared_from']`
141
+ - Optimized batch queries across agents
142
+
143
+ See [CHANGELOG.md](CHANGELOG.md) for the complete history.
144
+
145
+ ---
146
+
147
+ ## What is ALMA?
148
+
149
+ ALMA is a **memory framework** that makes AI agents appear to "learn" by:
150
+ 1. **Storing** outcomes, strategies, and knowledge from past tasks
151
+ 2. **Retrieving** relevant memories before each new task
152
+ 3. **Injecting** that knowledge into prompts
153
+ 4. **Learning** from new outcomes to improve future performance
154
+
155
+ **No fine-tuning. No model changes. Just smarter prompts.**
156
+
157
+ ```
158
+ +---------------------------------------------------------------------+
159
+ | BEFORE TASK: Retrieve relevant memories |
160
+ | +-- "Last time you tested forms, incremental validation worked" |
161
+ | +-- "User prefers verbose output" |
162
+ | +-- "Don't use sleep() - causes flaky tests" |
163
+ +---------------------------------------------------------------------+
164
+ | DURING TASK: Agent executes with injected knowledge |
165
+ +---------------------------------------------------------------------+
166
+ | AFTER TASK: Learn from outcome |
167
+ | +-- Success? -> New heuristic. Failure? -> Anti-pattern. |
168
+ +---------------------------------------------------------------------+
169
+ ```
170
+
171
+ ---
172
+
173
+ ## Installation
174
+
175
+ ```bash
176
+ pip install alma-memory
177
+ ```
178
+
179
+ **With optional backends:**
180
+ ```bash
181
+ # Local development
182
+ pip install alma-memory[local] # SQLite + FAISS + local embeddings
183
+
184
+ # Production databases
185
+ pip install alma-memory[postgres] # PostgreSQL + pgvector
186
+ pip install alma-memory[qdrant] # Qdrant vector database
187
+ pip install alma-memory[pinecone] # Pinecone vector database
188
+ pip install alma-memory[chroma] # ChromaDB
189
+
190
+ # Enterprise
191
+ pip install alma-memory[azure] # Azure Cosmos DB + Azure OpenAI
192
+
193
+ # Everything
194
+ pip install alma-memory[all]
195
+ ```
196
+
197
+ **TypeScript/JavaScript:**
198
+ ```bash
199
+ npm install alma-memory
200
+ # or
201
+ yarn add alma-memory
202
+ ```
203
+
204
+ ---
205
+
206
+ ## Quick Start
207
+
208
+ ### Python
209
+
210
+ ```python
211
+ from alma import ALMA
212
+
213
+ # Initialize
214
+ alma = ALMA.from_config(".alma/config.yaml")
215
+
216
+ # Before task: Get relevant memories
217
+ memories = alma.retrieve(
218
+ task="Test the login form validation",
219
+ agent="helena",
220
+ top_k=5
221
+ )
222
+
223
+ # Inject into your prompt
224
+ prompt = f"""
225
+ ## Your Task
226
+ Test the login form validation
227
+
228
+ ## Knowledge from Past Runs
229
+ {memories.to_prompt()}
230
+ """
231
+
232
+ # After task: Learn from outcome
233
+ alma.learn(
234
+ agent="helena",
235
+ task="Test login form",
236
+ outcome="success",
237
+ strategy_used="Tested empty fields, invalid email, valid submission",
238
+ )
239
+ ```
240
+
241
+ ### TypeScript/JavaScript
242
+
243
+ ```typescript
244
+ import { ALMA } from 'alma-memory';
245
+
246
+ // Create client
247
+ const alma = new ALMA({
248
+ baseUrl: 'http://localhost:8765',
249
+ projectId: 'my-project'
250
+ });
251
+
252
+ // Retrieve memories
253
+ const memories = await alma.retrieve({
254
+ query: 'authentication flow',
255
+ agent: 'dev-agent',
256
+ topK: 5
257
+ });
258
+
259
+ // Learn from outcomes
260
+ await alma.learn({
261
+ agent: 'dev-agent',
262
+ task: 'Implement OAuth',
263
+ outcome: 'success',
264
+ strategyUsed: 'Used passport.js middleware'
265
+ });
266
+
267
+ // Add preferences and knowledge
268
+ await alma.addPreference({
269
+ userId: 'user-123',
270
+ category: 'code_style',
271
+ preference: 'Use TypeScript strict mode'
272
+ });
273
+
274
+ await alma.addKnowledge({
275
+ agent: 'dev-agent',
276
+ domain: 'authentication',
277
+ fact: 'API uses JWT with 24h expiry'
278
+ });
279
+ ```
280
+
281
+ ---
282
+
283
+ ## Core Features
284
+
285
+ ### Five Memory Types
286
+
287
+ | Type | What It Stores | Example |
288
+ |------|----------------|---------|
289
+ | **Heuristic** | Learned strategies | "For forms with >5 fields, test validation incrementally" |
290
+ | **Outcome** | Task results | "Login test succeeded using JWT token strategy" |
291
+ | **Preference** | User constraints | "User prefers verbose test output" |
292
+ | **Domain Knowledge** | Accumulated facts | "Login uses OAuth 2.0 with 24h token expiry" |
293
+ | **Anti-pattern** | What NOT to do | "Don't use sleep() for async waits - causes flaky tests" |
294
+
295
+ ### Scoped Learning
296
+
297
+ Agents only learn within their defined domains. Helena (frontend tester) cannot learn backend logic:
298
+
299
+ ```yaml
300
+ agents:
301
+ helena:
302
+ domain: coding
303
+ can_learn:
304
+ - testing_strategies
305
+ - selector_patterns
306
+ cannot_learn:
307
+ - backend_logic
308
+ - database_queries
309
+ ```
310
+
311
+ ### Multi-Agent Memory Sharing
312
+
313
+ Enable agents to share knowledge hierarchically:
314
+
315
+ ```yaml
316
+ agents:
317
+ senior_dev:
318
+ can_learn: [architecture, best_practices]
319
+ share_with: [junior_dev, qa_agent] # Others can read my memories
320
+
321
+ junior_dev:
322
+ can_learn: [coding_patterns]
323
+ inherit_from: [senior_dev] # I can read senior's memories
324
+ ```
325
+
326
+ ```python
327
+ # Junior dev retrieves memories (includes senior's shared memories)
328
+ memories = alma.retrieve(
329
+ task="Implement user authentication",
330
+ agent="junior_dev",
331
+ include_shared=True # Include inherited memories
332
+ )
333
+
334
+ # Shared memories are marked with origin
335
+ for mem in memories.heuristics:
336
+ if mem.metadata.get('shared_from'):
337
+ print(f"Learned from {mem.metadata['shared_from']}: {mem.strategy}")
338
+ ```
339
+
340
+ ### Storage Backends
341
+
342
+ | Backend | Use Case | Vector Search | Production Ready |
343
+ |---------|----------|---------------|------------------|
344
+ | **SQLite + FAISS** | Local development | Yes | Yes |
345
+ | **PostgreSQL + pgvector** | Production, HA | Yes (HNSW) | Yes |
346
+ | **Qdrant** | Managed vector DB | Yes (HNSW) | Yes |
347
+ | **Pinecone** | Serverless vector DB | Yes | Yes |
348
+ | **Chroma** | Lightweight local | Yes | Yes |
349
+ | **Azure Cosmos DB** | Enterprise, Azure-native | Yes (DiskANN) | Yes |
350
+ | **File-based** | Testing | No | No |
351
+
352
+ ---
353
+
354
+ ## Memory Consolidation
355
+
356
+ Automatically deduplicate and merge similar memories using LLM intelligence:
357
+
358
+ ```python
359
+ from alma.consolidation import ConsolidationEngine
360
+
361
+ engine = ConsolidationEngine(
362
+ storage=alma.storage,
363
+ llm_client=my_llm_client # Optional: for intelligent merging
364
+ )
365
+
366
+ # Consolidate heuristics for an agent
367
+ result = await engine.consolidate(
368
+ agent="helena",
369
+ project_id="my-project",
370
+ memory_type="heuristics",
371
+ similarity_threshold=0.85, # Group memories above this similarity
372
+ use_llm=True, # Use LLM for intelligent merging
373
+ dry_run=False # Set True to preview without changes
374
+ )
375
+
376
+ print(f"Merged {result.merged_count} memories from {result.groups_found} groups")
377
+ ```
378
+
379
+ **Features:**
380
+ - Cosine similarity-based grouping
381
+ - LLM-powered intelligent merging (preserves important nuances)
382
+ - Provenance tracking (`merged_from` metadata)
383
+ - Support for heuristics, domain_knowledge, and anti_patterns
384
+
385
+ ---
386
+
387
+ ## Event System
388
+
389
+ React to memory changes with webhooks or in-process callbacks:
390
+
391
+ ### In-Process Callbacks
392
+
393
+ ```python
394
+ from alma.events import get_emitter, MemoryEventType
395
+
396
+ def on_memory_created(event):
397
+ print(f"Memory created: {event.memory_id} by {event.agent}")
398
+ # Trigger downstream processes, update caches, etc.
399
+
400
+ emitter = get_emitter()
401
+ emitter.subscribe(MemoryEventType.CREATED, on_memory_created)
402
+ emitter.subscribe(MemoryEventType.CONSOLIDATED, on_consolidation)
403
+ ```
404
+
405
+ ### Webhooks
406
+
407
+ ```python
408
+ from alma.events import WebhookConfig, WebhookManager, get_emitter
409
+
410
+ manager = WebhookManager()
411
+ manager.add_webhook(WebhookConfig(
412
+ url="https://your-app.com/alma-webhook",
413
+ events=[MemoryEventType.CREATED, MemoryEventType.UPDATED],
414
+ secret="your-webhook-secret", # For HMAC signature verification
415
+ retry_count=3,
416
+ retry_delay=5.0
417
+ ))
418
+ manager.start(get_emitter())
419
+ ```
420
+
421
+ **Event Types:**
422
+ - `CREATED` - New memory stored
423
+ - `UPDATED` - Memory modified
424
+ - `DELETED` - Memory removed
425
+ - `ACCESSED` - Memory retrieved
426
+ - `CONSOLIDATED` - Memories merged
427
+
428
+ ---
429
+
430
+ ## Graph Memory
431
+
432
+ Capture entity relationships for complex reasoning:
433
+
434
+ ```python
435
+ from alma.graph import create_graph_backend, BackendGraphStore, EntityExtractor
436
+
437
+ # Create graph backend (Neo4j for production, memory for testing)
438
+ backend = create_graph_backend(
439
+ "neo4j",
440
+ uri="neo4j+s://xxx.databases.neo4j.io",
441
+ username="neo4j",
442
+ password="your-password"
443
+ )
444
+ # Or for testing:
445
+ # backend = create_graph_backend("memory")
446
+
447
+ # Create store with backend
448
+ graph = BackendGraphStore(backend)
449
+
450
+ # Extract entities and relationships from text
451
+ extractor = EntityExtractor()
452
+ entities, relationships = extractor.extract(
453
+ "Alice from Acme Corp reviewed the PR that Bob submitted."
454
+ )
455
+
456
+ # Store in graph
457
+ for entity in entities:
458
+ graph.add_entity(entity)
459
+ for rel in relationships:
460
+ graph.add_relationship(rel)
461
+
462
+ # Query relationships
463
+ alice_relations = graph.get_relationships("alice", relationship_type="WORKS_FOR")
464
+ ```
465
+
466
+ ---
467
+
468
+ ## The Harness Pattern
469
+
470
+ ALMA implements a generalized harness pattern for any tool-using agent:
471
+
472
+ ```
473
+ +---------------------------------------------------------------------+
474
+ | 1. SETTING Fixed environment: tools, constraints |
475
+ +---------------------------------------------------------------------+
476
+ | 2. CONTEXT Ephemeral per-run inputs: task, user |
477
+ +---------------------------------------------------------------------+
478
+ | 3. AGENT The executor with scoped intelligence |
479
+ +---------------------------------------------------------------------+
480
+ | 4. MEMORY SCHEMA Domain-specific learning structure |
481
+ +---------------------------------------------------------------------+
482
+ ```
483
+
484
+ ```python
485
+ from alma import create_harness, Context
486
+
487
+ # Create domain-specific harness
488
+ harness = create_harness("coding", "helena", alma)
489
+
490
+ # Run with automatic memory injection
491
+ result = harness.run(Context(
492
+ task="Test the login form validation",
493
+ project_id="my-app",
494
+ ))
495
+ ```
496
+
497
+ ---
498
+
499
+ ## MCP Server Integration
500
+
501
+ Expose ALMA to Claude Code or any MCP-compatible client:
502
+
503
+ ```bash
504
+ python -m alma.mcp --config .alma/config.yaml
505
+ ```
506
+
507
+ ```json
508
+ // .mcp.json
509
+ {
510
+ "mcpServers": {
511
+ "alma-memory": {
512
+ "command": "python",
513
+ "args": ["-m", "alma.mcp", "--config", ".alma/config.yaml"]
514
+ }
515
+ }
516
+ }
517
+ ```
518
+
519
+ **Available MCP Tools:**
520
+ | Tool | Description |
521
+ |------|-------------|
522
+ | `alma_retrieve` | Get memories for a task |
523
+ | `alma_learn` | Record task outcome |
524
+ | `alma_add_preference` | Add user preference |
525
+ | `alma_add_knowledge` | Add domain knowledge |
526
+ | `alma_forget` | Prune stale memories |
527
+ | `alma_stats` | Get memory statistics |
528
+ | `alma_health` | Health check |
529
+
530
+ ---
531
+
532
+ ## Advanced Features
533
+
534
+ ### Domain Memory Factory
535
+
536
+ Create ALMA instances for any domain - not just coding:
537
+
538
+ ```python
539
+ from alma.domains import DomainMemoryFactory, get_research_schema
540
+
541
+ # Pre-built schemas
542
+ factory = DomainMemoryFactory()
543
+ alma = factory.create_alma(get_research_schema(), "my-research-project")
544
+
545
+ # Or create custom domains
546
+ schema = factory.create_schema("sales", {
547
+ "entity_types": [
548
+ {"name": "lead", "attributes": ["stage", "value"]},
549
+ {"name": "objection", "attributes": ["type", "response"]},
550
+ ],
551
+ "learning_categories": [
552
+ "objection_handling",
553
+ "closing_techniques",
554
+ "qualification_patterns",
555
+ ],
556
+ })
557
+ ```
558
+
559
+ **Pre-built schemas:** `coding`, `research`, `sales`, `general`, `customer_support`, `content_creation`
560
+
561
+ ### Progress Tracking
562
+
563
+ Track work items and get intelligent next-task suggestions:
564
+
565
+ ```python
566
+ from alma.progress import ProgressTracker
567
+
568
+ tracker = ProgressTracker("my-project")
569
+
570
+ # Create work items
571
+ item = tracker.create_work_item(
572
+ title="Fix authentication bug",
573
+ description="Login fails on mobile devices",
574
+ priority=80,
575
+ agent="Victor",
576
+ )
577
+
578
+ # Update status
579
+ tracker.update_status(item.id, "in_progress")
580
+
581
+ # Get next task (by priority, quick wins, or unblock others)
582
+ next_task = tracker.get_next_item(strategy="priority")
583
+ ```
584
+
585
+ ### Session Handoff
586
+
587
+ Maintain context across sessions - no more "starting fresh":
588
+
589
+ ```python
590
+ from alma.session import SessionManager
591
+
592
+ manager = SessionManager("my-project")
593
+
594
+ # Start session (loads previous context)
595
+ context = manager.start_session(agent="Helena", goal="Complete auth testing")
596
+
597
+ # Previous session info is available
598
+ if context.previous_handoff:
599
+ print(f"Last action: {context.previous_handoff.last_action}")
600
+ print(f"Blockers: {context.previous_handoff.blockers}")
601
+
602
+ # End session with handoff for next time
603
+ manager.create_handoff("Helena", context.session_id,
604
+ last_action="completed_oauth_tests",
605
+ last_outcome="success",
606
+ next_steps=["Test refresh tokens", "Add error cases"],
607
+ )
608
+ ```
609
+
610
+ ### LLM-Powered Fact Extraction
611
+
612
+ Automatically extract and learn from conversations:
613
+
614
+ ```python
615
+ from alma.extraction import AutoLearner
616
+
617
+ alma = ALMA.from_config(".alma/config.yaml")
618
+ auto_learner = AutoLearner(alma)
619
+
620
+ # After a conversation, automatically extract learnings
621
+ results = auto_learner.learn_from_conversation(
622
+ messages=[
623
+ {"role": "user", "content": "Test the login form"},
624
+ {"role": "assistant", "content": "I used incremental validation which worked well..."},
625
+ ],
626
+ agent="helena",
627
+ )
628
+
629
+ print(f"Extracted {results['extracted_count']} facts")
630
+ ```
631
+
632
+ ### Confidence Engine
633
+
634
+ Assess strategies before trying them:
635
+
636
+ ```python
637
+ from alma.confidence import ConfidenceEngine
638
+
639
+ engine = ConfidenceEngine(alma)
640
+
641
+ # Assess a strategy before trying it
642
+ signal = engine.assess_strategy(
643
+ strategy="Use incremental validation",
644
+ context="Testing a 5-field registration form",
645
+ agent="Helena",
646
+ )
647
+
648
+ print(f"Confidence: {signal.confidence_score:.0%}")
649
+ print(f"Recommendation: {signal.recommendation}")
650
+ # -> Confidence: 78%
651
+ # -> Recommendation: yes
652
+ ```
653
+
654
+ ---
655
+
656
+ ## Architecture
657
+
658
+ ```
659
+ +-------------------------------------------------------------------------+
660
+ | ALMA v0.5.0 |
661
+ +-------------------------------------------------------------------------+
662
+ | HARNESS LAYER |
663
+ | +-----------+ +-----------+ +-----------+ +----------------+ |
664
+ | | Setting | | Context | | Agent | | MemorySchema | |
665
+ | +-----------+ +-----------+ +-----------+ +----------------+ |
666
+ +-------------------------------------------------------------------------+
667
+ | EXTENSION MODULES |
668
+ | +-------------+ +---------------+ +------------------+ |
669
+ | | Progress | | Session | | Domain Memory | |
670
+ | | Tracking | | Handoff | | Factory | |
671
+ | +-------------+ +---------------+ +------------------+ |
672
+ | +-------------+ +---------------+ +------------------+ |
673
+ | | Auto | | Confidence | | Memory | |
674
+ | | Learner | | Engine | | Consolidation | |
675
+ | +-------------+ +---------------+ +------------------+ |
676
+ | +-------------+ +---------------+ |
677
+ | | Event | | TypeScript | |
678
+ | | System | | SDK | |
679
+ | +-------------+ +---------------+ |
680
+ +-------------------------------------------------------------------------+
681
+ | CORE LAYER |
682
+ | +-------------+ +-------------+ +-------------+ +------------+ |
683
+ | | Retrieval | | Learning | | Caching | | Forgetting | |
684
+ | | Engine | | Protocol | | Layer | | Mechanism | |
685
+ | +-------------+ +-------------+ +-------------+ +------------+ |
686
+ +-------------------------------------------------------------------------+
687
+ | STORAGE LAYER |
688
+ | +---------------+ +------------------+ +---------------+ |
689
+ | | SQLite+FAISS | | PostgreSQL+pgvec | | Azure Cosmos | |
690
+ | +---------------+ +------------------+ +---------------+ |
691
+ | +---------------+ +------------------+ +---------------+ |
692
+ | | Qdrant | | Pinecone | | Chroma | |
693
+ | +---------------+ +------------------+ +---------------+ |
694
+ +-------------------------------------------------------------------------+
695
+ | GRAPH LAYER |
696
+ | +---------------+ +------------------+ |
697
+ | | Neo4j | | In-Memory | |
698
+ | +---------------+ +------------------+ |
699
+ +-------------------------------------------------------------------------+
700
+ | INTEGRATION LAYER |
701
+ | +-------------------------------------------------------------------+ |
702
+ | | MCP Server | |
703
+ | +-------------------------------------------------------------------+ |
704
+ +-------------------------------------------------------------------------+
705
+ ```
706
+
707
+ ---
708
+
709
+ ## Configuration
710
+
711
+ Create `.alma/config.yaml`:
712
+
713
+ ```yaml
714
+ alma:
715
+ project_id: "my-project"
716
+ storage: sqlite # sqlite | postgres | qdrant | pinecone | chroma | azure | file
717
+ embedding_provider: local # local | azure | mock
718
+ storage_dir: .alma
719
+ db_name: alma.db
720
+ embedding_dim: 384
721
+
722
+ agents:
723
+ helena:
724
+ domain: coding
725
+ can_learn:
726
+ - testing_strategies
727
+ - selector_patterns
728
+ cannot_learn:
729
+ - backend_logic
730
+ min_occurrences_for_heuristic: 3
731
+ share_with: [qa_lead] # Share memories with QA lead
732
+
733
+ victor:
734
+ domain: coding
735
+ can_learn:
736
+ - api_patterns
737
+ - database_queries
738
+ cannot_learn:
739
+ - frontend_selectors
740
+ inherit_from: [senior_architect] # Learn from senior architect
741
+ ```
742
+
743
+ ### Storage Backend Configuration
744
+
745
+ **PostgreSQL + pgvector:**
746
+ ```yaml
747
+ storage: postgres
748
+ postgres:
749
+ host: localhost
750
+ port: 5432
751
+ database: alma
752
+ user: alma_user
753
+ password: ${POSTGRES_PASSWORD}
754
+ vector_index_type: hnsw # hnsw | ivfflat
755
+ ```
756
+
757
+ **Qdrant:**
758
+ ```yaml
759
+ storage: qdrant
760
+ qdrant:
761
+ url: http://localhost:6333
762
+ api_key: ${QDRANT_API_KEY} # Optional for cloud
763
+ collection_prefix: alma
764
+ ```
765
+
766
+ **Pinecone:**
767
+ ```yaml
768
+ storage: pinecone
769
+ pinecone:
770
+ api_key: ${PINECONE_API_KEY}
771
+ environment: us-east-1-aws
772
+ index_name: alma-memories
773
+ ```
774
+
775
+ **Chroma:**
776
+ ```yaml
777
+ storage: chroma
778
+ chroma:
779
+ persist_directory: .alma/chroma
780
+ # Or for client-server mode:
781
+ # host: localhost
782
+ # port: 8000
783
+ ```
784
+
785
+ ### Embedding Providers
786
+
787
+ | Provider | Model | Dimensions | Cost | Best For |
788
+ |----------|-------|------------|------|----------|
789
+ | **local** | all-MiniLM-L6-v2 | 384 | Free | Development, offline |
790
+ | **azure** | text-embedding-3-small | 1536 | ~$0.02/1M | Production |
791
+ | **mock** | (hash-based) | 384 | Free | Testing only |
792
+
793
+ ---
794
+
795
+ ## Development Status
796
+
797
+ | Phase | Description | Status |
798
+ |-------|-------------|--------|
799
+ | Core Abstractions | Memory types, scopes | Done |
800
+ | Local Storage | SQLite + FAISS | Done |
801
+ | Retrieval Engine | Semantic search, scoring | Done |
802
+ | Learning Protocols | Heuristic formation | Done |
803
+ | Agent Integration | Harness pattern | Done |
804
+ | Azure Cosmos DB | Enterprise storage | Done |
805
+ | PostgreSQL | Production storage | Done |
806
+ | Cache Layer | Performance optimization | Done |
807
+ | Forgetting Mechanism | Memory pruning | Done |
808
+ | MCP Server | Claude Code integration | Done |
809
+ | Progress Tracking | Work item management | Done |
810
+ | Session Handoff | Context continuity | Done |
811
+ | Domain Factory | Any-domain support | Done |
812
+ | Confidence Engine | Strategy assessment | Done |
813
+ | Technical Debt Sprint | Security & performance fixes | Done |
814
+ | Multi-Agent Sharing | Cross-agent memory access | Done |
815
+ | Memory Consolidation | LLM-powered deduplication | Done |
816
+ | Event System | Webhooks and callbacks | Done |
817
+ | TypeScript SDK | JavaScript/TypeScript client | Done |
818
+ | Qdrant Backend | Vector database support | Done |
819
+ | Pinecone Backend | Serverless vector DB | Done |
820
+ | Chroma Backend | Lightweight vector DB | Done |
821
+ | Graph Abstraction | Pluggable graph backends | Done |
822
+
823
+ ---
824
+
825
+ ## Troubleshooting
826
+
827
+ ### Common Issues
828
+
829
+ **ImportError: sentence-transformers is required**
830
+ ```bash
831
+ pip install alma-memory[local]
832
+ ```
833
+
834
+ **pgvector extension not found**
835
+ ```sql
836
+ CREATE EXTENSION IF NOT EXISTS vector;
837
+ ```
838
+
839
+ **Qdrant connection refused**
840
+ ```bash
841
+ # Start Qdrant with Docker
842
+ docker run -p 6333:6333 qdrant/qdrant
843
+ ```
844
+
845
+ **Pinecone index not found**
846
+ - Ensure your index exists in the Pinecone console
847
+ - Check that `index_name` in config matches your index
848
+
849
+ **Embeddings dimension mismatch**
850
+ - Ensure `embedding_dim` in config matches your embedding provider
851
+ - Local: 384, Azure text-embedding-3-small: 1536
852
+
853
+ ### Debug Logging
854
+
855
+ ```python
856
+ import logging
857
+ logging.getLogger("alma").setLevel(logging.DEBUG)
858
+ ```
859
+
860
+ ---
861
+
862
+ ## Contributing
863
+
864
+ We welcome contributions! See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
865
+
866
+ **What we need most:**
867
+ - Documentation improvements
868
+ - Test coverage for edge cases
869
+ - Additional LLM provider integrations (Ollama, Groq)
870
+ - Frontend dashboard for memory visualization
871
+
872
+ ---
873
+
874
+ ## Roadmap
875
+
876
+ **Completed:**
877
+ - Multi-agent memory sharing
878
+ - Memory consolidation engine
879
+ - Event system / webhooks
880
+ - TypeScript SDK
881
+ - Qdrant, Pinecone, Chroma backends
882
+ - Graph database abstraction
883
+
884
+ **Next:**
885
+ - Memory compression / summarization
886
+ - Temporal reasoning (time-aware retrieval)
887
+ - Proactive memory suggestions
888
+ - Visual memory explorer dashboard
889
+ - Additional graph backends (Neptune, TigerGraph)
890
+
891
+ ---
892
+
893
+ ## License
894
+
895
+ MIT
896
+
897
+ ---
898
+
899
+ ## Star History
900
+
901
+ If ALMA helps your AI agents get smarter, consider giving us a star!
902
+
903
+ ---
904
+
905
+ **Built for AI agents that get better with every task.**