cortex 0.2.... i think?

This commit is contained in:
serversdwn
2025-11-29 05:14:32 -05:00
parent ebe3e27095
commit cc014d0a73
6 changed files with 338 additions and 4 deletions

View File

@@ -2,8 +2,37 @@
import json
import os
import re
import logging
from llm.llm_router import call_llm
# Logger
VERBOSE_DEBUG = os.getenv("VERBOSE_DEBUG", "false").lower() == "true"
logger = logging.getLogger(__name__)
if VERBOSE_DEBUG:
logger.setLevel(logging.DEBUG)
# Console handler
console_handler = logging.StreamHandler()
console_handler.setFormatter(logging.Formatter(
'%(asctime)s [REFLECTION] %(levelname)s: %(message)s',
datefmt='%H:%M:%S'
))
logger.addHandler(console_handler)
# File handler
try:
os.makedirs('/app/logs', exist_ok=True)
file_handler = logging.FileHandler('/app/logs/cortex_verbose_debug.log', mode='a')
file_handler.setFormatter(logging.Formatter(
'%(asctime)s [REFLECTION] %(levelname)s: %(message)s',
datefmt='%Y-%m-%d %H:%M:%S'
))
logger.addHandler(file_handler)
logger.debug("VERBOSE_DEBUG mode enabled for reflection.py - logging to file")
except Exception as e:
logger.debug(f"VERBOSE_DEBUG mode enabled for reflection.py - file logging failed: {e}")
async def reflect_notes(intake_summary: str, identity_block: dict | None) -> dict:
"""
@@ -46,8 +75,23 @@ async def reflect_notes(intake_summary: str, identity_block: dict | None) -> dic
# -----------------------------
# Call the selected LLM backend
# -----------------------------
if VERBOSE_DEBUG:
logger.debug(f"\n{'='*80}")
logger.debug("[REFLECTION] Full prompt being sent to LLM:")
logger.debug(f"{'='*80}")
logger.debug(prompt)
logger.debug(f"{'='*80}")
logger.debug(f"Backend: {backend}")
logger.debug(f"{'='*80}\n")
raw = await call_llm(prompt, backend=backend)
print("[Reflection-Raw]:", raw)
if VERBOSE_DEBUG:
logger.debug(f"\n{'='*80}")
logger.debug("[REFLECTION] LLM Response received:")
logger.debug(f"{'='*80}")
logger.debug(raw)
logger.debug(f"{'='*80}\n")
# -----------------------------
# Try direct JSON
@@ -55,9 +99,12 @@ async def reflect_notes(intake_summary: str, identity_block: dict | None) -> dic
try:
parsed = json.loads(raw.strip())
if isinstance(parsed, dict) and "notes" in parsed:
if VERBOSE_DEBUG:
logger.debug(f"[REFLECTION] Parsed {len(parsed['notes'])} notes from JSON")
return parsed
except:
pass
if VERBOSE_DEBUG:
logger.debug("[REFLECTION] Direct JSON parsing failed, trying extraction...")
# -----------------------------
# Try JSON extraction