alma-memory 0.5.0__py3-none-any.whl → 0.7.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.
Files changed (111) hide show
  1. alma/__init__.py +296 -194
  2. alma/compression/__init__.py +33 -0
  3. alma/compression/pipeline.py +980 -0
  4. alma/confidence/__init__.py +47 -47
  5. alma/confidence/engine.py +540 -540
  6. alma/confidence/types.py +351 -351
  7. alma/config/loader.py +157 -157
  8. alma/consolidation/__init__.py +23 -23
  9. alma/consolidation/engine.py +678 -678
  10. alma/consolidation/prompts.py +84 -84
  11. alma/core.py +1189 -322
  12. alma/domains/__init__.py +30 -30
  13. alma/domains/factory.py +359 -359
  14. alma/domains/schemas.py +448 -448
  15. alma/domains/types.py +272 -272
  16. alma/events/__init__.py +75 -75
  17. alma/events/emitter.py +285 -284
  18. alma/events/storage_mixin.py +246 -246
  19. alma/events/types.py +126 -126
  20. alma/events/webhook.py +425 -425
  21. alma/exceptions.py +49 -49
  22. alma/extraction/__init__.py +31 -31
  23. alma/extraction/auto_learner.py +265 -264
  24. alma/extraction/extractor.py +420 -420
  25. alma/graph/__init__.py +106 -81
  26. alma/graph/backends/__init__.py +32 -18
  27. alma/graph/backends/kuzu.py +624 -0
  28. alma/graph/backends/memgraph.py +432 -0
  29. alma/graph/backends/memory.py +236 -236
  30. alma/graph/backends/neo4j.py +417 -417
  31. alma/graph/base.py +159 -159
  32. alma/graph/extraction.py +198 -198
  33. alma/graph/store.py +860 -860
  34. alma/harness/__init__.py +35 -35
  35. alma/harness/base.py +386 -386
  36. alma/harness/domains.py +705 -705
  37. alma/initializer/__init__.py +37 -37
  38. alma/initializer/initializer.py +418 -418
  39. alma/initializer/types.py +250 -250
  40. alma/integration/__init__.py +62 -62
  41. alma/integration/claude_agents.py +444 -432
  42. alma/integration/helena.py +423 -423
  43. alma/integration/victor.py +471 -471
  44. alma/learning/__init__.py +101 -86
  45. alma/learning/decay.py +878 -0
  46. alma/learning/forgetting.py +1446 -1446
  47. alma/learning/heuristic_extractor.py +390 -390
  48. alma/learning/protocols.py +374 -374
  49. alma/learning/validation.py +346 -346
  50. alma/mcp/__init__.py +123 -45
  51. alma/mcp/__main__.py +156 -156
  52. alma/mcp/resources.py +122 -122
  53. alma/mcp/server.py +955 -591
  54. alma/mcp/tools.py +3254 -511
  55. alma/observability/__init__.py +91 -0
  56. alma/observability/config.py +302 -0
  57. alma/observability/guidelines.py +170 -0
  58. alma/observability/logging.py +424 -0
  59. alma/observability/metrics.py +583 -0
  60. alma/observability/tracing.py +440 -0
  61. alma/progress/__init__.py +21 -21
  62. alma/progress/tracker.py +607 -607
  63. alma/progress/types.py +250 -250
  64. alma/retrieval/__init__.py +134 -53
  65. alma/retrieval/budget.py +525 -0
  66. alma/retrieval/cache.py +1304 -1061
  67. alma/retrieval/embeddings.py +202 -202
  68. alma/retrieval/engine.py +850 -366
  69. alma/retrieval/modes.py +365 -0
  70. alma/retrieval/progressive.py +560 -0
  71. alma/retrieval/scoring.py +344 -344
  72. alma/retrieval/trust_scoring.py +637 -0
  73. alma/retrieval/verification.py +797 -0
  74. alma/session/__init__.py +19 -19
  75. alma/session/manager.py +442 -399
  76. alma/session/types.py +288 -288
  77. alma/storage/__init__.py +101 -61
  78. alma/storage/archive.py +233 -0
  79. alma/storage/azure_cosmos.py +1259 -1048
  80. alma/storage/base.py +1083 -525
  81. alma/storage/chroma.py +1443 -1443
  82. alma/storage/constants.py +103 -0
  83. alma/storage/file_based.py +614 -619
  84. alma/storage/migrations/__init__.py +21 -0
  85. alma/storage/migrations/base.py +321 -0
  86. alma/storage/migrations/runner.py +323 -0
  87. alma/storage/migrations/version_stores.py +337 -0
  88. alma/storage/migrations/versions/__init__.py +11 -0
  89. alma/storage/migrations/versions/v1_0_0.py +373 -0
  90. alma/storage/migrations/versions/v1_1_0_workflow_context.py +551 -0
  91. alma/storage/pinecone.py +1080 -1080
  92. alma/storage/postgresql.py +1948 -1452
  93. alma/storage/qdrant.py +1306 -1306
  94. alma/storage/sqlite_local.py +3041 -1358
  95. alma/testing/__init__.py +46 -0
  96. alma/testing/factories.py +301 -0
  97. alma/testing/mocks.py +389 -0
  98. alma/types.py +292 -264
  99. alma/utils/__init__.py +19 -0
  100. alma/utils/tokenizer.py +521 -0
  101. alma/workflow/__init__.py +83 -0
  102. alma/workflow/artifacts.py +170 -0
  103. alma/workflow/checkpoint.py +311 -0
  104. alma/workflow/context.py +228 -0
  105. alma/workflow/outcomes.py +189 -0
  106. alma/workflow/reducers.py +393 -0
  107. {alma_memory-0.5.0.dist-info → alma_memory-0.7.0.dist-info}/METADATA +244 -72
  108. alma_memory-0.7.0.dist-info/RECORD +112 -0
  109. alma_memory-0.5.0.dist-info/RECORD +0 -76
  110. {alma_memory-0.5.0.dist-info → alma_memory-0.7.0.dist-info}/WHEEL +0 -0
  111. {alma_memory-0.5.0.dist-info → alma_memory-0.7.0.dist-info}/top_level.txt +0 -0
