Skip to content

Do not allow repeated roles on Duo Chat to prevent errors

What does this MR do and why?

We noticed that sometimes Duo Chat can get into an error state where it has multiple of the same role in a row.

Then we get this error from the AI Gateway:

roles must alternate between "user" and "assistant", but found multiple "assistant" roles in a row

This MR makes it so that only the last message in a row with a role gets added to the prompt.

MR acceptance checklist

Screenshots or screen recordings

N/A

How to set up and validate locally

  1. Regression test Duo Chat
  2. You can edit the code here to add another 'Utils::Prompt.as_assistant' method call. It should not work on master, but it does with this change.

Related to #469101 (closed)

Edited by Lesley Razzaghian

Merge request reports