From 6b074653f29ea804b23b58c31fff42a2ce2c8cd4 Mon Sep 17 00:00:00 2001 From: Joao Date: Fri, 16 Jan 2026 20:16:44 +0000 Subject: [PATCH] fix: prevent system prompt re-injection on subsequent turns When tool results are sent back to the model, the system prompt was being re-injected into the user message content, causing the model to think the user had pasted the system prompt again. This was especially noticeable after multiple tool uses. The fix checks if there is conversation history (len(history) > 0). If so, it's a subsequent turn and we skip system prompt injection. The system prompt is only injected on the first turn (len(history) == 0). This ensures: - First turn: system prompt is injected - Tool result turns: system prompt is NOT re-injected - New conversations: system prompt is injected fresh --- internal/translator/kiro/claude/kiro_claude_request.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/internal/translator/kiro/claude/kiro_claude_request.go b/internal/translator/kiro/claude/kiro_claude_request.go index 06141a29..bcd39af4 100644 --- a/internal/translator/kiro/claude/kiro_claude_request.go +++ b/internal/translator/kiro/claude/kiro_claude_request.go @@ -240,9 +240,13 @@ func BuildKiroPayload(claudeBody []byte, modelID, profileArn, origin string, isA // Process messages and build history history, currentUserMsg, currentToolResults := processMessages(messages, modelID, origin) - // Build content with system prompt + // Build content with system prompt (only on first turn to avoid re-injection) if currentUserMsg != nil { - currentUserMsg.Content = buildFinalContent(currentUserMsg.Content, systemPrompt, currentToolResults) + effectiveSystemPrompt := systemPrompt + if len(history) > 0 { + effectiveSystemPrompt = "" // Don't re-inject on subsequent turns + } + currentUserMsg.Content = buildFinalContent(currentUserMsg.Content, effectiveSystemPrompt, currentToolResults) // Deduplicate currentToolResults currentToolResults = deduplicateToolResults(currentToolResults)