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.
- alma/__init__.py +296 -226
- alma/compression/__init__.py +33 -0
- alma/compression/pipeline.py +980 -0
- alma/confidence/__init__.py +47 -47
- alma/confidence/engine.py +540 -540
- alma/confidence/types.py +351 -351
- alma/config/loader.py +157 -157
- alma/consolidation/__init__.py +23 -23
- alma/consolidation/engine.py +678 -678
- alma/consolidation/prompts.py +84 -84
- alma/core.py +1189 -430
- alma/domains/__init__.py +30 -30
- alma/domains/factory.py +359 -359
- alma/domains/schemas.py +448 -448
- alma/domains/types.py +272 -272
- alma/events/__init__.py +75 -75
- alma/events/emitter.py +285 -284
- alma/events/storage_mixin.py +246 -246
- alma/events/types.py +126 -126
- alma/events/webhook.py +425 -425
- alma/exceptions.py +49 -49
- alma/extraction/__init__.py +31 -31
- alma/extraction/auto_learner.py +265 -265
- alma/extraction/extractor.py +420 -420
- alma/graph/__init__.py +106 -106
- alma/graph/backends/__init__.py +32 -32
- alma/graph/backends/kuzu.py +624 -624
- alma/graph/backends/memgraph.py +432 -432
- alma/graph/backends/memory.py +236 -236
- alma/graph/backends/neo4j.py +417 -417
- alma/graph/base.py +159 -159
- alma/graph/extraction.py +198 -198
- alma/graph/store.py +860 -860
- alma/harness/__init__.py +35 -35
- alma/harness/base.py +386 -386
- alma/harness/domains.py +705 -705
- alma/initializer/__init__.py +37 -37
- alma/initializer/initializer.py +418 -418
- alma/initializer/types.py +250 -250
- alma/integration/__init__.py +62 -62
- alma/integration/claude_agents.py +444 -444
- alma/integration/helena.py +423 -423
- alma/integration/victor.py +471 -471
- alma/learning/__init__.py +101 -86
- alma/learning/decay.py +878 -0
- alma/learning/forgetting.py +1446 -1446
- alma/learning/heuristic_extractor.py +390 -390
- alma/learning/protocols.py +374 -374
- alma/learning/validation.py +346 -346
- alma/mcp/__init__.py +123 -45
- alma/mcp/__main__.py +156 -156
- alma/mcp/resources.py +122 -122
- alma/mcp/server.py +955 -591
- alma/mcp/tools.py +3254 -509
- alma/observability/__init__.py +91 -84
- alma/observability/config.py +302 -302
- alma/observability/guidelines.py +170 -0
- alma/observability/logging.py +424 -424
- alma/observability/metrics.py +583 -583
- alma/observability/tracing.py +440 -440
- alma/progress/__init__.py +21 -21
- alma/progress/tracker.py +607 -607
- alma/progress/types.py +250 -250
- alma/retrieval/__init__.py +134 -53
- alma/retrieval/budget.py +525 -0
- alma/retrieval/cache.py +1304 -1061
- alma/retrieval/embeddings.py +202 -202
- alma/retrieval/engine.py +850 -427
- alma/retrieval/modes.py +365 -0
- alma/retrieval/progressive.py +560 -0
- alma/retrieval/scoring.py +344 -344
- alma/retrieval/trust_scoring.py +637 -0
- alma/retrieval/verification.py +797 -0
- alma/session/__init__.py +19 -19
- alma/session/manager.py +442 -399
- alma/session/types.py +288 -288
- alma/storage/__init__.py +101 -90
- alma/storage/archive.py +233 -0
- alma/storage/azure_cosmos.py +1259 -1259
- alma/storage/base.py +1083 -583
- alma/storage/chroma.py +1443 -1443
- alma/storage/constants.py +103 -103
- alma/storage/file_based.py +614 -614
- alma/storage/migrations/__init__.py +21 -21
- alma/storage/migrations/base.py +321 -321
- alma/storage/migrations/runner.py +323 -323
- alma/storage/migrations/version_stores.py +337 -337
- alma/storage/migrations/versions/__init__.py +11 -11
- alma/storage/migrations/versions/v1_0_0.py +373 -373
- alma/storage/migrations/versions/v1_1_0_workflow_context.py +551 -0
- alma/storage/pinecone.py +1080 -1080
- alma/storage/postgresql.py +1948 -1559
- alma/storage/qdrant.py +1306 -1306
- alma/storage/sqlite_local.py +3041 -1457
- alma/testing/__init__.py +46 -46
- alma/testing/factories.py +301 -301
- alma/testing/mocks.py +389 -389
- alma/types.py +292 -264
- alma/utils/__init__.py +19 -0
- alma/utils/tokenizer.py +521 -0
- alma/workflow/__init__.py +83 -0
- alma/workflow/artifacts.py +170 -0
- alma/workflow/checkpoint.py +311 -0
- alma/workflow/context.py +228 -0
- alma/workflow/outcomes.py +189 -0
- alma/workflow/reducers.py +393 -0
- {alma_memory-0.5.1.dist-info → alma_memory-0.7.0.dist-info}/METADATA +210 -72
- alma_memory-0.7.0.dist-info/RECORD +112 -0
- alma_memory-0.5.1.dist-info/RECORD +0 -93
- {alma_memory-0.5.1.dist-info → alma_memory-0.7.0.dist-info}/WHEEL +0 -0
- {alma_memory-0.5.1.dist-info → alma_memory-0.7.0.dist-info}/top_level.txt +0 -0
alma/events/types.py
CHANGED
|
@@ -1,126 +1,126 @@
|
|
|
1
|
-
"""
|
|
2
|
-
ALMA Event Types.
|
|
3
|
-
|
|
4
|
-
Defines event types and the MemoryEvent dataclass for the event system.
|
|
5
|
-
"""
|
|
6
|
-
|
|
7
|
-
from dataclasses import dataclass, field
|
|
8
|
-
from datetime import datetime, timezone
|
|
9
|
-
from enum import Enum
|
|
10
|
-
from typing import Any, Dict, Optional
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
class MemoryEventType(Enum):
|
|
14
|
-
"""Types of events that can be emitted by the memory system."""
|
|
15
|
-
|
|
16
|
-
# Core memory operations
|
|
17
|
-
CREATED = "memory.created"
|
|
18
|
-
UPDATED = "memory.updated"
|
|
19
|
-
DELETED = "memory.deleted"
|
|
20
|
-
CONSOLIDATED = "memory.consolidated"
|
|
21
|
-
|
|
22
|
-
# Learning-specific events
|
|
23
|
-
HEURISTIC_FORMED = "heuristic.formed"
|
|
24
|
-
ANTIPATTERN_DETECTED = "antipattern.detected"
|
|
25
|
-
PREFERENCE_ADDED = "preference.added"
|
|
26
|
-
KNOWLEDGE_ADDED = "knowledge.added"
|
|
27
|
-
|
|
28
|
-
# Confidence events
|
|
29
|
-
CONFIDENCE_UPDATED = "confidence.updated"
|
|
30
|
-
CONFIDENCE_DECAYED = "confidence.decayed"
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
@dataclass
|
|
34
|
-
class MemoryEvent:
|
|
35
|
-
"""
|
|
36
|
-
Represents an event in the memory system.
|
|
37
|
-
|
|
38
|
-
Events are emitted when memory operations occur, allowing external
|
|
39
|
-
systems to react to changes through callbacks or webhooks.
|
|
40
|
-
|
|
41
|
-
Attributes:
|
|
42
|
-
event_type: The type of event that occurred
|
|
43
|
-
agent: Name of the agent associated with the event
|
|
44
|
-
project_id: Project identifier
|
|
45
|
-
memory_type: Type of memory (heuristics, outcomes, etc.)
|
|
46
|
-
memory_id: Unique identifier of the affected memory
|
|
47
|
-
timestamp: When the event occurred
|
|
48
|
-
payload: Event-specific data (e.g., the created memory)
|
|
49
|
-
metadata: Optional additional context
|
|
50
|
-
"""
|
|
51
|
-
|
|
52
|
-
event_type: MemoryEventType
|
|
53
|
-
agent: str
|
|
54
|
-
project_id: str
|
|
55
|
-
memory_type: (
|
|
56
|
-
str # heuristics, outcomes, preferences, domain_knowledge, anti_patterns
|
|
57
|
-
)
|
|
58
|
-
memory_id: str
|
|
59
|
-
timestamp: datetime
|
|
60
|
-
payload: Dict[str, Any]
|
|
61
|
-
metadata: Optional[Dict[str, Any]] = field(default_factory=dict)
|
|
62
|
-
|
|
63
|
-
def to_dict(self) -> Dict[str, Any]:
|
|
64
|
-
"""Convert event to dictionary for serialization."""
|
|
65
|
-
return {
|
|
66
|
-
"event_type": self.event_type.value,
|
|
67
|
-
"agent": self.agent,
|
|
68
|
-
"project_id": self.project_id,
|
|
69
|
-
"memory_type": self.memory_type,
|
|
70
|
-
"memory_id": self.memory_id,
|
|
71
|
-
"timestamp": self.timestamp.isoformat(),
|
|
72
|
-
"payload": self.payload,
|
|
73
|
-
"metadata": self.metadata or {},
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
@classmethod
|
|
77
|
-
def from_dict(cls, data: Dict[str, Any]) -> "MemoryEvent":
|
|
78
|
-
"""Create event from dictionary."""
|
|
79
|
-
return cls(
|
|
80
|
-
event_type=MemoryEventType(data["event_type"]),
|
|
81
|
-
agent=data["agent"],
|
|
82
|
-
project_id=data["project_id"],
|
|
83
|
-
memory_type=data["memory_type"],
|
|
84
|
-
memory_id=data["memory_id"],
|
|
85
|
-
timestamp=datetime.fromisoformat(data["timestamp"]),
|
|
86
|
-
payload=data["payload"],
|
|
87
|
-
metadata=data.get("metadata"),
|
|
88
|
-
)
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
def create_memory_event(
|
|
92
|
-
event_type: MemoryEventType,
|
|
93
|
-
agent: str,
|
|
94
|
-
project_id: str,
|
|
95
|
-
memory_type: str,
|
|
96
|
-
memory_id: str,
|
|
97
|
-
payload: Dict[str, Any],
|
|
98
|
-
metadata: Optional[Dict[str, Any]] = None,
|
|
99
|
-
*,
|
|
100
|
-
default_metadata: bool = True,
|
|
101
|
-
) -> MemoryEvent:
|
|
102
|
-
"""
|
|
103
|
-
Factory function to create a MemoryEvent with current timestamp.
|
|
104
|
-
|
|
105
|
-
Args:
|
|
106
|
-
event_type: Type of event
|
|
107
|
-
agent: Agent name
|
|
108
|
-
project_id: Project identifier
|
|
109
|
-
memory_type: Type of memory
|
|
110
|
-
memory_id: Memory identifier
|
|
111
|
-
payload: Event-specific data
|
|
112
|
-
metadata: Optional additional context
|
|
113
|
-
|
|
114
|
-
Returns:
|
|
115
|
-
A new MemoryEvent instance
|
|
116
|
-
"""
|
|
117
|
-
return MemoryEvent(
|
|
118
|
-
event_type=event_type,
|
|
119
|
-
agent=agent,
|
|
120
|
-
project_id=project_id,
|
|
121
|
-
memory_type=memory_type,
|
|
122
|
-
memory_id=memory_id,
|
|
123
|
-
timestamp=datetime.now(timezone.utc),
|
|
124
|
-
payload=payload,
|
|
125
|
-
metadata=metadata if metadata is not None else {},
|
|
126
|
-
)
|
|
1
|
+
"""
|
|
2
|
+
ALMA Event Types.
|
|
3
|
+
|
|
4
|
+
Defines event types and the MemoryEvent dataclass for the event system.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from dataclasses import dataclass, field
|
|
8
|
+
from datetime import datetime, timezone
|
|
9
|
+
from enum import Enum
|
|
10
|
+
from typing import Any, Dict, Optional
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class MemoryEventType(Enum):
|
|
14
|
+
"""Types of events that can be emitted by the memory system."""
|
|
15
|
+
|
|
16
|
+
# Core memory operations
|
|
17
|
+
CREATED = "memory.created"
|
|
18
|
+
UPDATED = "memory.updated"
|
|
19
|
+
DELETED = "memory.deleted"
|
|
20
|
+
CONSOLIDATED = "memory.consolidated"
|
|
21
|
+
|
|
22
|
+
# Learning-specific events
|
|
23
|
+
HEURISTIC_FORMED = "heuristic.formed"
|
|
24
|
+
ANTIPATTERN_DETECTED = "antipattern.detected"
|
|
25
|
+
PREFERENCE_ADDED = "preference.added"
|
|
26
|
+
KNOWLEDGE_ADDED = "knowledge.added"
|
|
27
|
+
|
|
28
|
+
# Confidence events
|
|
29
|
+
CONFIDENCE_UPDATED = "confidence.updated"
|
|
30
|
+
CONFIDENCE_DECAYED = "confidence.decayed"
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@dataclass
|
|
34
|
+
class MemoryEvent:
|
|
35
|
+
"""
|
|
36
|
+
Represents an event in the memory system.
|
|
37
|
+
|
|
38
|
+
Events are emitted when memory operations occur, allowing external
|
|
39
|
+
systems to react to changes through callbacks or webhooks.
|
|
40
|
+
|
|
41
|
+
Attributes:
|
|
42
|
+
event_type: The type of event that occurred
|
|
43
|
+
agent: Name of the agent associated with the event
|
|
44
|
+
project_id: Project identifier
|
|
45
|
+
memory_type: Type of memory (heuristics, outcomes, etc.)
|
|
46
|
+
memory_id: Unique identifier of the affected memory
|
|
47
|
+
timestamp: When the event occurred
|
|
48
|
+
payload: Event-specific data (e.g., the created memory)
|
|
49
|
+
metadata: Optional additional context
|
|
50
|
+
"""
|
|
51
|
+
|
|
52
|
+
event_type: MemoryEventType
|
|
53
|
+
agent: str
|
|
54
|
+
project_id: str
|
|
55
|
+
memory_type: (
|
|
56
|
+
str # heuristics, outcomes, preferences, domain_knowledge, anti_patterns
|
|
57
|
+
)
|
|
58
|
+
memory_id: str
|
|
59
|
+
timestamp: datetime
|
|
60
|
+
payload: Dict[str, Any]
|
|
61
|
+
metadata: Optional[Dict[str, Any]] = field(default_factory=dict)
|
|
62
|
+
|
|
63
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
64
|
+
"""Convert event to dictionary for serialization."""
|
|
65
|
+
return {
|
|
66
|
+
"event_type": self.event_type.value,
|
|
67
|
+
"agent": self.agent,
|
|
68
|
+
"project_id": self.project_id,
|
|
69
|
+
"memory_type": self.memory_type,
|
|
70
|
+
"memory_id": self.memory_id,
|
|
71
|
+
"timestamp": self.timestamp.isoformat(),
|
|
72
|
+
"payload": self.payload,
|
|
73
|
+
"metadata": self.metadata or {},
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
@classmethod
|
|
77
|
+
def from_dict(cls, data: Dict[str, Any]) -> "MemoryEvent":
|
|
78
|
+
"""Create event from dictionary."""
|
|
79
|
+
return cls(
|
|
80
|
+
event_type=MemoryEventType(data["event_type"]),
|
|
81
|
+
agent=data["agent"],
|
|
82
|
+
project_id=data["project_id"],
|
|
83
|
+
memory_type=data["memory_type"],
|
|
84
|
+
memory_id=data["memory_id"],
|
|
85
|
+
timestamp=datetime.fromisoformat(data["timestamp"]),
|
|
86
|
+
payload=data["payload"],
|
|
87
|
+
metadata=data.get("metadata"),
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def create_memory_event(
|
|
92
|
+
event_type: MemoryEventType,
|
|
93
|
+
agent: str,
|
|
94
|
+
project_id: str,
|
|
95
|
+
memory_type: str,
|
|
96
|
+
memory_id: str,
|
|
97
|
+
payload: Dict[str, Any],
|
|
98
|
+
metadata: Optional[Dict[str, Any]] = None,
|
|
99
|
+
*,
|
|
100
|
+
default_metadata: bool = True,
|
|
101
|
+
) -> MemoryEvent:
|
|
102
|
+
"""
|
|
103
|
+
Factory function to create a MemoryEvent with current timestamp.
|
|
104
|
+
|
|
105
|
+
Args:
|
|
106
|
+
event_type: Type of event
|
|
107
|
+
agent: Agent name
|
|
108
|
+
project_id: Project identifier
|
|
109
|
+
memory_type: Type of memory
|
|
110
|
+
memory_id: Memory identifier
|
|
111
|
+
payload: Event-specific data
|
|
112
|
+
metadata: Optional additional context
|
|
113
|
+
|
|
114
|
+
Returns:
|
|
115
|
+
A new MemoryEvent instance
|
|
116
|
+
"""
|
|
117
|
+
return MemoryEvent(
|
|
118
|
+
event_type=event_type,
|
|
119
|
+
agent=agent,
|
|
120
|
+
project_id=project_id,
|
|
121
|
+
memory_type=memory_type,
|
|
122
|
+
memory_id=memory_id,
|
|
123
|
+
timestamp=datetime.now(timezone.utc),
|
|
124
|
+
payload=payload,
|
|
125
|
+
metadata=metadata if metadata is not None else {},
|
|
126
|
+
)
|