feat: per-turn memory writes with witness flags
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
"""Per-turn memory writes (T21).
|
||||
|
||||
After ``assistant_turn`` lands, the turn flow records a ``memory_written``
|
||||
event for each present POV owner. Phase 1 single-bot turns only have the
|
||||
host bot as a memory-store owner — ``you`` doesn't have a memory store in
|
||||
v1 — so we write exactly one row per turn.
|
||||
|
||||
Phase 1 simplifications (per plan §11.1, T27 will refine):
|
||||
|
||||
- ``pov_summary`` is the assistant's raw narrative text. T27 rewrites at
|
||||
scene close into per-POV summary form.
|
||||
- ``significance`` defaults to ``1`` (Notable). T22's async significance
|
||||
pass overwrites via a follow-up event.
|
||||
- Witness flags are hard-coded ``[you=1, host=1, guest=0]``. Phase 2 will
|
||||
derive them from ``chat.guest_bot_id`` once a guest can be present.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from sqlite3 import Connection
|
||||
|
||||
from chat.eventlog.log import append_and_apply
|
||||
|
||||
|
||||
def record_turn_memory(
|
||||
conn: Connection,
|
||||
*,
|
||||
chat_id: str,
|
||||
host_bot_id: str,
|
||||
narrative_text: str,
|
||||
scene_id: int | None = None,
|
||||
chat_clock_at: str | None = None,
|
||||
source: str = "direct",
|
||||
significance: int = 1,
|
||||
) -> int:
|
||||
"""Append a ``memory_written`` event for the host bot's POV of this turn.
|
||||
|
||||
Uses :func:`chat.eventlog.log.append_and_apply` (not raw
|
||||
:func:`append_event`) so the new memory row is projected immediately
|
||||
without re-running prior non-idempotent handlers (e.g. ``edge_update``
|
||||
deltas). Returns the new event id.
|
||||
"""
|
||||
payload: dict = {
|
||||
"owner_id": host_bot_id,
|
||||
"chat_id": chat_id,
|
||||
"pov_summary": narrative_text,
|
||||
"witness_you": 1,
|
||||
"witness_host": 1,
|
||||
"witness_guest": 0,
|
||||
"source": source,
|
||||
"reliability": 1.0,
|
||||
"significance": significance,
|
||||
"pinned": 0,
|
||||
"auto_pinned": 0,
|
||||
}
|
||||
if scene_id is not None:
|
||||
payload["scene_id"] = scene_id
|
||||
if chat_clock_at is not None:
|
||||
payload["chat_clock_at"] = chat_clock_at
|
||||
|
||||
return append_and_apply(conn, kind="memory_written", payload=payload)
|
||||
Reference in New Issue
Block a user