aimu.sessions¶
Multi-user session storage: per-conversation state keyed by channel:sender, so one process serves many users/chats. See how-to: use sessions.
Sync, matching the MemoryStore / ConversationManager family; the async assistant loop calls it directly.
aimu.sessions.Session
dataclass
¶
Session(key: str, messages: list[dict] = list(), memory_namespace: Optional[str] = None, metadata: dict[str, Any] = dict())
One conversation's persisted state.
Attributes:
| Name | Type | Description |
|---|---|---|
key |
str
|
The session key (see :func: |
messages |
list[dict]
|
Conversation history as |
memory_namespace |
Optional[str]
|
Optional scope a caller can pass to a |
metadata |
dict[str, Any]
|
Free-form, opaque to the library (display name, locale, ...). |
aimu.sessions.SessionStore ¶
Bases: ABC
A store of :class:Session state keyed by session_key(channel, sender).
get returns a detached snapshot (mutating it does nothing until save); save persists.
aimu.sessions.InMemorySessionStore ¶
Bases: SessionStore
A non-durable :class:SessionStore backed by a dict. Sessions are lost on process exit.
get and save copy, so the stored state is detached from the returned/passed object
(same contract as the persisted stores).
aimu.sessions.TinyDBSessionStore ¶
Bases: SessionStore
A durable :class:SessionStore persisting one document per session to a TinyDB file.
aimu.sessions.SessionLocks ¶
Lazily-created per-key asyncio.Lock.
Serializes a single session's turns (shared message state, ordering) while letting different sessions run concurrently::
locks = SessionLocks()
async with locks(key):
... # this session's turn
Created locks are retained, so the same key always returns the same lock. Bound to the running
event loop via asyncio.Lock; use one SessionLocks per assistant process.
aimu.sessions.session_key ¶
Canonical session key from a message's channel + sender.
Single-user transports (no channel/sender) collapse to "default:default", so single-user
usage needs no ceremony.