From 5c1ff0ef58e9f6f67dbee61f8c6be24dc1f42026 Mon Sep 17 00:00:00 2001 From: gongzhiyong Date: Fri, 19 Jun 2026 08:41:44 +0800 Subject: [PATCH] =?UTF-8?q?feat(agent):=20=E4=BB=BB=E5=8A=A1=E6=89=A7?= =?UTF-8?q?=E8=A1=8C=E5=8A=A0=E7=BB=93=E6=9E=84=E5=8C=96=E6=97=A5=E5=BF=97?= =?UTF-8?q?(LLM=E6=8E=A8=E7=90=86/tool=E8=B0=83=E7=94=A8query=E4=B8=8E?= =?UTF-8?q?=E8=BF=94=E5=9B=9E/=E4=BA=A7=E5=87=BA)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.8 (1M context) (cherry picked from commit 099f270cc2a092a4eae7e5d06d99c4d7e076465e) --- agent/task_executor.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/agent/task_executor.py b/agent/task_executor.py index efd5bb9..e0b3b1b 100644 --- a/agent/task_executor.py +++ b/agent/task_executor.py @@ -342,6 +342,8 @@ Return ONLY the JSON array, no other text.""" content = "" try: description = subtask["description"] + logger.info("════════ [任务开始] task=%s role=%s\n 描述: %s", + task_id, context.get("specialist_role", "general"), description) workspace_files = self._summarize_workspace() workspace_context = self._collect_workspace_context() user_prompt = context.get("user_prompt") or context.get("run_goal") or context.get("root_task_description") or "" @@ -437,6 +439,10 @@ Return your response as JSON with this structure: Return ONLY the JSON, no other text.""" content = await self._complete(prompt, max_tokens=4000) result = self._parse_json_response(content) + logger.info("──────── [任务产出] task=%s status=%s 文件=%s\n 说明: %s", + task_id, result.get("status"), + [f.get("path") for f in (result.get("files") or [])], + (result.get("changes") or result.get("summary") or "")[:600]) if result.get("status") == "completed": apply_result = await self._apply_file_changes(result.get("files", [])) result["files_modified"] = apply_result["files_modified"] @@ -539,7 +545,7 @@ Return ONLY the JSON, no other text.""" tools = await self._load_jina_tools() messages = [{"role": "user", "content": prompt}] - for _ in range(8): # max 8 tool-call rounds + for round_i in range(8): # max 8 tool-call rounds kwargs: dict = dict( model=self.model, messages=messages, @@ -553,6 +559,10 @@ Return ONLY the JSON, no other text.""" self._record_openai_usage(response) msg = response.choices[0].message + # 记录这一轮 LLM 的"思考/回复"(可观测 agent 怎么想的) + if msg.content: + logger.info("[LLM·第%d轮] 思考/回复:\n%s", round_i + 1, msg.content.strip()[:1200]) + if not msg.tool_calls: return msg.content or "" @@ -560,8 +570,13 @@ Return ONLY the JSON, no other text.""" messages.append(msg.model_dump(exclude_unset=True)) for tc in msg.tool_calls: args = json.loads(tc.function.arguments or "{}") + # 记录调用了哪个 tool、query 是什么 + logger.info("[TOOL·调用] %s 参数=%s", tc.function.name, + json.dumps(args, ensure_ascii=False)[:400]) result = await self._call_jina_tool(tc.function.name, args) - logger.info("Jina tool %s → %d chars", tc.function.name, len(result)) + # 记录 tool 返回了什么(搜索结果内容,截断) + logger.info("[TOOL·返回] %s (%d字):\n%s", tc.function.name, len(result), + (result or "").strip()[:1000]) messages.append({ "role": "tool", "tool_call_id": tc.id,