sync: 鍚屾灞€鍩熺綉鏈€鏂颁唬鐮?(source master @ b69568e4)
This commit is contained in:
1 parent
4f7f07504a
commit
8bc8b0e082
1651 files changed
+278599
-11416
No files matched your search
@@ -74,6 +74,7 @@ from app.gateway.roundtable_diag import record_foreground_diag
|
||||
from app.gateway.routers._roundtable_seed import (
|
||||
EIGHTBF_INTENT_AGENT_ID,
|
||||
POSITION_INTENT_AGENT_ID,
|
||||
REPORT_COLLABORATION_INTENT_AGENT_ID,
|
||||
ensure_roundtable_functional_agents,
|
||||
)
|
||||
from app.gateway.routers.multi_agent import (
|
||||
@@ -131,15 +132,56 @@ INTENT_AGENT_ID = "roundtable-intent"
|
||||
# 8BF 独立会商页第一步专用的内置意图智能体:提示词与 roundtable-intent 同源,
|
||||
# 但目录独立、可单独调优,不改变通用会商与岗位会商的契约。
|
||||
_SUPPORTED_INTENT_AGENT_IDS = frozenset(
|
||||
{INTENT_AGENT_ID, POSITION_INTENT_AGENT_ID, EIGHTBF_INTENT_AGENT_ID}
|
||||
{
|
||||
INTENT_AGENT_ID,
|
||||
POSITION_INTENT_AGENT_ID,
|
||||
EIGHTBF_INTENT_AGENT_ID,
|
||||
REPORT_COLLABORATION_INTENT_AGENT_ID,
|
||||
}
|
||||
)
|
||||
|
||||
# SOUL 规定的交接信号:``[INTENT_READY]`` + markdown json 代码块。
|
||||
# group(1) 解析为 IntentSummary;解析失败则继续走澄清/asking 分支。
|
||||
_INTENT_READY_PATTERN = re.compile(
|
||||
r"\[INTENT_READY\]\s*```json\s*(\{.*?\})\s*```",
|
||||
re.DOTALL,
|
||||
)
|
||||
def _extract_intent_ready(text: str) -> tuple[dict[str, Any], int] | None:
|
||||
"""Parse a READY payload with nested objects, not a non-greedy regex.
|
||||
|
||||
Report collaboration carries a nested ``report_requirement`` object. The
|
||||
legacy regex stopped at its first ``}``, so a perfectly valid streamed
|
||||
agent hand-off was incorrectly downgraded to ``asking``.
|
||||
"""
|
||||
|
||||
marker = text.find("[INTENT_READY]")
|
||||
start = text.find("{", marker + len("[INTENT_READY]")) if marker >= 0 else -1
|
||||
if start < 0:
|
||||
return None
|
||||
depth = 0
|
||||
in_string = False
|
||||
escaped = False
|
||||
for index in range(start, len(text)):
|
||||
char = text[index]
|
||||
if escaped:
|
||||
escaped = False
|
||||
continue
|
||||
if char == "\\" and in_string:
|
||||
escaped = True
|
||||
continue
|
||||
if char == '"':
|
||||
in_string = not in_string
|
||||
continue
|
||||
if in_string:
|
||||
continue
|
||||
if char == "{":
|
||||
depth += 1
|
||||
elif char == "}":
|
||||
depth -= 1
|
||||
if depth == 0:
|
||||
try:
|
||||
payload = json.loads(text[start : index + 1])
|
||||
except json.JSONDecodeError:
|
||||
return None
|
||||
if not isinstance(payload, dict):
|
||||
return None
|
||||
fence = text.find("```", index + 1)
|
||||
return payload, fence + 3 if fence >= 0 else index + 1
|
||||
return None
|
||||
|
||||
|
||||
def _requested_intent_agent_id(payload: dict[str, Any]) -> str:
|
||||
@@ -738,20 +780,16 @@ async def stream_intent(request: Request, payload: dict = Body(...)) -> Streamin
|
||||
if (msg.get("type") or "").lower() not in ("ai", "aimessage", "aimessagechunk"):
|
||||
continue
|
||||
msg_text = _flatten_content(msg.get("content", ""))
|
||||
m = _INTENT_READY_PATTERN.search(msg_text)
|
||||
if m:
|
||||
try:
|
||||
summary = json.loads(m.group(1))
|
||||
except json.JSONDecodeError as exc:
|
||||
logger.warning("intent summary JSON parse failed: %s", exc)
|
||||
summary = None
|
||||
extracted_ready = _extract_intent_ready(msg_text)
|
||||
if extracted_ready:
|
||||
summary, ready_end = extracted_ready
|
||||
# SOUL §0 硬规则 3 要求 ```json``` 反引号闭合后不得再输出任何字符,
|
||||
# 但模型仍偶尔会在后面接 "那么我帮你列一下大纲……" 之类的尾巴。
|
||||
# 终态帧只回到 marker 块结尾 + 一个换行,把废话从 content 里裁掉——
|
||||
# 草稿持久化 / 跨设备重放 / 前端 splitIntentReadyBlock 的 after
|
||||
# 段都因此干净。流式期间用户仍会逐 token 看到那段废话,前端
|
||||
# Step1Panel 已经把 `parts.after` 隐藏掉,体验闭环。
|
||||
ready_text = msg_text[: m.end()].rstrip() + "\n"
|
||||
ready_text = msg_text[:ready_end].rstrip() + "\n"
|
||||
break
|
||||
if (
|
||||
summary
|
||||
|
||||
Reference in new issue
Block a user