context added, wired in. first attempt
This commit is contained in:
@@ -7,7 +7,9 @@ from reasoning.reasoning import reason_check
|
||||
from reasoning.reflection import reflect_notes
|
||||
from reasoning.refine import refine_answer
|
||||
from persona.speak import speak
|
||||
from persona.identity import load_identity
|
||||
from ingest.intake_client import IntakeClient
|
||||
from context import collect_context, update_last_assistant_message
|
||||
|
||||
# -----------------------------
|
||||
# Router (NOT FastAPI app)
|
||||
@@ -33,15 +35,25 @@ class ReasonRequest(BaseModel):
|
||||
@cortex_router.post("/reason")
|
||||
async def run_reason(req: ReasonRequest):
|
||||
|
||||
# 1. Pull context from Intake
|
||||
try:
|
||||
intake_summary = await intake_client.get_context(req.session_id)
|
||||
except Exception:
|
||||
intake_summary = "(no context available)"
|
||||
# 0. Collect unified context from all sources
|
||||
context_state = await collect_context(req.session_id, req.user_prompt)
|
||||
|
||||
# 0.5. Load identity block
|
||||
identity_block = load_identity(req.session_id)
|
||||
|
||||
# 1. Extract Intake summary for reflection
|
||||
# Use L20 (Session Overview) as primary summary for reflection
|
||||
intake_summary = "(no context available)"
|
||||
if context_state.get("intake"):
|
||||
l20_summary = context_state["intake"].get("L20")
|
||||
if l20_summary and isinstance(l20_summary, dict):
|
||||
intake_summary = l20_summary.get("summary", "(no context available)")
|
||||
elif isinstance(l20_summary, str):
|
||||
intake_summary = l20_summary
|
||||
|
||||
# 2. Reflection
|
||||
try:
|
||||
reflection = await reflect_notes(intake_summary, identity_block=None)
|
||||
reflection = await reflect_notes(intake_summary, identity_block=identity_block)
|
||||
reflection_notes = reflection.get("notes", [])
|
||||
except Exception:
|
||||
reflection_notes = []
|
||||
@@ -49,31 +61,40 @@ async def run_reason(req: ReasonRequest):
|
||||
# 3. First-pass reasoning draft
|
||||
draft = await reason_check(
|
||||
req.user_prompt,
|
||||
identity_block=None,
|
||||
rag_block=None,
|
||||
reflection_notes=reflection_notes
|
||||
identity_block=identity_block,
|
||||
rag_block=context_state.get("rag", []),
|
||||
reflection_notes=reflection_notes,
|
||||
context=context_state
|
||||
)
|
||||
|
||||
# 4. Refinement
|
||||
result = await refine_answer(
|
||||
draft_output=draft,
|
||||
reflection_notes=reflection_notes,
|
||||
identity_block=None,
|
||||
rag_block=None,
|
||||
identity_block=identity_block,
|
||||
rag_block=context_state.get("rag", []),
|
||||
)
|
||||
final_neutral = result["final_output"]
|
||||
|
||||
|
||||
# 5. Persona layer
|
||||
persona_answer = await speak(final_neutral)
|
||||
|
||||
# 6. Return full bundle
|
||||
# 6. Update session state with assistant's response
|
||||
update_last_assistant_message(req.session_id, persona_answer)
|
||||
|
||||
# 7. Return full bundle
|
||||
return {
|
||||
"draft": draft,
|
||||
"neutral": final_neutral,
|
||||
"persona": persona_answer,
|
||||
"reflection": reflection_notes,
|
||||
"session_id": req.session_id,
|
||||
"context_summary": {
|
||||
"rag_results": len(context_state.get("rag", [])),
|
||||
"minutes_since_last": context_state.get("minutes_since_last_msg"),
|
||||
"message_count": context_state.get("message_count"),
|
||||
"mode": context_state.get("mode"),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user