From 0bf7a87a0e85b2d232769b2da5110a5494234465 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E6=BD=AE?= Date: Mon, 18 May 2026 11:37:23 +0800 Subject: [PATCH] =?UTF-8?q?=20LLM=20=E5=8F=AA=E9=9C=80=E5=A4=84=E7=90=86?= =?UTF-8?q?=E6=9E=81=E7=9F=AD=E7=9A=84=20"Questions=20sent=20to=20user."?= =?UTF-8?q?=20=E8=80=8C=E4=B8=8D=E6=98=AF=E5=AE=8C=E6=95=B4=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20JSON=EF=BC=8C=E5=87=8F=E5=B0=91=E4=BA=86?= =?UTF-8?q?=20token=20=E6=B6=88=E8=80=97=E5=92=8C=E5=BB=B6=E8=BF=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routes/chat.py | 9 ++++--- skills/common/mcp-ui/ui_render_server.py | 30 +++++++----------------- 2 files changed, 13 insertions(+), 26 deletions(-) diff --git a/routes/chat.py b/routes/chat.py index 8845b4a..5511cfe 100644 --- a/routes/chat.py +++ b/routes/chat.py @@ -144,12 +144,11 @@ async def enhanced_generate_stream_response( is_ui_resource = ( msg.text and msg.text.lstrip().startswith('{"') - and ( - ('"ui://' in msg.text and ('"text/html' in msg.text or '"text/uri-list' in msg.text)) - or '"__ask_user__"' in msg.text - ) + and '"ui://' in msg.text + and ('"text/html' in msg.text or '"text/uri-list' in msg.text) ) - if config.tool_response or is_ui_resource: + is_ask_user = msg.name == 'ask_user' + if config.tool_response or is_ui_resource or is_ask_user: new_content = f"[{message_tag}] {msg.name}\n{msg.text}\n" # Collect full content diff --git a/skills/common/mcp-ui/ui_render_server.py b/skills/common/mcp-ui/ui_render_server.py index ea6bf0c..3f3536a 100644 --- a/skills/common/mcp-ui/ui_render_server.py +++ b/skills/common/mcp-ui/ui_render_server.py @@ -21,32 +21,20 @@ from mcp_common import ( ) -ASK_USER_MARKER = "__ask_user__" +ASK_USER_RESPONSE = "Questions sent to user." -def ask_user(questions: list) -> Dict[str, Any]: - """Create an ask_user response. +def ask_user() -> Dict[str, Any]: + """Return a minimal fixed response for ask_user tool. - Args: - questions: List of dicts, each with "question", "options", and "multi_select". - - Returns a JSON structure with a marker so the backend can detect it - and emit it as a special delta.ask_user event at the end of the stream. + The actual questions/options are already in the TOOL_CALL arguments, + so the frontend parses them directly from there. This response only + serves to acknowledge the tool call and minimize token usage in the + subsequent LLM inference round. """ - normalized = [] - for q in questions: - normalized.append({ - "question": q.get("question", ""), - "options": q.get("options", []), - "multi_select": q.get("multi_select", False), - }) - payload = { - "__type__": ASK_USER_MARKER, - "questions": normalized, - } return { "content": [ - {"type": "text", "text": json.dumps(payload, ensure_ascii=False)} + {"type": "text", "text": ASK_USER_RESPONSE} ] } @@ -168,7 +156,7 @@ async def handle_request(request: Dict[str, Any]) -> Dict[str, Any]: request_id, -32602, "Missing required parameter: questions" ) - result = ask_user(questions) + result = ask_user() return {"jsonrpc": "2.0", "id": request_id, "result": result} else: