Draft: Expose alternative branches to FE

What does this MR do and why?

Allows the front end to request the alternative messages to a specific user message. This will be used by the retry feature, and allows the front end to display all branches to the user.

Each group of alternatives also returns forkThreadTs which is the ID the front end should pass as resume_checkpoint_ts to select this branch as the branch to continue from.

References

Full PoC: gitlab-org/modelops/applied-ml/code-suggestions/ai-assist!6124 (closed)

Epic: gitlab-org#21289

Python implementation for retries: gitlab-org/modelops/applied-ml/code-suggestions/ai-assist!6356 (merged)

Depends on: !249131 (merged)

Video demo: gitlab-org#21289 (comment 3666671057)

How to set up and validate locally

Query to get thread_ts and counts
{
  duoWorkflowWorkflows(workflowId: "gid://gitlab/Ai::DuoWorkflows::Workflow/11") {
    nodes { latestCheckpoint { duoMessages { content messageType threadTs parentTs alternativeCount } } }
  }
}
Query to get alternatives
{
  duoWorkflowBranches(
    workflowId: "gid://gitlab/Ai::DuoWorkflows::Workflow/52",
    threadTs: "1f196488-56dc-6fb7-8002-12836bae9b61"
  )
  {
    forkThreadTs
    messages {
      content
      messageType
      threadTs
      parentTs
      additionalContext { id category content metadata }
    }
  }
}
  1. Enable flags for incremental checkpoints:
    1. Feature.enable(:duo_workflow_incremental_checkpoints)
    2. Feature.enable(:duo_workflow_read_incremental_checkpoints)
    3. Feature.enable(:dw_read_blobs_graphql)
  2. Checkout this branch
    1. From gdk/gitlab run git checkout feature/duo-workflow-message-alternatives
  3. Restart
    1. gdk restart
  4. Start a conversation "Say 1" => "1" => "Say 2" => "2"
  5. From http://gdk.test:8080/-/graphql-explorer (replace port) run the query "Query to get thread_ts and counts` above with the workflow ID (You can get the workflow ID from dev tools => Application => Session storage => http://gdk.test:8080 => key).
    1. You should get something like
GraphQL response
{
  "data": {
    "duoWorkflowWorkflows": {
      "nodes": [
        {
          "latestCheckpoint": {
            "duoMessages": [
              {
                "content": "Say 1",
                "messageType": "user",
                "threadTs": "1f194af9-1e18-67ed-8000-179ed51f8f07",
                "parentTs": "1f194af9-1e15-6170-bfff-0db48fd15212",
                "alternativeCount": 0
              },
              {
                "content": "1",
                "messageType": "agent",
                "threadTs": "1f194af9-3081-6a93-8001-7df329fe8fe2",
                "parentTs": "1f194af9-1e18-67ed-8000-179ed51f8f07",
                "alternativeCount": null
              },
              {
                "content": "Say 2",
                "messageType": "user",
                "threadTs": "1f194af9-6ffa-6fcf-8002-69189ce6196a",
                "parentTs": "1f194af9-3081-6a93-8001-7df329fe8fe2",
                "alternativeCount": 0
              },
              {
                "content": "2",
                "messageType": "agent",
                "threadTs": "1f194af9-6ffa-6fcf-8002-69189ce6196a",
                "parentTs": "1f194af9-3081-6a93-8001-7df329fe8fe2",
                "alternativeCount": null
              }
            ]
          }
        }
      ]
    }
  },
  "correlationId": "01KZNQ9YCPF5K0BS2KQQQADJEC"
}
  1. Copy the parentTs of "Say 2" into gitlab-ai-gateway/duo_workflow_service/server.py replacing resume_checkpoint_ts=start_workflow_request.startRequest.resume_checkpoint_ts with resume_checkpoint_ts="1f194af9-3081-6a93-8001-7df329fe8fe2"
  2. Run gdk restart duo-workflow-service
  3. Send new messages "Say 3", "Say 4"
    1. 3 will replace 2, and then 4 will replace 3
  4. Run the query again, and you will see that 4 has 2 alternatives
  5. Run "Query to get thread_ts and counts" with the thread_ts of "say 4"
    1. You should see messages 2 and 3
GraphQL response
{
  "data": {
    "duoWorkflowBranches": [
      {
        "forkThreadTs": "1f194af9-6ffa-6fcf-8002-69189ce6196a",
        "messages": [
          {
            "content": "Say 2",
            "messageType": "user",
            "threadTs": "1f194af9-6ffa-6fcf-8002-69189ce6196a",
            "parentTs": "1f194af9-3081-6a93-8001-7df329fe8fe2",
            "alternativeCount": 2
          },
          {
            "content": "2",
            "messageType": "agent",
            "threadTs": "1f194af9-6ffa-6fcf-8002-69189ce6196a",
            "parentTs": "1f194af9-3081-6a93-8001-7df329fe8fe2",
            "alternativeCount": null
          }
        ]
      },
      {
        "forkThreadTs": "1f194b00-309b-69f8-8003-8f17e5216602",
        "messages": [
          {
            "content": "Say 3",
            "messageType": "user",
            "threadTs": "1f194b00-216f-6995-8002-85db5d02e91a",
            "parentTs": "1f194af9-3081-6a93-8001-7df329fe8fe2",
            "alternativeCount": 2
          },
          {
            "content": "3",
            "messageType": "agent",
            "threadTs": "1f194b00-309b-69f8-8003-8f17e5216602",
            "parentTs": "1f194b00-216f-6995-8002-85db5d02e91a",
            "alternativeCount": null
          }
        ]
      }
    ]
  },
  "correlationId": "01KZNQPFTKXC02MNRQXQZR918Z"
}

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Kaveh Nejad

Merge request reports

Loading
Loading