Add conversation context to AI mention flow goals
What does this MR do and why?
When a foundational-flow service account is @mentioned in a note, the AI agent currently only receives the single triggering note as its input. To understand a multi-turn conversation, the agent therefore has to fetch the rest of the discussion itself — which means additional LLM calls and token usage, i.e. extra latency and cost for our customers. This MR gives the agent the full discussion thread up front so that round-trip is no longer needed.
This is part 1 of 3 in splitting up the larger mention → messaging-adapter migration (alternative to !235039 (closed) / !238360 (closed)) into independently reviewable pieces. This part is self-contained and improves the existing RunService mention path — no feature flag, no new adapter.
Changes:
- New
Ai::Notes::ConversationContextBuilder— extracts the human (non-system) notes of a note's discussion, ordered chronologically, capped at 15 (older messages truncated with a notice telling the agent how to fetch more), formatted as<message>blocks. - Mention goal template restructured — the single
<mention>block becomes explicit<gitlab_context>(resource/title/note URLs) and<conversation>(thread history) sections. Delivery instructions are now selectable via adelivery_modeparam::defaultpreserves today's reply-in-thread +glab apiguidance;:adapteris added (dormant) for the later messaging-adapter path. PostProcessServicewiring — feeds the built conversation context (instead of justnote.note) plus a structuredsource_contextanddiscussion_idinto the mention flow.
Database
Raw SQL:
SELECT "notes".*
FROM "notes"
WHERE "notes"."noteable_type" = 'Issue' -- O
AND "notes"."noteable_id" = [notable_id]
AND "notes"."discussion_id" = [discussion_id]
AND "notes"."system" = FALSE
ORDER BY "notes"."created_at" DESC, "notes"."id" DESC
LIMIT 16;Plan: https://console.postgres.ai/gitlab/gitlab-production-main/sessions/52186/commands/153708
How to set up and validate locally
- Set up a foundational-flow service account with a
:mentiontrigger on a project. - In an issue/MR/work-item discussion, post a couple of comments, then
@mentionthe service account in a reply. - Confirm the agent's goal now contains a
<conversation>block with the prior messages (not just the triggering note) and a<gitlab_context>block with the resource/note URLs. This can be inspected in the agent session view or in the LangSmith traces for the run.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist.
References
- Parent effort: !235039 (closed), !238360 (closed)
- Related: #597572 (closed)
- Tracking issue: #601705