feat: add fixed questions and improve authentication
This commit is contained in:
1 parent
8af4fed89d
commit
4c9f75f31e
42 files changed
+4008
-200
No files matched your search
@@ -29,7 +29,8 @@ SSE 协议(与前端 ``streamIntent`` 对齐)
|
||||
- ``done``:已解析 ``[INTENT_READY]`` + JSON 块,``summary`` 有值;
|
||||
- ``error``:上游或网关异常。
|
||||
|
||||
``content`` — 展示用 AI 正文(澄清时优先用 tool 后的 follow-up 文本)。
|
||||
``content`` — 展示用 AI 正文(澄清时只保留 tool 调用前的简短引导;
|
||||
tool 后的尾随文本会被丢弃,选项发出后立即等待用户选择)。
|
||||
|
||||
仅 ``status == "done"`` 时带 ``summary``;澄清时还带
|
||||
``question``、``clarification_type``、``clarification_context``、
|
||||
@@ -625,6 +626,14 @@ async def stream_intent(request: Request, payload: dict = Body(...)) -> Streamin
|
||||
# 2. message 前缀——给模型一个明确的"本轮必须收敛"信号。
|
||||
# 仅文件、无文本时给一句兜底引导,让模型先读文件再澄清意图。
|
||||
effective_message = message or "我上传了文件,请先阅读文件内容,再据此理解并澄清我的任务意图。"
|
||||
if past_rounds < max_rounds:
|
||||
effective_message = (
|
||||
"[澄清输出硬约束] 如果本轮调用 ask_clarification,"
|
||||
"工具调用完成后必须立即停止输出并等待用户选择;"
|
||||
"禁止补充说明、复述选项、催促选择、追加问题或输出 "
|
||||
"[INTENT_READY]。需要确认的全部内容只能写入工具参数。\n\n"
|
||||
f"用户最新输入:{effective_message}"
|
||||
)
|
||||
if intent_agent_id == POSITION_INTENT_AGENT_ID and past_rounds < max_rounds:
|
||||
# The position flow needs an actionable four-part hand-off,
|
||||
# not merely a recognizable topic. One turn may ask several
|
||||
@@ -637,6 +646,8 @@ async def stream_intent(request: Request, payload: dict = Body(...)) -> Streamin
|
||||
"ask_clarification;每个工具调用只能问一个决策点,不能把多项"
|
||||
"问题合并成一张卡片。用户会一次性回答这些卡片。"
|
||||
"如果四项意图已经足够明确,则直接输出最终结果。"
|
||||
"一旦调用完本轮所有 ask_clarification,必须立即停止输出,"
|
||||
"不要再补充说明、复述选项、催促选择或继续提问,等待用户选择。"
|
||||
"不要以风险提示和战略意义为空的 [INTENT_READY] 结束。"
|
||||
"本轮是第 %d/%d 轮用户协助;第 %d 轮若仍有缺口,必须把所有"
|
||||
"剩余关键缺口分别发成卡片,收到回答后立即收敛。\n\n"
|
||||
@@ -756,9 +767,6 @@ async def stream_intent(request: Request, payload: dict = Body(...)) -> Streamin
|
||||
content = _flatten_content(dispatch_msg.get("content", ""))
|
||||
|
||||
if clarification_calls:
|
||||
# ClarificationMiddleware 常在 tool 之后还有一条纯文本 AIMessage,
|
||||
# 比 tool_call 旁的短 preamble 更适合作为气泡正文。
|
||||
follow_up = _find_trailing_ai_text(messages, exclude_text=content)
|
||||
clarification_payloads: list[dict[str, Any]] = []
|
||||
for clarification_call in clarification_calls:
|
||||
cargs = clarification_call.get("args") or {}
|
||||
@@ -790,6 +798,9 @@ async def stream_intent(request: Request, payload: dict = Body(...)) -> Streamin
|
||||
)
|
||||
|
||||
if not clarification_payloads:
|
||||
# 这里只在所有卡片都因重复而被过滤时才允许使用 tool 后文本;
|
||||
# 此时前端没有选项需要等待,不属于澄清暂停态。
|
||||
follow_up = _find_trailing_ai_text(messages, exclude_text=content)
|
||||
fallback_msg = (
|
||||
follow_up
|
||||
or content
|
||||
@@ -805,7 +816,11 @@ async def stream_intent(request: Request, payload: dict = Body(...)) -> Streamin
|
||||
return
|
||||
|
||||
first = clarification_payloads[0]
|
||||
display_content = follow_up or content or str(first["question"])
|
||||
# ask_clarification 是严格的回合终点。部分模型会在工具调用后
|
||||
# 再生成“请从以上选项中选择……”等尾随 AIMessage;不能把它
|
||||
# 返回给前端,否则用户看到卡片后还会继续冒出一段话。
|
||||
# 仅保留工具调用自身携带的前置短句;没有则直接由卡片展示问题。
|
||||
display_content = content
|
||||
final_frame: dict[str, Any] = {
|
||||
"status": "clarification",
|
||||
"content": display_content,
|
||||
|
||||
Reference in new issue
Block a user