Skip to content

[Bug] AI Assistant restart chat still sends previous conversation history to LLM providers #3261

@akashrai2003

Description

@akashrai2003

Describe the bug
When clicking "Restart Chat" in the AI Assistant, the chat interface resets visually, but the LLM provider continues receiving the entire previous conversation history in API calls unless the page is refreshed. This wastes tokens and significantly increases API costs.

Evidence: After restart, network logs show the API request payload still contains ALL previous messages from before the restart (see logs below).

Issues with it:

  • Wasted API tokens (can be 100s-1000s per conversation)
  • Increased costs
  • Slower response times

To Reproduce
Steps to reproduce the behavior:

  1. Go to 'kepler.gl with AI Assistant enabled'
  2. Open browser DevTools → Network tab
  3. Click on 'AI Assistant panel and start a conversation (ask 3-4 questions)'
  4. Click 'Restart Chat button'
  5. Send a new message
  6. Check the API request to LLM provider (OpenAI/Google/etc.)
  7. See the issue: Request payload contains old conversation messages that should not be there

Expected behavior
After clicking "Restart Chat", LLM API calls should only contain the new message and system instructions. Previous conversation history should not be included in the request payload.

Screenshots

Image

After clicking "Restart Chat" and sending a new message, the API request still contains:

{
  "contents": [
    {
      "role": "user",
      "parts": [{"text": "How would you like to change the basemap's styleType?"}]
    },
    {
      "role": "model",
      "parts": [{"text": "I can help you change the basemap's styleType! ..."}]
    },
    {
      "role": "user",
      "parts": [{"text": "satellite"}]
    },
    {
      "role": "model",
      "parts": [{"text": "Great choice! Let's change the basemap to satellite..."}]
    },
    {
      "role": "user",
      "parts": [{"text": "what did I ask earlier?"}]  // ← NEW message after restart
    }
  ]
}

All the old conversation (first 4 exchanges) should NOT be there after restart, but they are being sent with every new request.

Desktop (please complete the following information):

  • OS: Windows 10/11 and Ubuntu 22 (reproducible on all platforms)
  • Browser: Tested on Brave/Chrome
  • Version: Latest (master branch)
  • LLM Providers tested: Google Gemini, and custom vLLM implementation

Additional context
In src/ai-assistant/src/components/ai-assistant-component.tsx, the onRestartAssistant() function clears Redux state but the AiAssistant component doesn't remount - it only uses initialMessages prop on first mount. When the prop changes, internal state is NOT reset.

Proposed Fix: Use the library's built-in restartChat function combined with React's key prop

I have implemented and tested this fix locally and am ready to submit a PR if approved.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions