Skip to content

"System prompt getting large" warning persists despite being under threshold (21K/30K tokens) #2404

@MartinMayday

Description

@MartinMayday

Bug

The "System prompt is getting large. Run /doctor then /recompile" warning persists in the desktop app even after:

  • Running /doctor (multiple times)
  • Running /recompile (multiple times)
  • Restarting the desktop app entirely

Evidence

From source code investigation of the CLI binary (/opt/homebrew/bin/letta):

  1. Threshold: STARTUP_SYSTEM_PROMPT_WARNING_THRESHOLD_TOKENS = 30000 (line ~217325)
  2. Token estimation: Uses Buffer.byteLength(text, "utf8") / 4 where SYSTEM_PROMPT_BYTES_PER_TOKEN = 4
  3. For memfs agents: Calls estimateSystemPromptTokensFromMemoryDir() which only counts system/ files
  4. Actual token count: letta memory tokens reports 14,195 tokens (was 21,100 before optimization — both well under 30K)
  5. Warning state: Stored in systemPromptDoctorStateByAgent = new Map() — set on startup via buildStartupSystemPromptWarning(agentState) and refreshed on recompile via refresh_doctor_state command

Environment

  • Letta Code CLI: v0.25.8 (installed via homebrew)
  • Desktop app: latest (auto-updates separately from CLI)
  • macOS Sequoia 15.x, Apple Silicon
  • Agent with memfs enabled

Hypothesis

Two possible causes:

  1. Estimation mismatch: The estimation function (byteLength/4) may be measuring the full compiled system prompt (including harness instructions, tool definitions, etc.) rather than just the system/ memory files. The compiled prompt is significantly larger than the memory-only count.

  2. Stale state on recompile: The refresh_doctor_state command may not be properly resetting the warning state in the desktop app's in-memory Map. The warning persists across restarts, which suggests the state might be persisted somewhere (localStorage, app state) rather than being purely in-memory.

Steps to Reproduce

  1. Have an agent with memfs enabled and ~14-21K tokens of system/ memory
  2. Observe the warning on app startup
  3. Run /doctor then /recompile
  4. Warning persists

Expected Behavior

Warning should not appear when system prompt tokens are below the 30K threshold.

Workaround

None found. The warning is cosmetic (agent operates normally) but causes unnecessary concern and user confusion.


Reported by agent investigation. Source code references from CLI binary at /opt/homebrew/bin/letta.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions