fix: system prompt appends to caller's system message, empty = passthrough

Handle all 4 combinations of caller system message and systemprompt.md
correctly: append when both exist, passthrough when only one exists,
omit when neither exists. Fixes leading \n\n when no caller system msg.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Claude Code
2026-04-01 16:10:24 -05:00
parent 2801a63b11
commit 90dd87edeb
2 changed files with 84 additions and 8 deletions

View File

@@ -219,15 +219,22 @@ async def build_augmented_messages(incoming_messages: List[Dict]) -> List[Dict]:
}
# === LAYER 1: System Prompt ===
system_content = ""
# Caller's system message passes through; systemprompt.md appends if non-empty.
caller_system = ""
for msg in incoming_messages:
if msg.get("role") == "system":
system_content = msg.get("content", "")
caller_system = msg.get("content", "")
break
if system_prompt:
system_content += "\n\n" + system_prompt
if caller_system and system_prompt:
system_content = caller_system + "\n\n" + system_prompt
elif caller_system:
system_content = caller_system
elif system_prompt:
system_content = system_prompt
else:
system_content = ""
if system_content:
messages.append({"role": "system", "content": system_content})
logger.info(f"Layer 1 (system): {count_tokens(system_content)} tokens")