Skip to content

fix(chat): include conversation history in Gemini prompt#658

Open
Tejas-h-blitz wants to merge 1 commit into
parthbuilds-community:mainfrom
Tejas-h-blitz:fix/chat-history-ignored-in-gemini-prompt
Open

fix(chat): include conversation history in Gemini prompt#658
Tejas-h-blitz wants to merge 1 commit into
parthbuilds-community:mainfrom
Tejas-h-blitz:fix/chat-history-ignored-in-gemini-prompt

Conversation

@Tejas-h-blitz

Copy link
Copy Markdown

🐛 Problem

Conversation history sent by the client was never included in the prompt
sent to Gemini. The prompt construction used an if/else if chain where
SAFETY_INSTRUCTION (a module-level constant) is always truthy, so the
historyBlock branch never executed. Every message was treated as the
first message in a new conversation.

Closes #645

📝 What does this PR do?

Replaces the broken if/else if chain with a single prompt builder that
always includes both SAFETY_INSTRUCTION and historyBlock (when
present):

const prompt = [
  SYSTEM_PROMPT,
  SAFETY_INSTRUCTION,
  historyBlock ? `Conversation so far:\n${historyBlock}` : "",
  `[USER INPUT START]\n${sanitized}\n[USER INPUT END]`,
]
  .filter(Boolean)
  .join("\n\n");

Also removed the redundant typeof chatSchema !== 'undefined' guard
since chatSchema is always defined in this file.

🧪 How was this tested?

  • Sent multi-turn messages and verified Gemini response references prior
    context
  • Verified single-message (no history) requests still work correctly
  • Verified prompt injection sanitization still applies

✅ Checklist

  • I've read the CONTRIBUTING guide
  • My code follows the project's style guidelines
  • I've tested my changes locally
  • I've linked the related issue
  • I haven't introduced any new secrets or API keys

@github-actions github-actions Bot added enhancement New feature or request refactor Improve code without changing functionality backend labels Jun 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend enhancement New feature or request refactor Improve code without changing functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(chat): conversation history is ignored when building Gemini prompt

1 participant