Wire batch gen into Session.reset behind CALLER_REDESIGN flag

This commit is contained in:
2026-04-05 03:06:42 -06:00
parent d4f1043be1
commit 969f8fb2fd
+74
View File
@@ -7147,6 +7147,58 @@ class Session:
}
return None
async def _pregenerate_backgrounds_slim(self):
"""New path: single sonnet-4.6 batch call generates all caller identities."""
from .services import caller_gen, regulars_v2
from datetime import datetime
voice_roster = [name for name in INWORLD_MALE_VOICES + INWORLD_FEMALE_VOICES
if name not in BLACKLISTED_VOICES]
active_regulars = regulars_v2.load_all_active_regulars()
regulars_for_tonight = [
{"name": r.name, "lore": r.lore_body, "arc_state": r.arc_state}
for r in active_regulars
][:3]
headlines: list[str] = []
if self.news_headlines:
for h in self.news_headlines[:5]:
headlines.append(h.title if hasattr(h, "title") else str(h))
ctx = {
"date": datetime.now().strftime("%A, %B %d, %Y"),
"weather": "cool desert night", # TODO: real weather feed
"headlines": headlines,
"recent_caller_summaries": self._get_recent_summaries(),
"regulars_included": regulars_for_tonight,
"caller_count": 12,
"voice_roster": voice_roster,
}
identities = await caller_gen.generate_batch(ctx)
for i, identity in enumerate(identities[:10]):
key = str(i + 1)
self.caller_backgrounds[key] = {
"name": identity.name,
"age": identity.age,
"voice": identity.voice_resolved,
"location": identity.location,
"identity": identity.identity,
"situation": identity.situation,
"reason_calling": identity.reason_calling,
"opening_line": identity.opening_line,
"secret_want": identity.secret_want,
"specific_details": identity.specific_details,
"emotional_register": identity.emotional_register,
}
print(f"[Background] Slim batch generated {len(identities[:10])} caller identities")
def _get_recent_summaries(self) -> list[str]:
# Return last 2 shows' caller summaries — stub for now, can wire into cost_db
return []
def reset(self):
"""Reset session - clears all caller backgrounds for fresh personalities"""
self.caller_backgrounds = {}
@@ -7639,6 +7691,9 @@ async def startup():
asyncio.create_task(_poll_imap_emails())
restored = _load_checkpoint()
if not restored:
if session.use_slim_caller_path:
asyncio.create_task(session._pregenerate_backgrounds_slim())
else:
asyncio.create_task(_pregenerate_backgrounds())
asyncio.create_task(avatar_service.ensure_devon())
threading.Thread(target=_update_on_air_cdn, args=(False,), daemon=True).start()
@@ -8540,6 +8595,9 @@ async def reset_session():
session.reset()
_chat_updates.clear()
# Pre-generate backgrounds in background so they're ready when callers are clicked
if session.use_slim_caller_path:
asyncio.create_task(session._pregenerate_backgrounds_slim())
else:
asyncio.create_task(_pregenerate_backgrounds())
return {"status": "reset", "session_id": session.id}
@@ -9602,6 +9660,10 @@ async def chat(request: ChatRequest):
mood += "\nSay goodbye NOW and end with [HANGUP]\n"
rel_ctx = session.relationship_context.get(session.current_caller_key, "")
if session.use_slim_caller_path:
slim_caller = session.caller_backgrounds.get(session.current_caller_key, {})
system_prompt = get_caller_prompt_slim(slim_caller)
else:
system_prompt = get_caller_prompt(session.caller, show_history, emotional_read=mood, relationship_context=rel_ctx)
call_shape = session.caller.get("shape", "standard") if session.caller else "standard"
@@ -10231,6 +10293,10 @@ async def show_preflight(test_responses: bool = False):
# Run all tests in parallel for speed
async def _test_caller(key, base, model):
if session.use_slim_caller_path:
slim_caller = session.caller_backgrounds.get(key, {})
prompt = get_caller_prompt_slim(slim_caller)
else:
caller_data = {
"name": base.get("name", key),
"vibe": session.get_caller_background(key),
@@ -10845,6 +10911,10 @@ async def _trigger_ai_auto_respond(accumulated_text: str):
if session._wrapup_exchanges > 2:
mood += "\nSay goodbye NOW and end with [HANGUP]\n"
rel_ctx = session.relationship_context.get(session.current_caller_key, "")
if session.use_slim_caller_path:
slim_caller = session.caller_backgrounds.get(session.current_caller_key, {})
system_prompt = get_caller_prompt_slim(slim_caller)
else:
system_prompt = get_caller_prompt(session.caller, show_history, emotional_read=mood, relationship_context=rel_ctx)
call_shape = session.caller.get("shape", "standard") if session.caller else "standard"
@@ -10967,6 +11037,10 @@ async def ai_respond():
if session._wrapup_exchanges > 2:
mood += "\nSay goodbye NOW and end with [HANGUP]\n"
rel_ctx = session.relationship_context.get(session.current_caller_key, "")
if session.use_slim_caller_path:
slim_caller = session.caller_backgrounds.get(session.current_caller_key, {})
system_prompt = get_caller_prompt_slim(slim_caller)
else:
system_prompt = get_caller_prompt(session.caller, show_history, emotional_read=mood, relationship_context=rel_ctx)
call_shape = session.caller.get("shape", "standard") if session.caller else "standard"