#2198·swarms

[错误][内存] persistent_memory 在每次启动时都会注入整个 MEMORY.md,因此每个会话的启动上下文都会增长约 5k 个字符,永远如此

作者: Steve-Dusty创建于 2026年9月8日更新于 2026年9月8日

import os from swarms.structs.conversation import Conversation path = os.path.join(os.environ["WORKSPACE_DIR"], "agents", "Probe", "MEMORY.md") def session(n_messages): c = Conversation(name="Probe", system_prompt="You are helpful.", memory_md_path=path) preamble = [m for m in c.conversation_history if m["role"] == "System" and "[Persistent Memory" in str(m.get("content", ""))] size = len(preamble[0]["content"]) if preamble else 0 for i in range(n_messages): c.add("User", f"question {i} " + "x" * 200) c.add("Assistant", f"answer {i} " + "y" * 200) return size print("run preamble_chars memory_md_bytes") for run in range(1, 6): size = session(10) print(f"{run:>3} {size:>14,} {os.path.getsize(path):>15,}")

Output on master @ 31f93639 (v15.0.1):

run  preamble_chars  memory_md_bytes
  1               0            5,354
  2           5,462           10,564
  3          10,632           15,774
  4          15,802           20,984
  5          20,972           26,194

Straight line, ~5,170 characters per session, forever. At 20 exchanges a day an agent is carrying roughly 100k characters — order 25k tokens — of its own back-catalogue into the first request of every run, before the agent has done anything.

内容来源: kyegomez/swarms