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 )