From acda8bb7e7282d3865cc5d2f9e5214bb66cf9ad2 Mon Sep 17 00:00:00 2001 From: ymq Date: Thu, 13 Aug 2026 17:08:42 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=5Festimate=5Ftokens/=5Fsummarize=20?= =?UTF-8?q?=E5=A4=84=E7=90=86=20native=20=E7=9A=84=20content=3DNone?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pipeline_service/agent_loop_v2.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pipeline_service/agent_loop_v2.py b/pipeline_service/agent_loop_v2.py index 552e13c..22fc725 100644 --- a/pipeline_service/agent_loop_v2.py +++ b/pipeline_service/agent_loop_v2.py @@ -966,7 +966,7 @@ class AgentExecutor: """简单 token 估算(中文 ~1.5 字符/token,英文 ~4 字符/token)""" total = 0 for m in self._msgs: - content = m.get("content", "") + content = m.get("content") or "" # 简单估算:平均每 2 字符 1 token total += len(content) // 2 + 1 return total @@ -974,10 +974,10 @@ class AgentExecutor: async def _summarize(self, messages: list) -> str: """压缩消息为摘要""" if len(messages) <= 2: - return "\n".join(m.get("content", "")[:200] for m in messages) + return "\n".join((m.get("content") or "")[:200] for m in messages) text = "\n".join( - f"[{m['role']}]: {m.get('content', '')[:500]}" + f"[{m['role']}]: {(m.get('content') or '')[:500]}" for m in messages )