| from dataclasses import dataclass, field |
| from datetime import datetime, timezone |
| from enum import Enum |
| from typing import Any, Dict, List, Optional |
| import uuid |
|
|
|
|
| class MemoryTier(str, Enum): |
| ASSOCIATIVE = "associative" |
| TEMPORAL = "temporal" |
| EXPERIENTIAL = "experiential" |
| WORKING = "working" |
|
|
|
|
| class MemoryOutcome(str, Enum): |
| SUCCESS = "success" |
| FAILURE = "failure" |
| GUARDRAIL = "guardrail" |
|
|
|
|
| @dataclass |
| class MemoryItem: |
| """Base unit for all memory tiers.""" |
| item_id: str = field(default_factory=lambda: str(uuid.uuid4())) |
| tier: MemoryTier = MemoryTier.WORKING |
| title: str = "" |
| content: str = "" |
| tags: List[str] = field(default_factory=list) |
| confidence: float = 0.5 |
| usage_count: int = 0 |
| created_at: datetime = field(default_factory=lambda: datetime.now(timezone.utc)) |
| updated_at: datetime = field(default_factory=lambda: datetime.now(timezone.utc)) |
| metadata: Dict[str, Any] = field(default_factory=dict) |
|
|
|
|
| @dataclass |
| class ExperientialStrategy(MemoryItem): |
| """ |
| ReasoningBank entry — Title + Description + Procedural Content. |
| Extracted from both successful paths and failure counterfactuals. |
| """ |
| tier: MemoryTier = field(default=MemoryTier.EXPERIENTIAL) |
| description: str = "" |
| outcome: MemoryOutcome = MemoryOutcome.SUCCESS |
| kind: str = "strategy" |
| is_guardrail: bool = False |
| task_pattern: str = "" |
|
|
|
|
| @dataclass |
| class TemporalEdge: |
| """Weighted directed edge in the temporal knowledge graph.""" |
| source_id: str = "" |
| target_id: str = "" |
| relation: str = "" |
| weight: float = 1.0 |
| last_updated: datetime = field(default_factory=lambda: datetime.now(timezone.utc)) |
|
|
|
|
| @dataclass |
| class RetrievalResult: |
| """Scored output from the memory retriever.""" |
| item: MemoryItem |
| relevance_score: float = 0.0 |
| similarity: float = 0.0 |
| confidence_contribution: float = 0.0 |
| usage_contribution: float = 0.0 |
|
|