intake internalized by cortex, removed intake route in relay
This commit is contained in:
@@ -15,13 +15,14 @@ import logging
|
||||
from datetime import datetime
|
||||
from typing import Dict, Any, Optional, List
|
||||
import httpx
|
||||
from intake.intake import summarize_context
|
||||
|
||||
|
||||
from neomem_client import NeoMemClient
|
||||
|
||||
# -----------------------------
|
||||
# Configuration
|
||||
# -----------------------------
|
||||
INTAKE_API_URL = os.getenv("INTAKE_API_URL", "http://intake:7080")
|
||||
NEOMEM_API = os.getenv("NEOMEM_API", "http://neomem-api:8000")
|
||||
RELEVANCE_THRESHOLD = float(os.getenv("RELEVANCE_THRESHOLD", "0.4"))
|
||||
VERBOSE_DEBUG = os.getenv("VERBOSE_DEBUG", "false").lower() == "true"
|
||||
@@ -89,69 +90,27 @@ def _init_session(session_id: str) -> Dict[str, Any]:
|
||||
# -----------------------------
|
||||
# Intake context retrieval
|
||||
# -----------------------------
|
||||
async def _get_intake_context(session_id: str) -> Dict[str, Any]:
|
||||
async def _get_intake_context(session_id: str, messages: List[Dict[str, str]]):
|
||||
"""
|
||||
Retrieve multilevel summaries from Intake /context endpoint.
|
||||
|
||||
Returns L1-L30 summary hierarchy:
|
||||
- L1: Last 5 exchanges
|
||||
- L5: Last 10 exchanges (reality check)
|
||||
- L10: Intermediate checkpoint
|
||||
- L20: Session overview
|
||||
- L30: Continuity report
|
||||
|
||||
Args:
|
||||
session_id: Session identifier
|
||||
|
||||
Returns:
|
||||
Dict with multilevel summaries or empty structure on failure
|
||||
Internal Intake — Direct call to summarize_context()
|
||||
No HTTP, no containers, no failures.
|
||||
"""
|
||||
url = f"{INTAKE_API_URL}/context"
|
||||
params = {"session_id": session_id}
|
||||
|
||||
try:
|
||||
async with httpx.AsyncClient(timeout=5.0) as client:
|
||||
response = await client.get(url, params=params)
|
||||
response.raise_for_status()
|
||||
data = response.json()
|
||||
|
||||
# Expected format from Intake:
|
||||
# {
|
||||
# "session_id": "...",
|
||||
# "L1": [...],
|
||||
# "L5": [...],
|
||||
# "L10": {...},
|
||||
# "L20": {...},
|
||||
# "L30": {...}
|
||||
# }
|
||||
|
||||
logger.info(f"Retrieved Intake context for session {session_id}")
|
||||
return data
|
||||
|
||||
except httpx.HTTPError as e:
|
||||
logger.warning(f"Failed to retrieve Intake context: {e}")
|
||||
return {
|
||||
"session_id": session_id,
|
||||
"L1": [],
|
||||
"L5": [],
|
||||
"L10": None,
|
||||
"L20": None,
|
||||
"L30": None,
|
||||
"error": str(e)
|
||||
}
|
||||
return await summarize_context(session_id, messages)
|
||||
except Exception as e:
|
||||
logger.error(f"Unexpected error retrieving Intake context: {e}")
|
||||
logger.error(f"Internal Intake summarization failed: {e}")
|
||||
return {
|
||||
"session_id": session_id,
|
||||
"L1": [],
|
||||
"L5": [],
|
||||
"L10": None,
|
||||
"L20": None,
|
||||
"L30": None,
|
||||
"L1": "",
|
||||
"L5": "",
|
||||
"L10": "",
|
||||
"L20": "",
|
||||
"L30": "",
|
||||
"error": str(e)
|
||||
}
|
||||
|
||||
|
||||
|
||||
# -----------------------------
|
||||
# NeoMem semantic search
|
||||
# -----------------------------
|
||||
@@ -279,7 +238,19 @@ async def collect_context(session_id: str, user_prompt: str) -> Dict[str, Any]:
|
||||
logger.debug(f"[COLLECT_CONTEXT] Time since last message: {minutes_since_last_msg:.2f} minutes")
|
||||
|
||||
# C. Gather Intake context (multilevel summaries)
|
||||
intake_data = await _get_intake_context(session_id)
|
||||
# Build compact message buffer for Intake:
|
||||
messages_for_intake = []
|
||||
|
||||
# You track messages inside SESSION_STATE — assemble it here:
|
||||
if "message_history" in state:
|
||||
for turn in state["message_history"]:
|
||||
messages_for_intake.append({
|
||||
"user_msg": turn.get("user", ""),
|
||||
"assistant_msg": turn.get("assistant", "")
|
||||
})
|
||||
|
||||
intake_data = await _get_intake_context(session_id, messages_for_intake)
|
||||
|
||||
|
||||
if VERBOSE_DEBUG:
|
||||
import json
|
||||
|
||||
Reference in New Issue
Block a user