Refine knowledge brain workflow
Align the brain prompts, graph view, and startup defaults with the latest phase 1 flow so local runs and navigation stay consistent.
This commit is contained in:
@@ -97,13 +97,49 @@ def _filter_user_messages(messages: list) -> list[BaseMessage]:
|
||||
return [m for m in messages if _msg_type(m) in ("human", "user")]
|
||||
|
||||
|
||||
def _normalize_user_text(text: str) -> str:
|
||||
return (text or "").strip().lower()
|
||||
|
||||
|
||||
def _is_simple_greeting(text: str) -> bool:
|
||||
normalized = _normalize_user_text(text)
|
||||
return normalized in {"你好", "您好", "早", "早上好", "在吗", "嗨", "hi", "hello"}
|
||||
|
||||
|
||||
def _is_identity_question(text: str) -> bool:
|
||||
normalized = _normalize_user_text(text)
|
||||
return normalized in {"你是谁", "你是誰"}
|
||||
|
||||
|
||||
def _is_capability_question(text: str) -> bool:
|
||||
normalized = _normalize_user_text(text)
|
||||
return normalized in {"你能做什么", "你可以做什么", "你会做什么"}
|
||||
|
||||
|
||||
# ===================== 节点定义 (async) =====================
|
||||
|
||||
async def master_node(state: AgentState) -> AgentState:
|
||||
"""主Agent节点: 理解用户意图,决定调用哪个子Agent"""
|
||||
llm = _get_llm_for_state(state)
|
||||
messages: list[BaseMessage] = state["messages"]
|
||||
user_msgs = _filter_user_messages(messages)
|
||||
user_query = user_msgs[-1].content.strip() if user_msgs else ""
|
||||
|
||||
if _is_simple_greeting(user_query):
|
||||
state["final_response"] = "您好。我在。\n\n您把问题给我,我先帮您收束重点,再往下推。"
|
||||
state["should_respond"] = True
|
||||
return state
|
||||
|
||||
if _is_identity_question(user_query):
|
||||
state["final_response"] = "我是 Jarvis。\n\n比起做一个泛泛的助手,我更像您的判断型协作伙伴:帮您看清问题、压缩路径、把事情往前推进。"
|
||||
state["should_respond"] = True
|
||||
return state
|
||||
|
||||
if _is_capability_question(user_query):
|
||||
state["final_response"] = "主要做三件事。\n- 帮您判断:看问题本质、梳理取舍、给出方向\n- 帮您收束:把复杂内容理顺,把重点拎出来\n- 帮您推进:拆任务、定步骤、把下一步变清楚\n\n如果您现在有具体目标,我可以直接进入处理。"
|
||||
state["should_respond"] = True
|
||||
return state
|
||||
|
||||
llm = _get_llm_for_state(state)
|
||||
system_msgs: list[BaseMessage] = [SystemMessage(content=MASTER_SYSTEM_PROMPT)]
|
||||
|
||||
# 注入记忆上下文
|
||||
|
||||
Reference in New Issue
Block a user