Skip to content

Commit da8d0f1

Browse files
authored
Bugfix/Disable default user input if memory is disabled for first node (#4530)
disable default user input if memory is disabled for first node
1 parent 3d6bf72 commit da8d0f1

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

packages/components/nodes/agentflow/Agent/Agent.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ class Agent_Agentflow implements INode {
756756
/*
757757
* If this is the first node:
758758
* - Add images to messages if exist
759-
* - Add user message
759+
* - Add user message if it does not exist in the agentMessages array
760760
*/
761761
if (options.uploads) {
762762
const imageContents = await getUniqueImageMessages(options, messages, modelConfig)
@@ -767,7 +767,7 @@ class Agent_Agentflow implements INode {
767767
}
768768
}
769769

770-
if (input && typeof input === 'string') {
770+
if (input && typeof input === 'string' && !agentMessages.some((msg) => msg.role === 'user')) {
771771
messages.push({
772772
role: 'user',
773773
content: input
@@ -977,7 +977,19 @@ class Agent_Agentflow implements INode {
977977
inputMessages.push(...runtimeImageMessagesWithFileRef)
978978
}
979979
if (input && typeof input === 'string') {
980-
inputMessages.push({ role: 'user', content: input })
980+
if (!enableMemory) {
981+
if (!agentMessages.some((msg) => msg.role === 'user')) {
982+
inputMessages.push({ role: 'user', content: input })
983+
} else {
984+
agentMessages.map((msg) => {
985+
if (msg.role === 'user') {
986+
inputMessages.push({ role: 'user', content: msg.content })
987+
}
988+
})
989+
}
990+
} else {
991+
inputMessages.push({ role: 'user', content: input })
992+
}
981993
}
982994
}
983995

packages/components/nodes/agentflow/LLM/LLM.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ class LLM_Agentflow implements INode {
410410
/*
411411
* If this is the first node:
412412
* - Add images to messages if exist
413-
* - Add user message
413+
* - Add user message if it does not exist in the llmMessages array
414414
*/
415415
if (options.uploads) {
416416
const imageContents = await getUniqueImageMessages(options, messages, modelConfig)
@@ -421,7 +421,7 @@ class LLM_Agentflow implements INode {
421421
}
422422
}
423423

424-
if (input && typeof input === 'string') {
424+
if (input && typeof input === 'string' && !llmMessages.some((msg) => msg.role === 'user')) {
425425
messages.push({
426426
role: 'user',
427427
content: input
@@ -545,7 +545,19 @@ class LLM_Agentflow implements INode {
545545
inputMessages.push(...runtimeImageMessagesWithFileRef)
546546
}
547547
if (input && typeof input === 'string') {
548-
inputMessages.push({ role: 'user', content: input })
548+
if (!enableMemory) {
549+
if (!llmMessages.some((msg) => msg.role === 'user')) {
550+
inputMessages.push({ role: 'user', content: input })
551+
} else {
552+
llmMessages.map((msg) => {
553+
if (msg.role === 'user') {
554+
inputMessages.push({ role: 'user', content: msg.content })
555+
}
556+
})
557+
}
558+
} else {
559+
inputMessages.push({ role: 'user', content: input })
560+
}
549561
}
550562
}
551563

0 commit comments

Comments
 (0)