Orchestrator and sub-agents produce duplicate final messages
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #3548718. --> Reported by: [narendrar](https://www.drupal.org/user/1730192) Related to !550 >>> <h3 id="overview">Overview</h3> <p><span class="drupalorg-gitlab-issue-link drupalorg-gitlab-link-wrapper"><a href="https://git.drupalcode.org/project/canvas/-/work_items/3531000" class="drupalorg-gitlab-link">https://git.drupalcode.org/project/canvas/-/work_items/3531000</a></span> added agent polling. This is a follow-up for <a href="https://www.drupal.org/project/canvas/issues/3531000#comment-16280629">#43.2</a> to decide on what do do in case of showing agent message and final message which could be duplicate.</p> <h3 id="proposed-resolution">Proposed resolution</h3> <p>The orchestrator message and status currently always appear at the top, while the sub-agent responses appear at the bottom. This creates a poor user experience. For example, the page builder agent may complete its task and display a message such as &ldquo;components have been added,&rdquo; but unless the orchestrator response is received, the components are not actually placed on the page. In this situation, the user may need to scroll up to notice the &ldquo;thinking&rdquo; status indicating that the orchestrator is still running. This results in a confusing and suboptimal experience. To improve this, the orchestrator response should be moved to the bottom.</p> <p>The duplication of messages mentioned in <a href="https://www.drupal.org/project/canvas/issues/3531000#comment-16280629">#43.2</a> was caused by two reasons:</p> <ul> <li>The orchestrator message was not actually being sent back to the user when it invoked a sub-agent. The $response['message'] rendered in the UI always contained the message from the last sub-agent invoked by the orchestrator. This has now been fixed.</li> <li>The <code>buildHtmlContent </code>method in Aiwizard compiles messages from all agents obtained through polling, which also includes the orchestrator message. Once polling is complete, the orchestrator message should be removed from the list so that only the sub-agent messages are displayed.</li> </ul> <h3 id="ui-changes">User interface changes</h3> <h3>Before</h3> <ul> <li>Orchestrator status (Thinking) appears at the top</li> <li>The orchestrator status (&ldquo;Thinking&rdquo;) appears at the top.</li> <li>The final message after polling is duplicated. It is the same message generated by the metadata generation agent, which appears below &ldquo;Generate a Description&rdquo;.</li> </ul> <p><img src="https://www.drupal.org/files/issues/2026-02-06/Drupal%20Canvas%20%281%29.gif" alt="test"></p> <h3>After</h3> <ul> <li>The orchestrator status always appears at the bottom.</li> <li>The final orchestrator message is displayed at the end of polling, and there is no message duplication.</li> </ul> <p><img src="https://www.drupal.org/files/issues/2026-02-06/Drupal%20Canvas%20%282%29.gif" alt="test"></p> <h3 id="summary-ai-usage">AI usage (if applicable)</h3> <p>[ ] AI Assisted Issue<br> This issue was generated with AI assistance, but was reviewed and refined by the creator.</p> <p>[ ] AI Assisted Code<br> This code was mainly generated by a human, with AI autocompleting or parts AI generated, but under full human supervision.</p> <p>[x] AI Generated Code<br> This code was mainly generated by an AI with human guidance, and reviewed, tested, and refined by a human.</p> <p>[ ] Vibe Coded<br> This code was generated by an AI and has only been functionally tested.</p> > Related issue: [Issue #3555239](https://www.drupal.org/node/3555239) > Related issue: [Issue #3573049](https://www.drupal.org/node/3573049) > Related issue: [Issue #3531000](https://www.drupal.org/node/3531000)
issue