-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathsession.py
More file actions
28 lines (19 loc) · 755 Bytes
/
session.py
File metadata and controls
28 lines (19 loc) · 755 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"""Session — the persistable state of one conversation.
Holds the transcript plus a scratch of facts recalled for the current turn.
Persisted via :class:`SessionStorePort` keyed by ``Identity.session_key`` so a
thread picks up where it left off (tiebreaker #4).
"""
from __future__ import annotations
from dataclasses import dataclass, field
from ..core.identity import Identity
from ..core.types import Message
@dataclass
class Session:
identity: Identity
transcript: list[Message] = field(default_factory=list)
def add(self, message: Message) -> None:
self.transcript.append(message)
def history(self) -> list[Message]:
return list(self.transcript)
def reset(self) -> None:
self.transcript.clear()