Skip to content

Bugfix/Disable default user input if memory is disabled for first node #4530

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions packages/components/nodes/agentflow/Agent/Agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ class Agent_Agentflow implements INode {
/*
* If this is the first node:
* - Add images to messages if exist
* - Add user message
* - Add user message if it does not exist in the agentMessages array
*/
if (options.uploads) {
const imageContents = await getUniqueImageMessages(options, messages, modelConfig)
Expand All @@ -767,7 +767,7 @@ class Agent_Agentflow implements INode {
}
}

if (input && typeof input === 'string') {
if (input && typeof input === 'string' && !agentMessages.some((msg) => msg.role === 'user')) {
messages.push({
role: 'user',
content: input
Expand Down Expand Up @@ -977,7 +977,19 @@ class Agent_Agentflow implements INode {
inputMessages.push(...runtimeImageMessagesWithFileRef)
}
if (input && typeof input === 'string') {
inputMessages.push({ role: 'user', content: input })
if (!enableMemory) {
if (!agentMessages.some((msg) => msg.role === 'user')) {
inputMessages.push({ role: 'user', content: input })
} else {
agentMessages.map((msg) => {
if (msg.role === 'user') {
inputMessages.push({ role: 'user', content: msg.content })
}
})
}
} else {
inputMessages.push({ role: 'user', content: input })
}
}
}

Expand Down
18 changes: 15 additions & 3 deletions packages/components/nodes/agentflow/LLM/LLM.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ class LLM_Agentflow implements INode {
/*
* If this is the first node:
* - Add images to messages if exist
* - Add user message
* - Add user message if it does not exist in the llmMessages array
*/
if (options.uploads) {
const imageContents = await getUniqueImageMessages(options, messages, modelConfig)
Expand All @@ -421,7 +421,7 @@ class LLM_Agentflow implements INode {
}
}

if (input && typeof input === 'string') {
if (input && typeof input === 'string' && !llmMessages.some((msg) => msg.role === 'user')) {
messages.push({
role: 'user',
content: input
Expand Down Expand Up @@ -545,7 +545,19 @@ class LLM_Agentflow implements INode {
inputMessages.push(...runtimeImageMessagesWithFileRef)
}
if (input && typeof input === 'string') {
inputMessages.push({ role: 'user', content: input })
if (!enableMemory) {
if (!llmMessages.some((msg) => msg.role === 'user')) {
inputMessages.push({ role: 'user', content: input })
} else {
llmMessages.map((msg) => {
if (msg.role === 'user') {
inputMessages.push({ role: 'user', content: msg.content })
}
})
}
} else {
inputMessages.push({ role: 'user', content: input })
}
}
}

Expand Down