Compare commits

..

4 commits

Author SHA1 Message Date
Sakura-RanChen
4ae96c6e02 fix: 配置读取缺失 2026-11-19 09:40:51 +08:00
Sakura-RanChen
9100e7ecd2 无快照时不回落共享连接态 2026-11-18 15:14:21 +08:00
Sakura-RanChen
4c04b9dd37 调整并发模拟,减少明文 2026-11-18 14:54:51 +08:00
Sakura-RanChen
f441703e6c 补充形参 2026-11-18 11:43:38 +08:00
4 changed files with 23 additions and 6 deletions

View file

@ -916,6 +916,8 @@ class ConnectionHandler:
self.chat_history_conf = int(private_config["chat_history_conf"])
if private_config.get("mcp_endpoint", None) is not None:
self.config["mcp_endpoint"] = private_config["mcp_endpoint"]
if private_config.get("mcp_forward_speaker", None) is not None:
self.config["mcp_forward_speaker"] = private_config["mcp_forward_speaker"]
if private_config.get("context_providers", None) is not None:
self.config["context_providers"] = private_config["context_providers"]
@ -1122,7 +1124,19 @@ class ConnectionHandler:
# 仅在该说话人首次出现时把身份注入 system,之后靠对话历史首轮保留,
# 避免每轮在 system 重复出现名字诱导模型反复称呼
speaker_for_system = None
cs = (self.current_speaker or "").strip()
# 展示名只取本轮数据(声纹快照 → query JSON),不读并发下会被覆盖的连接态
cs = ""
if speaker is not None:
cs = (speaker.name or "").strip()
if not cs and depth == 0 and query:
q = query.strip()
if q.startswith("{") and q.endswith("}"):
try:
parsed = json.loads(q)
if isinstance(parsed, dict):
cs = str(parsed.get("speaker") or "").strip()
except (json.JSONDecodeError, TypeError, ValueError):
pass
if cs and cs != UNKNOWN_SPEAKER_NAME and cs not in self.system_introduced_speakers:
self.system_introduced_speakers.add(cs)
speaker_for_system = cs
@ -1370,7 +1384,7 @@ class ConnectionHandler:
# 统一处理工具调用结果
if tool_results:
self._handle_function_result(tool_results, depth=depth, streamed_text=streamed_text)
self._handle_function_result(tool_results, depth=depth, streamed_text=streamed_text, speaker=speaker)
# 存储对话内容
if len(response_message) > 0:
@ -1395,7 +1409,7 @@ class ConnectionHandler:
return True
def _handle_function_result(self, tool_results, depth, streamed_text=""):
def _handle_function_result(self, tool_results, depth, streamed_text="", speaker=None):
need_llm_tools = []
record_tools = []

View file

@ -47,7 +47,7 @@ async def handle_user_intent(conn: "ConnectionHandler", text, speaker=None):
# 会话开始时生成sentence_id
conn.sentence_id = str(uuid.uuid4().hex)
# 处理各种意图
return await process_intent_result(conn, intent_result, text)
return await process_intent_result(conn, intent_result, text, speaker=speaker)
async def check_direct_exit(conn: "ConnectionHandler", text):
@ -81,7 +81,7 @@ async def analyze_intent_with_llm(conn: "ConnectionHandler", text):
async def process_intent_result(
conn: "ConnectionHandler", intent_result, original_text
conn: "ConnectionHandler", intent_result, original_text, speaker=None
):
"""处理意图识别结果"""
try:

View file

@ -362,7 +362,8 @@ async def call_mcp_endpoint_tool(
message = json.dumps(payload)
log_suffix = ""
if meta:
log_suffix = f",_meta: {json.dumps(meta, ensure_ascii=False)}"
# 只记是否附带身份及字段名,不输出 speakerId/speakerName 明文
log_suffix = f",_meta: 附带身份字段 {list(meta.keys())}"
logger.bind(tag=TAG).info(
f"发送MCP接入点工具调用请求: {actual_name},参数: {json.dumps(arguments, ensure_ascii=False)}{log_suffix}"
)

View file

@ -153,6 +153,8 @@ async def test_executor_reads_snapshot_not_conn_state(monkeypatch):
monkeypatch.setattr(executor_mod, "call_mcp_endpoint_tool", fake_call)
conn = _Conn()
# 模拟并发场景:连接态已被下一轮覆盖成另一个人,meta 仍必须取自快照
conn.current_speaker = "旧说话人"
await executor_mod.MCPEndpointExecutor(conn).execute(
conn,
"HassTurnOn",