From 094d66d42be6db6482336f78f25eeba8b54dc818 Mon Sep 17 00:00:00 2001 From: ymq Date: Thu, 13 Aug 2026 17:23:19 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=88=97=E8=A1=A8/=E8=AF=8A=E6=96=AD?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E5=AE=8C=E6=95=B4ID=EF=BC=8C=E8=AF=A6?= =?UTF-8?q?=E6=83=85=E5=B7=A5=E5=85=B7=E6=94=AF=E6=8C=81=E5=89=8D=E7=BC=80?= =?UTF-8?q?=E5=8C=B9=E9=85=8D=E5=85=9C=E5=BA=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - _t_list_tasks 返回完整ID(不再截断8位) - _t_list_questions 返回完整ID(去掉Q前缀+截断) - _t_list_deliverables 返回完整ID - _t_diagnose_project 列出失败/待执行任务完整ID - _t_task_detail/_t_answer_question/_t_view_deliverable 支持8位前缀匹配兜底 --- pipeline_service/agent_loop_v2.py | 60 +++++++++++++++++++++++++------ 1 file changed, 49 insertions(+), 11 deletions(-) diff --git a/pipeline_service/agent_loop_v2.py b/pipeline_service/agent_loop_v2.py index 22fc725..87205fb 100644 --- a/pipeline_service/agent_loop_v2.py +++ b/pipeline_service/agent_loop_v2.py @@ -686,7 +686,7 @@ class AgentExecutor: icon = icons.get(st, "❓") title = (getattr(r, 'title', '') or '')[:60] role = getattr(r, 'role', '') - tid = getattr(r, 'id', '')[:8] + tid = getattr(r, 'id', '') lines.append(f"| {icon} {st} | {title} | {role} | {tid} |") return "\n".join(lines) @@ -697,6 +697,11 @@ class AgentExecutor: recs = await sor.sqlExe( "SELECT * FROM pipeline_tasks WHERE id=${tid}$", {"tid": tid}) + if not recs and len(tid) >= 6: + # 前缀匹配兜底(兼容 8 位截断 ID) + recs = await sor.sqlExe( + "SELECT * FROM pipeline_tasks WHERE id LIKE ${prefix}$ LIMIT 1", + {"prefix": tid + "%"}) if not recs: return f"任务不存在: {tid}" @@ -767,14 +772,32 @@ class AgentExecutor: fc = getattr(failed[0], "c", 0) if failed else 0 vc = getattr(review[0], "c", 0) if review else 0 - return ( - f"项目诊断:\n" - f"- 待执行: {sc}\n" - f"- 运行中: {rc}\n" - f"- 待审核: {vc}\n" - f"- 失败: {fc}\n" - f"- 待回答问题: {qc}\n" - ) + lines = [ + "项目诊断:", + f"- 待执行: {sc}", + f"- 运行中: {rc}", + f"- 待审核: {vc}", + f"- 失败: {fc}", + f"- 待回答问题: {qc}", + ] + + # 列出失败/待执行任务完整 ID,方便 agent 直接 task_detail + if fc: + failed_rows = await sor.sqlExe( + "SELECT id, title, role FROM pipeline_tasks WHERE tenant_id=${pid}$ AND state='failed' ORDER BY created_at DESC LIMIT 10", + {"pid": pid}) + lines.append("失败任务:") + for fr in (failed_rows or []): + lines.append(f" - [{getattr(fr, 'role', '?')}] {getattr(fr, 'title', '')} (id={getattr(fr, 'id', '')})") + if sc: + submitted_rows = await sor.sqlExe( + "SELECT id, title, role FROM pipeline_tasks WHERE tenant_id=${pid}$ AND state='submitted' ORDER BY created_at ASC LIMIT 10", + {"pid": pid}) + lines.append("待执行任务:") + for sr in (submitted_rows or []): + lines.append(f" - [{getattr(sr, 'role', '?')}] {getattr(sr, 'title', '')} (id={getattr(sr, 'id', '')})") + + return "\n".join(lines) async def _t_list_deliverables(self, sor, p, pid): if not pid: @@ -793,7 +816,7 @@ class AgentExecutor: for r in recs: lines.append( f"- [{getattr(r, 'review_status', '?')}] {getattr(r, 'title', '')} " - f"({getattr(r, 'deliverable_type', '')})" + f"({getattr(r, 'deliverable_type', '')}) id={getattr(r, 'id', '')}" ) return "\n".join(lines) @@ -804,6 +827,10 @@ class AgentExecutor: recs = await sor.sqlExe( "SELECT * FROM pipeline_deliverables WHERE id=${did}$", {"did": did}) + if not recs and len(did) >= 6: + recs = await sor.sqlExe( + "SELECT * FROM pipeline_deliverables WHERE id LIKE ${prefix}$ LIMIT 1", + {"prefix": did + "%"}) if not recs: return f"交付件不存在: {did}" @@ -833,7 +860,7 @@ class AgentExecutor: lines = [] for r in recs: - lines.append(f"- Q{getattr(r, 'id', '')[:8]}: {getattr(r, 'question', '')[:200]}") + lines.append(f"- [{getattr(r, 'id', '')}] {getattr(r, 'question', '')[:200]}") return "\n".join(lines) async def _t_answer_question(self, sor, p, pid): @@ -842,6 +869,17 @@ class AgentExecutor: if not qid or not answer: return "需要问题ID和回答内容" + # 先精确匹配,再前缀匹配兜底(兼容截断 ID) + recs = await sor.sqlExe( + "SELECT id FROM pipeline_agent_questions WHERE id=${qid}$", {"qid": qid}) + if not recs and len(qid) >= 6: + recs = await sor.sqlExe( + "SELECT id FROM pipeline_agent_questions WHERE id LIKE ${prefix}$ LIMIT 1", + {"prefix": qid + "%"}) + if not recs: + return f"问题不存在: {qid}" + qid = getattr(recs[0], "id", qid) + await sor.sqlExe( "UPDATE pipeline_agent_questions SET answered=1, answer=${a}$ WHERE id=${qid}$", {"a": answer, "qid": qid})