Open
Conversation
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
The goal of this PR is to add an option to the Dust node > Operation: Talk to an agent, to listen to events SSE endpoint until receiving the agent_message_done event or until timeout is reached, to then retrieve the last Agent message and to return it, with the events.
The code adds 2 options in the Talk to an agent operation:

The first option changes the request made to create the conversation and post the message, to a blocking: false mode.
If this option is enabled, the request won't wait for the Agent response. The code will instead call the /events endpoint in SSE, to listen to the conversation events until receiving the "agent_message_done" event, or until the timeout defined in the second option (or by default = 300 seconds) is reached.
Once the event is received, the code will retrieve all the messages from the agent having the node message ID as parentMessageId, it will concatenate them and return it in the node response. It will also add the "events" arrays in the node response, containing the data json of each events received during the event listening.
On top of this, I edited the way to join the messages to avoid joining empty messages, to avoid responses looking like "\n\n\n\nHello World\n". Unfortunately, the code inside Dust can still generate this in one single agent message, so we can't fully avoid it.
Avoiding joining empty messages will output "No message returned" in the case there are only empty agent messages in the conversation.
Tests
I built the node and started a local instance of n8n with it:
In the local n8n instance, I created a Dust node, used the Talk to agent operation, and called an agent that used to answer "\n\n\n\n" because it usually takes 10-20 minutes to run.
With this setup, I enabled the SSE option + timeout at 3000 seconds, and the node now returns (in my case after 409379 ms) the agent message and an array of events (including user_message_new, agent_message_new, conversation_title and agent_mesasage_done).
With the same node, I configured the node with a 10 second timeout, and the node fails after 10491 ms with the error message "This operation was aborted".
With the same node, I disabled the SSE option and got "No message returned" after ~180 seconds.
With the same node, I disabled the SSE option and configured a timeout of 10 seconds. The node behaves normally, and the timeout is not applied.
Risk
The code contains a
while (true)loop but is wrapped in an AbortController with a timeout that is always set.I couldn't test the case where the SSE connexion is unexpectedly interrupted. The code is supposed to produce an exception that will be caught in the try/catch and should produce an error in n8n node.
Deploy plan
Simply merge the code and make a new release in npm, available for n8n clients.