| 116 | |
| 117 | @dataclass |
| 118 | class MemoryItem: |
| 119 | id: str |
| 120 | content_summary: str |
| 121 | metadata: Dict[str, Any] |
| 122 | embedding: Optional[List[float]] = None |
| 123 | timestamp: float | None = None |
| 124 | input_snapshot: MemoryContentSnapshot | None = None |
| 125 | output_snapshot: MemoryContentSnapshot | None = None |
| 126 | |
| 127 | def __post_init__(self) -> None: |
| 128 | if self.timestamp is None: |
| 129 | self.timestamp = time.time() |
| 130 | |
| 131 | def to_dict(self) -> Dict[str, Any]: |
| 132 | payload: Dict[str, Any] = { |
| 133 | "id": self.id, |
| 134 | "content_summary": self.content_summary, |
| 135 | "metadata": self.metadata, |
| 136 | "embedding": self.embedding, |
| 137 | "timestamp": self.timestamp, |
| 138 | } |
| 139 | if self.input_snapshot: |
| 140 | payload["input_snapshot"] = self.input_snapshot.to_dict() |
| 141 | if self.output_snapshot: |
| 142 | payload["output_snapshot"] = self.output_snapshot.to_dict() |
| 143 | return payload |
| 144 | |
| 145 | @classmethod |
| 146 | def from_dict(cls, payload: Dict[str, Any]) -> "MemoryItem": |
| 147 | return cls( |
| 148 | id=payload["id"], |
| 149 | content_summary=payload.get("content_summary", ""), |
| 150 | metadata=payload.get("metadata") or {}, |
| 151 | embedding=payload.get("embedding"), |
| 152 | timestamp=payload.get("timestamp"), |
| 153 | input_snapshot=MemoryContentSnapshot.from_dict(payload.get("input_snapshot")), |
| 154 | output_snapshot=MemoryContentSnapshot.from_dict(payload.get("output_snapshot")), |
| 155 | ) |
| 156 | |
| 157 | def attachments(self) -> List[Dict[str, Any]]: |
| 158 | attachments: List[Dict[str, Any]] = [] |
| 159 | if self.input_snapshot: |
| 160 | attachments.extend(self.input_snapshot.attachment_overview()) |
| 161 | if self.output_snapshot: |
| 162 | attachments.extend(self.output_snapshot.attachment_overview()) |
| 163 | return attachments |
| 164 | |
| 165 | |
| 166 | @dataclass |
no outgoing calls