alma-memory 0.5.1__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 -226
  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 -430
  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 -265
  24. alma/extraction/extractor.py +420 -420
  25. alma/graph/__init__.py +106 -106
  26. alma/graph/backends/__init__.py +32 -32
  27. alma/graph/backends/kuzu.py +624 -624
  28. alma/graph/backends/memgraph.py +432 -432
  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 -444
  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 -509
  55. alma/observability/__init__.py +91 -84
  56. alma/observability/config.py +302 -302
  57. alma/observability/guidelines.py +170 -0
  58. alma/observability/logging.py +424 -424
  59. alma/observability/metrics.py +583 -583
  60. alma/observability/tracing.py +440 -440
  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 -427
  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 -90
  78. alma/storage/archive.py +233 -0
  79. alma/storage/azure_cosmos.py +1259 -1259
  80. alma/storage/base.py +1083 -583
  81. alma/storage/chroma.py +1443 -1443
  82. alma/storage/constants.py +103 -103
  83. alma/storage/file_based.py +614 -614
  84. alma/storage/migrations/__init__.py +21 -21
  85. alma/storage/migrations/base.py +321 -321
  86. alma/storage/migrations/runner.py +323 -323
  87. alma/storage/migrations/version_stores.py +337 -337
  88. alma/storage/migrations/versions/__init__.py +11 -11
  89. alma/storage/migrations/versions/v1_0_0.py +373 -373
  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 -1559
  93. alma/storage/qdrant.py +1306 -1306
  94. alma/storage/sqlite_local.py +3041 -1457
  95. alma/testing/__init__.py +46 -46
  96. alma/testing/factories.py +301 -301
  97. alma/testing/mocks.py +389 -389
  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.1.dist-info → alma_memory-0.7.0.dist-info}/METADATA +210 -72
  108. alma_memory-0.7.0.dist-info/RECORD +112 -0
  109. alma_memory-0.5.1.dist-info/RECORD +0 -93
  110. {alma_memory-0.5.1.dist-info → alma_memory-0.7.0.dist-info}/WHEEL +0 -0
  111. {alma_memory-0.5.1.dist-info → alma_memory-0.7.0.dist-info}/top_level.txt +0 -0
alma/__init__.py CHANGED
@@ -1,226 +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
- 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.5.1"
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
- # Harness Pattern
84
- from alma.harness.base import (
85
- Agent,
86
- Context,
87
- Harness,
88
- MemorySchema,
89
- RunResult,
90
- Setting,
91
- Tool,
92
- ToolType,
93
- )
94
- from alma.harness.domains import (
95
- CodingDomain,
96
- ContentDomain,
97
- OperationsDomain,
98
- ResearchDomain,
99
- create_harness,
100
- )
101
-
102
- # Session Initializer (Phase 11)
103
- from alma.initializer import (
104
- CodebaseOrientation,
105
- InitializationResult,
106
- RulesOfEngagement,
107
- SessionInitializer,
108
- )
109
-
110
- # Observability (Phase 20)
111
- from alma.observability import (
112
- ALMAMetrics,
113
- configure_observability,
114
- get_logger,
115
- get_metrics,
116
- get_tracer,
117
- trace_method,
118
- )
119
-
120
- # Progress Tracking (Phase 10)
121
- from alma.progress import (
122
- ProgressLog,
123
- ProgressSummary,
124
- ProgressTracker,
125
- WorkItem,
126
- WorkItemStatus,
127
- )
128
-
129
- # Session Management (Phase 10)
130
- from alma.session import (
131
- SessionContext,
132
- SessionHandoff,
133
- SessionManager,
134
- SessionOutcome,
135
- )
136
- from alma.types import (
137
- AntiPattern,
138
- DomainKnowledge,
139
- Heuristic,
140
- MemoryScope,
141
- MemorySlice,
142
- Outcome,
143
- UserPreference,
144
- )
145
-
146
- __all__ = [
147
- # Core
148
- "ALMA",
149
- "Heuristic",
150
- "Outcome",
151
- "UserPreference",
152
- "DomainKnowledge",
153
- "AntiPattern",
154
- "MemorySlice",
155
- "MemoryScope",
156
- # Harness Pattern
157
- "Setting",
158
- "Context",
159
- "Agent",
160
- "MemorySchema",
161
- "Harness",
162
- "Tool",
163
- "ToolType",
164
- "RunResult",
165
- # Domain Configurations
166
- "CodingDomain",
167
- "ResearchDomain",
168
- "ContentDomain",
169
- "OperationsDomain",
170
- "create_harness",
171
- # Progress Tracking
172
- "WorkItem",
173
- "WorkItemStatus",
174
- "ProgressLog",
175
- "ProgressSummary",
176
- "ProgressTracker",
177
- # Session Management
178
- "SessionHandoff",
179
- "SessionContext",
180
- "SessionOutcome",
181
- "SessionManager",
182
- # Domain Memory Factory
183
- "DomainSchema",
184
- "EntityType",
185
- "RelationshipType",
186
- "DomainMemoryFactory",
187
- "get_coding_schema",
188
- "get_research_schema",
189
- "get_sales_schema",
190
- "get_general_schema",
191
- # Session Initializer
192
- "CodebaseOrientation",
193
- "InitializationResult",
194
- "RulesOfEngagement",
195
- "SessionInitializer",
196
- # Confidence Engine
197
- "ConfidenceEngine",
198
- "ConfidenceSignal",
199
- "OpportunitySignal",
200
- "RiskSignal",
201
- # Consolidation Engine
202
- "ConsolidationEngine",
203
- "ConsolidationResult",
204
- # Event System
205
- "MemoryEvent",
206
- "MemoryEventType",
207
- "EventEmitter",
208
- "get_emitter",
209
- "WebhookConfig",
210
- "WebhookManager",
211
- # Exceptions
212
- "ALMAError",
213
- "ConfigurationError",
214
- "ScopeViolationError",
215
- "StorageError",
216
- "EmbeddingError",
217
- "RetrievalError",
218
- "ExtractionError",
219
- # Observability
220
- "configure_observability",
221
- "get_tracer",
222
- "get_logger",
223
- "get_metrics",
224
- "ALMAMetrics",
225
- "trace_method",
226
- ]
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
+ ]