fix: prevent duplicate AI agent invocation on first interaction - #3267
Merged
Conversation
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
Davidhidalgo
approved these changes
Sep 3, 2026
pepalonsocosta
approved these changes
Sep 3, 2026
…ge.json and package-lock.json
…t response on first interaction
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
On the first interaction, Flow Builder no longer appends a second AI Agent resolution when the start contents already handle the user input (a Bot Action as the last node, or an AI Agent / AI Agent Router anywhere in the start chain). The user message is still processed once by the agent already reached from the start flow.
Context
When
session.is_first_interactionis true,getContentsByFirstInteractionalways resolved the Main start contents and then, if the user sent text, concatenatedgetContentsByAiAgentFromUserInput.A common layout is: Main start node → go-to-flow → AI Agents.
getStartContents()already follows that go-to-flow and includes the AI Agent. Concatenating the user-input AI Agent path invoked inference twice and returned twoFlowAiAgentcontents with the same greeting, so WhatsApp (and other channels) showed two identical messages.This only happened on the first interaction. Later turns use
getContents()without that concatenation, so the agent answered once as expected.The same first-interaction path already skipped extra matching when the last start content was a Bot Action. AI Agent / AI Agent Router were not covered.
Approach taken / Explain the design
startContentsAlreadyHandleUserInputdecides whether start contents already consume the user message:If that helper returns true, first interaction returns only the start contents.
FlowBuilderAction.prepareContentsToRenderstill runs inference once on the agent already in that list, using the current user input.If the start chain is only welcome text (no agent), behaviour is unchanged: keywords / intents / AI Agent from user input are still appended after the start contents.
To document / Usage example
No public API change. Bots whose Main start goes to the AI Agents flow no longer need a workaround on first interaction.
No extra configuration is required.
disableAIAgentInFirstInteractionstill disables the appended user-input AI Agent path when start contents do not already include an agent.Testing
The pull request...
Added a first-interaction test with Main start = go-to-flow to AI Agents and user text
hola:getAiAgentResponseis called once and contents contain a singleFlowAiAgent. Existing first-interaction tests (welcome + agent,disableAIAgentInFirstInteraction) still pass.