alma/__init__.py CHANGED
@@ -1,194 +1,296 @@
1
- """
2
- ALMA - Agent Learning Memory Architecture
3
-
4
- Persistent memory system for AI agents that learn and improve over time
5
- through structured memory layers - without model weight updates.
6
-
7
- The Harness Pattern:
8
- 1. Setting - Fixed environment (tools, constraints)
9
- 2. Context - Ephemeral per-run inputs
10
- 3. Agent - The executor with scoped intelligence
11
- 4. Memory Schema - Domain-specific learning structure
12
-
13
- This makes any tool-using agent appear to "learn" by injecting relevant
14
- memory slices before each run and updating memory after.
15
- """
16
-
17
- __version__ = "0.4.0"
18
-
19
- # Core
20
- # Confidence Engine (Phase 12)
21
- from alma.confidence import (
22
- ConfidenceEngine,
23
- ConfidenceSignal,
24
- OpportunitySignal,
25
- RiskSignal,
26
- )
27
-
28
- # Consolidation Engine (Phase 13)
29
- from alma.consolidation import (
30
- ConsolidationEngine,
31
- ConsolidationResult,
32
- )
33
- from alma.core import ALMA
34
-
35
- # Domain Memory Factory (Phase 10)
36
- from alma.domains import (
37
- DomainMemoryFactory,
38
- DomainSchema,
39
- EntityType,
40
- RelationshipType,
41
- get_coding_schema,
42
- get_general_schema,
43
- get_research_schema,
44
- get_sales_schema,
45
- )
46
-
47
- # Event System (Phase 19)
48
- from alma.events import (
49
- EventEmitter,
50
- MemoryEvent,
51
- MemoryEventType,
52
- WebhookConfig,
53
- WebhookManager,
54
- get_emitter,
55
- )
56
-
57
- # Exceptions
58
- from alma.exceptions import (
59
- ALMAError,
60
- ConfigurationError,
61
- EmbeddingError,
62
- ExtractionError,
63
- RetrievalError,
64
- ScopeViolationError,
65
- StorageError,
66
- )
67
-
68
- # Harness Pattern
69
- from alma.harness.base import (
70
- Agent,
71
- Context,
72
- Harness,
73
- MemorySchema,
74
- RunResult,
75
- Setting,
76
- Tool,
77
- ToolType,
78
- )
79
- from alma.harness.domains import (
80
- CodingDomain,
81
- ContentDomain,
82
- OperationsDomain,
83
- ResearchDomain,
84
- create_harness,
85
- )
86
-
87
- # Session Initializer (Phase 11)
88
- from alma.initializer import (
89
- CodebaseOrientation,
90
- InitializationResult,
91
- RulesOfEngagement,
92
- SessionInitializer,
93
- )
94
-
95
- # Progress Tracking (Phase 10)
96
- from alma.progress import (
97
- ProgressLog,
98
- ProgressSummary,
99
- ProgressTracker,
100
- WorkItem,
101
- WorkItemStatus,
102
- )
103
-
104
- # Session Management (Phase 10)
105
- from alma.session import (
106
- SessionContext,
107
- SessionHandoff,
108
- SessionManager,
109
- SessionOutcome,
110
- )
111
- from alma.types import (
112
- AntiPattern,
113
- DomainKnowledge,
114
- Heuristic,
115
- MemoryScope,
116
- MemorySlice,
117
- Outcome,
118
- UserPreference,
119
- )
120
-
121
- __all__ = [
122
- # Core
123
- "ALMA",
124
- "Heuristic",
125
- "Outcome",
126
- "UserPreference",
127
- "DomainKnowledge",
128
- "AntiPattern",
129
- "MemorySlice",
130
- "MemoryScope",
131
- # Harness Pattern
132
- "Setting",
133
- "Context",
134
- "Agent",
135
- "MemorySchema",
136
- "Harness",
137
- "Tool",
138
- "ToolType",
139
- "RunResult",
140
- # Domain Configurations
141
- "CodingDomain",
142
- "ResearchDomain",
143
- "ContentDomain",
144
- "OperationsDomain",
145
- "create_harness",
146
- # Progress Tracking
147
- "WorkItem",
148
- "WorkItemStatus",
149
- "ProgressLog",
150
- "ProgressSummary",
151
- "ProgressTracker",
152
- # Session Management
153
- "SessionHandoff",
154
- "SessionContext",
155
- "SessionOutcome",
156
- "SessionManager",
157
- # Domain Memory Factory
158
- "DomainSchema",
159
- "EntityType",
160
- "RelationshipType",
161
- "DomainMemoryFactory",
162
- "get_coding_schema",
163
- "get_research_schema",
164
- "get_sales_schema",
165
- "get_general_schema",
166
- # Session Initializer
167
- "CodebaseOrientation",
168
- "InitializationResult",
169
- "RulesOfEngagement",
170
- "SessionInitializer",
171
- # Confidence Engine
172
- "ConfidenceEngine",
173
- "ConfidenceSignal",
174
- "OpportunitySignal",
175
- "RiskSignal",
176
- # Consolidation Engine
177
- "ConsolidationEngine",
178
- "ConsolidationResult",
179
- # Event System
180
- "MemoryEvent",
181
- "MemoryEventType",
182
- "EventEmitter",
183
- "get_emitter",
184
- "WebhookConfig",
185
- "WebhookManager",
186
- # Exceptions
187
- "ALMAError",
188
- "ConfigurationError",
189
- "ScopeViolationError",
190
- "StorageError",
191
- "EmbeddingError",
192
- "RetrievalError",
193
- "ExtractionError",
194
- ]
1
+ """
2
+ ALMA - Agent Learning Memory Architecture
3
+
4
+ Persistent memory system for AI agents that learn and improve over time
5
+ through structured memory layers - without model weight updates.
6
+
7
+ The Harness Pattern:
8
+ 1. Setting - Fixed environment (tools, constraints)
9
+ 2. Context - Ephemeral per-run inputs
10
+ 3. Agent - The executor with scoped intelligence
11
+ 4. Memory Schema - Domain-specific learning structure
12
+
13
+ This makes any tool-using agent appear to "learn" by injecting relevant
14
+ memory slices before each run and updating memory after.
15
+
16
+ Testing Support:
17
+ For testing ALMA integrations, use the `alma.testing` module:
18
+
19
+ from alma.testing import MockStorage, create_test_heuristic
20
+
21
+ def test_my_integration():
22
+ storage = MockStorage()
23
+ heuristic = create_test_heuristic(agent="test-agent")
24
+ storage.save_heuristic(heuristic)
25
+
26
+ Available utilities:
27
+ - MockStorage: In-memory storage backend
28
+ - MockEmbedder: Deterministic fake embeddings
29
+ - create_test_heuristic(), create_test_outcome(), etc.
30
+ """
31
+
32
+ __version__ = "0.7.0"
33
+
34
+ # Core
35
+ # Confidence Engine (Phase 12)
36
+ from alma.confidence import (
37
+ ConfidenceEngine,
38
+ ConfidenceSignal,
39
+ OpportunitySignal,
40
+ RiskSignal,
41
+ )
42
+
43
+ # Consolidation Engine (Phase 13)
44
+ from alma.consolidation import (
45
+ ConsolidationEngine,
46
+ ConsolidationResult,
47
+ )
48
+ from alma.core import ALMA
49
+
50
+ # Domain Memory Factory (Phase 10)
51
+ from alma.domains import (
52
+ DomainMemoryFactory,
53
+ DomainSchema,
54
+ EntityType,
55
+ RelationshipType,
56
+ get_coding_schema,
57
+ get_general_schema,
58
+ get_research_schema,
59
+ get_sales_schema,
60
+ )
61
+
62
+ # Event System (Phase 19)
63
+ from alma.events import (
64
+ EventEmitter,
65
+ MemoryEvent,
66
+ MemoryEventType,
67
+ WebhookConfig,
68
+ WebhookManager,
69
+ get_emitter,
70
+ )
71
+
72
+ # Exceptions
73
+ from alma.exceptions import (
74
+ ALMAError,
75
+ ConfigurationError,
76
+ EmbeddingError,
77
+ ExtractionError,
78
+ RetrievalError,
79
+ ScopeViolationError,
80
+ StorageError,
81
+ )
82
+
83
+ # Extraction / AutoLearner (Phase 15)
84
+ from alma.extraction import (
85
+ AutoLearner,
86
+ ExtractedFact,
87
+ ExtractionResult,
88
+ FactExtractor,
89
+ FactType,
90
+ LLMFactExtractor,
91
+ RuleBasedExtractor,
92
+ add_auto_learning_to_alma,
93
+ create_extractor,
94
+ )
95
+
96
+ # Harness Pattern
97
+ from alma.harness.base import (
98
+ Agent,
99
+ Context,
100
+ Harness,
101
+ MemorySchema,
102
+ RunResult,
103
+ Setting,
104
+ Tool,
105
+ ToolType,
106
+ )
107
+ from alma.harness.domains import (
108
+ CodingDomain,
109
+ ContentDomain,
110
+ OperationsDomain,
111
+ ResearchDomain,
112
+ create_harness,
113
+ )
114
+
115
+ # Session Initializer (Phase 11)
116
+ from alma.initializer import (
117
+ CodebaseOrientation,
118
+ InitializationResult,
119
+ RulesOfEngagement,
120
+ SessionInitializer,
121
+ )
122
+
123
+ # Observability (Phase 20)
124
+ from alma.observability import (
125
+ ALMAMetrics,
126
+ configure_observability,
127
+ get_logger,
128
+ get_metrics,
129
+ get_tracer,
130
+ trace_method,
131
+ )
132
+
133
+ # Progress Tracking (Phase 10)
134
+ from alma.progress import (
135
+ ProgressLog,
136
+ ProgressSummary,
137
+ ProgressTracker,
138
+ WorkItem,
139
+ WorkItemStatus,
140
+ )
141
+
142
+ # Session Management (Phase 10)
143
+ from alma.session import (
144
+ SessionContext,
145
+ SessionHandoff,
146
+ SessionManager,
147
+ SessionOutcome,
148
+ )
149
+ from alma.types import (
150
+ AntiPattern,
151
+ DomainKnowledge,
152
+ Heuristic,
153
+ MemoryScope,
154
+ MemorySlice,
155
+ Outcome,
156
+ UserPreference,
157
+ )
158
+
159
+ # Token Estimation (Issue #11: LOW-001)
160
+ from alma.utils.tokenizer import (
161
+ ModelTokenBudget,
162
+ TokenEstimator,
163
+ get_default_token_budget,
164
+ get_token_estimator,
165
+ )
166
+
167
+ # Workflow Context Layer (v0.6.0)
168
+ from alma.workflow import (
169
+ # Artifacts
170
+ ArtifactRef,
171
+ ArtifactType,
172
+ # Checkpoints
173
+ Checkpoint,
174
+ CheckpointManager,
175
+ # State reducers
176
+ ReducerConfig,
177
+ # Context and scoping
178
+ RetrievalScope,
179
+ StateMerger,
180
+ WorkflowContext,
181
+ # Workflow outcomes
182
+ WorkflowOutcome,
183
+ WorkflowResult,
184
+ link_artifact,
185
+ merge_states,
186
+ )
187
+
188
+ __all__ = [
189
+ # Core
190
+ "ALMA",
191
+ "Heuristic",
192
+ "Outcome",
193
+ "UserPreference",
194
+ "DomainKnowledge",
195
+ "AntiPattern",
196
+ "MemorySlice",
197
+ "MemoryScope",
198
+ # Harness Pattern
199
+ "Setting",
200
+ "Context",
201
+ "Agent",
202
+ "MemorySchema",
203
+ "Harness",
204
+ "Tool",
205
+ "ToolType",
206
+ "RunResult",
207
+ # Domain Configurations
208
+ "CodingDomain",
209
+ "ResearchDomain",
210
+ "ContentDomain",
211
+ "OperationsDomain",
212
+ "create_harness",
213
+ # Progress Tracking
214
+ "WorkItem",
215
+ "WorkItemStatus",
216
+ "ProgressLog",
217
+ "ProgressSummary",
218
+ "ProgressTracker",
219
+ # Session Management
220
+ "SessionHandoff",
221
+ "SessionContext",
222
+ "SessionOutcome",
223
+ "SessionManager",
224
+ # Workflow Context Layer (v0.6.0)
225
+ "RetrievalScope",
226
+ "WorkflowContext",
227
+ "Checkpoint",
228
+ "CheckpointManager",
229
+ "WorkflowOutcome",
230
+ "WorkflowResult",
231
+ "ArtifactRef",
232
+ "ArtifactType",
233
+ "link_artifact",
234
+ "ReducerConfig",
235
+ "StateMerger",
236
+ "merge_states",
237
+ # Domain Memory Factory
238
+ "DomainSchema",
239
+ "EntityType",
240
+ "RelationshipType",
241
+ "DomainMemoryFactory",
242
+ "get_coding_schema",
243
+ "get_research_schema",
244
+ "get_sales_schema",
245
+ "get_general_schema",
246
+ # Session Initializer
247
+ "CodebaseOrientation",
248
+ "InitializationResult",
249
+ "RulesOfEngagement",
250
+ "SessionInitializer",
251
+ # Confidence Engine
252
+ "ConfidenceEngine",
253
+ "ConfidenceSignal",
254
+ "OpportunitySignal",
255
+ "RiskSignal",
256
+ # Consolidation Engine
257
+ "ConsolidationEngine",
258
+ "ConsolidationResult",
259
+ # Event System
260
+ "MemoryEvent",
261
+ "MemoryEventType",
262
+ "EventEmitter",
263
+ "get_emitter",
264
+ "WebhookConfig",
265
+ "WebhookManager",
266
+ # Exceptions
267
+ "ALMAError",
268
+ "ConfigurationError",
269
+ "ScopeViolationError",
270
+ "StorageError",
271
+ "EmbeddingError",
272
+ "RetrievalError",
273
+ "ExtractionError",
274
+ # Observability
275
+ "configure_observability",
276
+ "get_tracer",
277
+ "get_logger",
278
+ "get_metrics",
279
+ "ALMAMetrics",
280
+ "trace_method",
281
+ # Extraction / AutoLearner
282
+ "AutoLearner",
283
+ "FactExtractor",
284
+ "LLMFactExtractor",
285
+ "RuleBasedExtractor",
286
+ "ExtractedFact",
287
+ "ExtractionResult",
288
+ "FactType",
289
+ "create_extractor",
290
+ "add_auto_learning_to_alma",
291
+ # Token Estimation
292
+ "TokenEstimator",
293
+ "ModelTokenBudget",
294
+ "get_token_estimator",
295
+ "get_default_token_budget",
296
+ ]
@@ -0,0 +1,33 @@
1
+ """
2
+ ALMA Memory Compression Pipeline.
3
+
4
+ Provides intelligent compression of verbose content into structured memories.
5
+ Based on Memory Wall principles: "Do not upload 40 pages hoping the AI extracts
6
+ what matters. You need to do the compression work."
7
+
8
+ Key features:
9
+ - Multiple compression levels (NONE, LIGHT, MEDIUM, AGGRESSIVE)
10
+ - LLM-based intelligent extraction
11
+ - Rule-based fallback without LLM
12
+ - Key fact and constraint extraction
13
+ - Heuristic extraction from multiple experiences
14
+ - Deduplication against existing knowledge
15
+ """
16
+
17
+ from alma.compression.pipeline import (
18
+ CompressedMemory,
19
+ CompressionConfig,
20
+ CompressionLevel,
21
+ CompressionResult,
22
+ MemoryCompressor,
23
+ create_compressor,
24
+ )
25
+
26
+ __all__ = [
27
+ "CompressionLevel",
28
+ "CompressedMemory",
29
+ "CompressionResult",
30
+ "CompressionConfig",
31
+ "MemoryCompressor",
32
+ "create_compressor",
33
+ ]