From 2216b01dcb29e7256c9bf789cbb0870a93f7d940 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E6=BD=AE?= Date: Sat, 4 Apr 2026 23:35:12 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix:=20=E4=BF=AE=E5=A4=8D=20prom?= =?UTF-8?q?pt=20=E6=A8=A1=E6=9D=BF=E8=8A=B1=E6=8B=AC=E5=8F=B7=E8=BD=AC?= =?UTF-8?q?=E4=B9=89=E5=8F=8A=20tool=5Fcall=5Fchunk=20=E5=AE=89=E5=85=A8?= =?UTF-8?q?=E8=AE=BF=E9=97=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - prompt 中 JSON 示例的 {} 被 str.format() 误解析为模板变量,转义为 {{}} - tool_call_chunk 改用 .get() 安全访问,避免 KeyError Co-Authored-By: Claude Opus 4.6 (1M context) --- prompt/system_prompt.md | 2 +- prompt/system_prompt_deep_agent.md | 2 +- routes/chat.py | 10 ++++++---- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/prompt/system_prompt.md b/prompt/system_prompt.md index d740313..d98dbed 100644 --- a/prompt/system_prompt.md +++ b/prompt/system_prompt.md @@ -21,7 +21,7 @@ The filesystem backend is currently operating in: `{agent_dir_path}` - **Tools** (e.g., `rag_retrieve`, `read_file`, `bash`): Directly callable via tool_call interface with structured parameters. - **Skills** (e.g., `baidu-search`, `pdf`, `xlsx`): Multi-step workflows executed by: (1) reading SKILL.md, (2) extracting the command, (3) running it via the `bash` tool. -❌ WRONG: Generating a tool_call with `{"name": "baidu-search", "arguments": {...}}` +❌ WRONG: Generating a tool_call with `{{"name": "baidu-search", "arguments": {{...}}}}` ✅ CORRECT: Using `read_file` to read SKILL.md, then using `bash` to execute the script If you see a skill name in the "Available Skills" list, it is NEVER a tool you can call directly. diff --git a/prompt/system_prompt_deep_agent.md b/prompt/system_prompt_deep_agent.md index ecca407..01a2575 100644 --- a/prompt/system_prompt_deep_agent.md +++ b/prompt/system_prompt_deep_agent.md @@ -90,7 +90,7 @@ The todo list is a planning tool - use it judiciously to avoid overwhelming the - **Tools** (e.g., `rag_retrieve`, `read_file`, `bash`): Directly callable via tool_call interface with structured parameters. - **Skills** (e.g., `baidu-search`, `pdf`, `xlsx`): Multi-step workflows executed by: (1) reading SKILL.md, (2) extracting the command, (3) running it via the `bash` tool. -❌ WRONG: Generating a tool_call with `{"name": "baidu-search", "arguments": {...}}` +❌ WRONG: Generating a tool_call with `{{"name": "baidu-search", "arguments": {{...}}}}` ✅ CORRECT: Using `read_file` to read SKILL.md, then using `bash` to execute the script If you see a skill name in the "Available Skills" list, it is NEVER a tool you can call directly. diff --git a/routes/chat.py b/routes/chat.py index 0be1aaa..c280054 100644 --- a/routes/chat.py +++ b/routes/chat.py @@ -102,10 +102,12 @@ async def enhanced_generate_stream_response( message_tag = "TOOL_CALL" if config.tool_response: for tool_call_chunk in msg.tool_call_chunks: - if tool_call_chunk["name"]: - new_content = f"[{message_tag}] {tool_call_chunk['name']}\n" - if tool_call_chunk['args']: - new_content += tool_call_chunk['args'] + chunk_name = tool_call_chunk.get("name") if isinstance(tool_call_chunk, dict) else getattr(tool_call_chunk, "name", None) + chunk_args = tool_call_chunk.get("args") if isinstance(tool_call_chunk, dict) else getattr(tool_call_chunk, "args", None) + if chunk_name: + new_content = f"[{message_tag}] {chunk_name}\n" + if chunk_args: + new_content += chunk_args # 处理文本内容 elif msg.content: preamble_completed.set()