aaa.session¶
SessionManager ¶
SessionManager(
engine: Engine,
algo: Algorithm,
*,
system: str = "",
context: ContextPolicy | None = None,
turn_budget: Budget | None = None,
session_budget: Budget | None = None,
)
Creates, finds and lists sessions for one inner algorithm. Build it in EVERY process that may handle a turn (workers register the algorithms; clients just call it).
create
async
¶
create(
*,
tenant: str | None = None,
user: str | None = None,
title: str | None = None,
meta: dict[str, str | int | float | bool] | None = None,
session_id: str | None = None,
) -> Session
A new session. user is who it is for (memory is scoped by it; it is never taken from the model).
get
async
¶
Reattach to an existing session. KeyError if it does not exist or belongs to another tenant.
Session ¶
wait
async
¶
The reply to turn, from any process, even if the one that sent it died. Raises SessionClosed if
the session ends first.
send
async
¶
Say something and wait for the answer. One turn at a time (SessionBusy).
stream
async
¶
Like send, but iterate the reply as it is written (needs an inner algorithm built with stream=True).
close
async
¶
End the session. A running turn is cancelled. A closed session is an ordinary finished run, so it can be erased and falls under retention like any other.
TenantSessions ¶
Sessions of one tenant: ids are namespaced and a lookup of another tenant's session is a plain KeyError.
TurnResult
dataclass
¶
TurnResult(
turn: int,
text: str,
kind: str,
reason: str | None = None,
run_id: str | None = None,
)
TurnStream ¶
async for piece in chat.stream(...) yields the reply as it is written; await s.result() is the final turn.
Turn ¶
Bases: BaseModel
SessionAlgo ¶
SessionAlgo(
inner: Algorithm,
*,
system: str = "",
context: ContextPolicy | None = None,
turn_budget: Budget | None = None,
)
Reacts to aaa.session.message by starting the inner algorithm on the conversation, and to the child's
completion by recording aaa.session.reply. Stateless, like every algorithm: all state is the stream.