Skip to content

chore: deduplicate <additional_context> in message history

What does this merge request do and why?

As described in gitlab-org/gitlab#572713 (closed) we are including the same <additional_context> in every message we send in agentic chat. Each time a chat is resumed we send whatever additional_context the user is viewing. If you stay on the same page and keep sending messages it keeps showing up the same content every time.

This MR changes things such that we strip out any duplicate <additional_context> tags before sending to the LLM. We only strip the tag if the content is identical. This means that if an issue changes in any way while you're viewing it then it will be included again (so will the original version so that the chat history is always preserved).

This approach going forward should never actually change the chat history at all because duplicates won't get sent to the LLM in the first place. But existing chat histories may change by removing duplicates in future messages.

We have chosen to keep the earliest <additional_context> tag so that we avoid changing the conversation history. If we don't do this it may promote hallucinations because the chat history might incoherently suggest that the LLM is just making up information in responose to questions when in fact it had access to information at that point in time.

How to set up and validate locally

  1. Ensure you have langsmith set up so you can see the message details
  2. Open an issue in your GDK
  3. Open agentic chat in the Web UI
  4. Say "hello"
  5. Say "hello" again
  6. Say "hello" again
  7. Check in Langsmith traces and confirm that the issue context was only sent with the first "hello" and subsequent messages were just "hello"
  8. Make an edit to the issue title
  9. Refresh the page (needed because the client is loading all this content on initial page load)
  10. Send another "hello"
  11. Confirm in langsmith trace that the updated content is visible in the most recent message. The first message will still include the old content under <additional_context>

Screenshots

Screenshot_2025-10-01_at_12.23.35_pm

source

Merge request checklist

  • Tests added for new functionality. If not, please raise an issue to follow up.
  • Documentation added/updated, if needed.
  • If this change requires executor implementation: verified that issues/MRs exist for both Go executor and Node executor or confirmed that changes are backward-compatible and don't break existing executor functionality.

Related to gitlab-org/gitlab#572713 (comment 2785302442)

Edited by Dylan Griffith

Merge request reports

Loading