@@ -257,7 +257,7 @@ async def _maybe_handle_conversational_intent(
257257 ans = (intent .direct_response or "" ).strip ()
258258 if not ans :
259259 ans = (
260- "收到~有需要执行的安全任务随时说。 "
260+ "收到~有需要执行的安全任务随时说! "
261261 if intent .intent == "small_talk"
262262 else "我会尽量帮你查清楚。"
263263 )
@@ -375,20 +375,38 @@ async def handle_message(
375375 import os
376376
377377 at = agent_type or self .get_current_agent_type ()
378+ sid = self .current_session .id if self .current_session else "default"
378379
379380 # ---- 强制 Q&A(mode=ask)----
380381 if force_qa :
381382 await self .event_bus .emit_simple_async (
382383 EventType .TASK_PHASE , phase = "done" , detail = ""
383384 )
384- response = await self .qa_agent .answer (user_input )
385+ if self .context_assembler and self .current_session :
386+ ctx = await self .context_assembler .build (
387+ query = user_input ,
388+ session = self .current_session ,
389+ session_id = sid ,
390+ agent_type = "qa" ,
391+ model_name = model_name ,
392+ )
393+ await self ._emit_context_usage (ctx .debug )
394+ hist = [
395+ {"role" : m .role .value , "content" : m .content }
396+ for m in self .current_session .messages
397+ ]
398+ response = await self .qa_agent .answer_with_context (
399+ user_input , hist , ctx .context_block
400+ )
401+ else :
402+ response = await self .qa_agent .answer (user_input )
385403 if self .current_session :
386404 self .current_session .add_message (MessageRole .ASSISTANT , response )
405+ await self ._persist_turn (user_input , response , "qa" )
387406 return response
388407
389408 # ---- IntentRouter + 可选 Explore + 预算上下文 ----
390409 _context_block = ""
391- sid = self .current_session .id if self .current_session else "default"
392410 focus_kw : List [str ] = []
393411 unresolved_snap : List [str ] = []
394412 if self .context_assembler :
@@ -532,6 +550,7 @@ def event_bridge(event_type: str, data: dict):
532550 skip_planning = True ,
533551 skip_report = True ,
534552 todos = [],
553+ context_block = _context_block ,
535554 get_root_password = getattr (self , "get_root_password" , None ),
536555 )
537556 else :
@@ -541,6 +560,7 @@ def event_bridge(event_type: str, data: dict):
541560 skip_planning = True ,
542561 skip_report = True ,
543562 todos = [],
563+ context_block = _context_block ,
544564 get_root_password = getattr (self , "get_root_password" , None ),
545565 )
546566
@@ -678,6 +698,7 @@ async def _do_execute():
678698 planner = self .planner ,
679699 event_bus = self .event_bus ,
680700 get_root_password = getattr (self , "get_root_password" , None ),
701+ context_block = _context_block ,
681702 )
682703 return await executor .run (user_input , on_event = event_bridge )
683704 else :
@@ -687,6 +708,7 @@ async def _do_execute():
687708 skip_planning = True ,
688709 skip_report = True ,
689710 todos = todos_snapshot ,
711+ context_block = _context_block ,
690712 get_root_password = getattr (self , "get_root_password" , None ),
691713 )
692714 return resp
@@ -749,6 +771,7 @@ async def _do_execute():
749771 planner = self .planner ,
750772 event_bus = self .event_bus ,
751773 get_root_password = getattr (self , "get_root_password" , None ),
774+ context_block = _context_block ,
752775 )
753776 if lock is not None :
754777 async with lock :
0 commit comments