Draft: Extract MR ID from additional context to update resourceId
What does this MR do and why?
For #483496 (closed), related to !167734 (merged) and gitlab-org/editor-extensions/gitlab-lsp!842 (merged)
As part of the pinned context feature, users should be able to /include a merge request as additional context. We already have a merge request tool implemented in the AIGW that fetches MR information. In order to make use of this, we need to extract the MR id from the additional context a user adds and update the GraphQl mutation to include a resourceId as an argument before it is sent to the AIGW. With this information (the MR global ID), the AIGW will treat the MR as if the user is currently viewing it and correctly identify the merge_request_reader as the proper tool to use.
I considered updating the AIGW additional_context prompt to do something like:
...
{%- if added_context.category == "MERGE_REQUEST" %}
To fetch the context for this merge request, please use the merge_request_reader with the following merge request ID: {{ added_context.id }}
{%- else %}
<additional_context>
<id> {{ added_context.id }} </id>
<category> {{ added_context.category }} </category>
<content>
{{ added_context.content }}
</content>
</additional_context>
...
With the idea being giving the llm a tip to use the MR tool. However, I don't think this is necessary as with the changes I propose in this MR, the MR context works out of the box with the AIGW. This does make me wonder if it would improve latency to update the AIGW prompt anyway to skip adding MR context if it exists? Otherwise we are just stuffing the prompt with additional context unnecessarily.
TODO
-
specs
MR acceptance checklist
Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Screenshots or screen recordings
| graphql mutation | Duo Chat |
|---|---|
![]() |
![]() |
Example LangSmith tracing: https://smith.langchain.com/public/2e5eb202-8d54-4664-b521-97aa593000ce/r
How to set up and validate locally
- Run gdk locally
- In terminal,
gdk rails c - Look up any MR's global id and title
MergeRequest.last.to_global_idandMergeRequest.last.title - Navigate to the graphql explorer
http://gdk.test:3000/-/graphql-explorer - Use the ai action chat mutation to start a chat and pass a merge request as additional context:
mutation {
aiAction(
input: {
chat: {
content: "What is the name of this merge request?",
additionalContext: [
{
category: MERGE_REQUEST,
id: "gid://gitlab/MergeRequest/156",
content: ""
}
]}}) {
clientMutationId
errors
}
}
- Open Duo Chat in the UI and verify Duo responds with the correct MR title
- Open LangSmith (note you need to have tracing setup (setup docs here) and verify the AI correctly identified it should use the MergeRequest tool to answer the question

