From 2a91105f8226bee24ae36c25fc0dc415626ac8bd Mon Sep 17 00:00:00 2001 From: TatsuKo Tsukimi Date: Thu, 11 Jun 2026 21:24:40 +0800 Subject: [PATCH] fix: raise soul.md cap in build_agent_context from 2000 to 30000 chars MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit _read_file_safe silently truncates at max_chars (appending "...(truncated)" without logging), and build_agent_context read soul.md with a 2000-char cap. Any agent whose soul.md exceeds 2000 chars therefore ran with every tail section — rules, boundaries, operational facts — silently missing from its system prompt, while the file, DB, and UI all showed the full soul. On one deployment, 68 of 141 agents exceeded the cap (largest 12k chars: only the first 17% ever reached the model), and agents confidently denied facts their souls plainly stated. Soul is author-curated and bounded, so a generous 30000-char cap is safe. Memory and relationships keep their small caps because they grow unbounded at runtime. Co-Authored-By: Claude Opus 4.8 --- backend/app/services/agent_context.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/backend/app/services/agent_context.py b/backend/app/services/agent_context.py index b0d72e7ab..f9d78d8ee 100644 --- a/backend/app/services/agent_context.py +++ b/backend/app/services/agent_context.py @@ -250,7 +250,13 @@ async def build_agent_context(agent_id: uuid.UUID, agent_name: str, role_descrip - Database → relationship network (human + agent) """ # --- Soul --- - soul = await _read_file_safe(normalize_storage_key(f"{agent_id}/soul.md"), 2000) + # Soul is the agent's full author-curated identity; detailed souls (e.g. + # bundle agents) run 4-12k chars. A tight cap silently drops every tail + # section — rules, boundaries, facts — and the agent then confidently + # denies things its soul plainly states, with no log of the truncation. + # Memory and relationships below keep small caps because they grow + # unbounded at runtime; the soul does not (only seeded/explicitly edited). + soul = await _read_file_safe(normalize_storage_key(f"{agent_id}/soul.md"), 30000) # Strip markdown heading if present if soul.startswith("# "): soul = "\n".join(soul.split("\n")[1:]).strip()