feat: inject session mode into persona system prompt
context_loader.load_context() now accepts a mode param ("chat"|"otr").
In OTR mode, the --- System --- block gains a second line:
Current mode: Off The Record — this conversation is private
and will not be logged or included in memory distillation
routers/chat.py passes mode="otr" when req.off_record is True.
Normal chat and all orchestrator calls stay at mode="chat" (no change
to the System block). The System block consolidates date/time and mode
in one place, matching the existing timestamp pattern.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -21,6 +21,7 @@ def load_context(
|
|||||||
include_short: bool = True,
|
include_short: bool = True,
|
||||||
role_append: str = "",
|
role_append: str = "",
|
||||||
inject_datetime: bool = True,
|
inject_datetime: bool = True,
|
||||||
|
mode: str = "chat",
|
||||||
) -> str:
|
) -> str:
|
||||||
"""
|
"""
|
||||||
Build the system-prompt context block for a given tier and memory toggles.
|
Build the system-prompt context block for a given tier and memory toggles.
|
||||||
@@ -39,10 +40,18 @@ def load_context(
|
|||||||
inara_dir = persona_path()
|
inara_dir = persona_path()
|
||||||
parts = []
|
parts = []
|
||||||
|
|
||||||
# ── 0. Current date and time (per-role toggle — injected first so it's prominent) ──
|
# ── 0. System block — date/time and session mode (injected first so it's prominent) ──
|
||||||
|
system_lines = []
|
||||||
if inject_datetime:
|
if inject_datetime:
|
||||||
now = datetime.now().astimezone()
|
now = datetime.now().astimezone()
|
||||||
parts.append(f"--- System ---\nCurrent date and time: {now.strftime('%A, %Y-%m-%d at %I:%M %p %Z')}")
|
system_lines.append(f"Current date and time: {now.strftime('%A, %Y-%m-%d at %I:%M %p %Z')}")
|
||||||
|
if mode == "otr":
|
||||||
|
system_lines.append(
|
||||||
|
"Current mode: Off The Record — "
|
||||||
|
"this conversation is private and will not be logged or included in memory distillation"
|
||||||
|
)
|
||||||
|
if system_lines:
|
||||||
|
parts.append("--- System ---\n" + "\n".join(system_lines))
|
||||||
|
|
||||||
# ── 1. Core identity (always) ──────────────────────────────────
|
# ── 1. Core identity (always) ──────────────────────────────────
|
||||||
for filename in _CORE:
|
for filename in _CORE:
|
||||||
|
|||||||
@@ -95,6 +95,7 @@ async def _stream_chat(req: ChatRequest):
|
|||||||
include_long=req.include_long,
|
include_long=req.include_long,
|
||||||
include_mid=req.include_mid,
|
include_mid=req.include_mid,
|
||||||
include_short=req.include_short,
|
include_short=req.include_short,
|
||||||
|
mode="otr" if req.off_record else "chat",
|
||||||
)
|
)
|
||||||
history = load_session(session_id)
|
history = load_session(session_id)
|
||||||
history.append({"role": "user", "content": req.message})
|
history.append({"role": "user", "content": req.message})
|
||||||
|
|||||||
Reference in New Issue
Block a user