add. cleanup
This commit is contained in:
@@ -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 Intake’s 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}
|
||||
|
||||
Reference in New Issue
Block a user