add. cleanup

This commit is contained in:
serversdwn
2025-11-30 03:58:15 -05:00
parent 320bf4439b
commit fc85557f76
3 changed files with 73 additions and 5 deletions

View File

@@ -1,6 +1,13 @@
import os
from datetime import datetime
from typing import List, Dict, Any
from typing import List, Dict, Any, TYPE_CHECKING
if TYPE_CHECKING:
from collections import deque as _deque
SESSIONS: dict
L10_HISTORY: dict
L20_HISTORY: dict
def bg_summarize(session_id: str) -> None: ...
from llm.llm_router import call_llm # use Cortex's shared router
@@ -258,3 +265,36 @@ async def summarize_context(
"L30": L30,
"last_updated": datetime.now().isoformat(),
}
# ─────────────────────────────
# Internal entrypoint for Cortex
# ─────────────────────────────
def add_exchange_internal(exchange: dict):
"""
Direct internal call — bypasses FastAPI request handling.
Cortex uses this to feed user/assistant turns directly
into Intakes buffer and trigger full summarization.
"""
session_id = exchange.get("session_id")
if not session_id:
raise ValueError("session_id missing")
exchange["timestamp"] = datetime.now().isoformat()
# Ensure session exists
if session_id not in SESSIONS:
SESSIONS[session_id] = {
"buffer": deque(maxlen=200),
"created_at": datetime.now()
}
# Append exchange into the rolling buffer
SESSIONS[session_id]["buffer"].append(exchange)
# Trigger summarization immediately
try:
bg_summarize(session_id)
except Exception as e:
print(f"[Internal Intake] Summarization error: {e}")
return {"ok": True, "session_id": session_id}