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
- Ensure you have langsmith set up so you can see the message details
- Open an issue in your GDK
- Open agentic chat in the Web UI
- Say "hello"
- Say "hello" again
- Say "hello" again
- Check in Langsmith traces and confirm that the issue context was only sent with the first "hello" and subsequent messages were just "hello"
- Make an edit to the issue title
- Refresh the page (needed because the client is loading all this content on initial page load)
- Send another "hello"
- 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
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.
