Enrich Duo Developer goal templates with trigger context: who triggered the flow and user notification instructions
## Problem to solve
The Rails-side goal templates for the Duo Developer flow (`GoalTemplates::Developer`) were introduced in [!231681 (merged)](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/231681) to move goal construction from the AI Gateway Jinja templates to Rails. This was a significant improvement, but the current templates are missing two important pieces of context:
### 1. The triggering user is not identified in the goal
When the agent is triggered by a mention or an assignment, the goal does not tell the agent **who** triggered the flow. The agent has to infer this by reading the thread or issue context, which is expensive and error-prone.
For example, the current `MENTION_TEMPLATE` is:
```
You were mentioned in a note on this %{resource_name}: %{note_url}
<mention>
%{user_input}
</mention>
Read the conversation thread to fully understand what is being asked...
```
The agent knows _what_ was said (via `user_input`) and _where_ (via `note_url`), but not _who_ said it. This means the agent cannot reliably:
* Address the user by name in its response
* `@mention` the triggering user when it completes the task
* Assign the triggering user to any MRs it creates
### 2. No instructions to notify the triggering user when done
Users switch context while the agent works (sessions can take 3–15 minutes). There are no instructions in the goal templates telling the agent to notify the triggering user when it finishes. This means users have no reliable way to know when the agent is done.
Related feedback: https://gitlab.com/gitlab-org/editor-extensions/gitlab-lsp/-/work_items/2206#note_3269871298
Related discussion: https://gitlab.com/gitlab-org/editor-extensions/gitlab-lsp/-/work_items/2206#note_3288310430
## Proposal
Enrich the `GoalTemplates::Developer` templates (in `ee/app/models/ai/catalog/goal_templates/developer.rb`) to include:
### 1. Pass the triggering user to the goal
The `resolve` method already receives `params:` — extend it to accept and interpolate a `triggered_by_username` variable. The trigger points in Rails already have access to the user who triggered the event (e.g. the note author for mention triggers, the user who made the assignment for assign triggers).
Example enriched `MENTION_TEMPLATE`:
```
You were mentioned in a note on this %{resource_name}: %{note_url}
The mention was made by @%{triggered_by_username}.
<mention>
%{user_input}
</mention>
Read the conversation thread to fully understand what is being asked. Then determine the appropriate course of action.
When responding, reply in the same discussion thread where you were mentioned. @mention @%{triggered_by_username} in your reply so they are notified. Only post a new top-level comment if the task explicitly calls for a standalone update.
If the task involves code changes, verify they work. If you create a merge request, assign @%{triggered_by_username} as the assignee.
```
Similarly, enrich the assign templates to include who assigned the agent and instructions to notify them when done.
### 2. Pass the triggering user from the trigger points
Update the trigger points that call `goal_templates.resolve(...)` to pass the triggering user:
* `ee/app/services/ee/notes/post_process_service.rb` — mention trigger: pass the note author
* `ee/app/services/ai/flow_triggers/run_service.rb` — assign/assign_reviewer triggers: pass the user who made the assignment
## Key files
| File | Change |
|------|--------|
| `ee/app/models/ai/catalog/goal_templates/developer.rb` | Add `%{triggered_by_username}` interpolation to all templates; add notification instructions |
| `ee/app/services/ee/notes/post_process_service.rb` | Pass note author username to `resolve` for mention triggers |
| `ee/app/services/ai/flow_triggers/run_service.rb` | Pass assigning user username to `resolve` for assign/assign_reviewer triggers |
## Further details
This was raised during the [DAP Factory Trial with Duo CLI](https://gitlab.com/gitlab-org/editor-extensions/gitlab-lsp/-/work_items/2206) where repeated feedback highlighted that:
* The agent does not notify users when it finishes
* The agent often misses the intent of the mention because it lacks the trigger context
The goal construction was moved to Rails in [!231681 (merged)](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/231681), making this the right place to add trigger context. Newer GitLab versions will send the goal from Rails, so this change will benefit all users on those versions.
A companion issue for the AI Gateway side (updating agent goals explicitly) is tracked at: https://gitlab.com/gitlab-org/modelops/applied-ml/code-suggestions/ai-assist/-/work_items/2211
## Links / references
* Goal construction moved to Rails: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/231681
* Feedback thread: https://gitlab.com/gitlab-org/editor-extensions/gitlab-lsp/-/work_items/2206#note_3288310430
* User notification feedback: https://gitlab.com/gitlab-org/editor-extensions/gitlab-lsp/-/work_items/2206#note_3269871298
* AI Gateway companion issue: https://gitlab.com/gitlab-org/modelops/applied-ml/code-suggestions/ai-assist/-/work_items/2211
issue