mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-28 21:00:58 +03:00
feat: Add conversation history selection options to ConditionAgent node (#3719)
* feat: Enhance ConditionAgent with conversation history selection options - Added a new parameter `conversationHistorySelection` to allow users to choose which messages from the conversation history to include in prompts. - Options include: User Question, Last Conversation Message, All Conversation Messages, and Empty. - Default selection is set to 'All Conversation Messages' for improved context management in sequential LLM and Agent nodes. * Bump version from 2.0 to 3.0
This commit is contained in:
@@ -6,6 +6,7 @@ import { RunnableSequence, RunnablePassthrough, RunnableConfig } from '@langchai
|
|||||||
import { BaseMessage } from '@langchain/core/messages'
|
import { BaseMessage } from '@langchain/core/messages'
|
||||||
import { BaseChatModel } from '@langchain/core/language_models/chat_models'
|
import { BaseChatModel } from '@langchain/core/language_models/chat_models'
|
||||||
import {
|
import {
|
||||||
|
ConversationHistorySelection,
|
||||||
ICommonObject,
|
ICommonObject,
|
||||||
IDatabaseEntity,
|
IDatabaseEntity,
|
||||||
INode,
|
INode,
|
||||||
@@ -23,6 +24,7 @@ import {
|
|||||||
customGet,
|
customGet,
|
||||||
getVM,
|
getVM,
|
||||||
transformObjectPropertyToFunction,
|
transformObjectPropertyToFunction,
|
||||||
|
filterConversationHistory,
|
||||||
restructureMessages
|
restructureMessages
|
||||||
} from '../commonUtils'
|
} from '../commonUtils'
|
||||||
import { ChatGoogleGenerativeAI } from '../../chatmodels/ChatGoogleGenerativeAI/FlowiseChatGoogleGenerativeAI'
|
import { ChatGoogleGenerativeAI } from '../../chatmodels/ChatGoogleGenerativeAI/FlowiseChatGoogleGenerativeAI'
|
||||||
@@ -149,7 +151,7 @@ class ConditionAgent_SeqAgents implements INode {
|
|||||||
constructor() {
|
constructor() {
|
||||||
this.label = 'Condition Agent'
|
this.label = 'Condition Agent'
|
||||||
this.name = 'seqConditionAgent'
|
this.name = 'seqConditionAgent'
|
||||||
this.version = 2.0
|
this.version = 3.0
|
||||||
this.type = 'ConditionAgent'
|
this.type = 'ConditionAgent'
|
||||||
this.icon = 'condition.svg'
|
this.icon = 'condition.svg'
|
||||||
this.category = 'Sequential Agents'
|
this.category = 'Sequential Agents'
|
||||||
@@ -185,6 +187,42 @@ class ConditionAgent_SeqAgents implements INode {
|
|||||||
additionalParams: true,
|
additionalParams: true,
|
||||||
optional: true
|
optional: true
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: 'Conversation History',
|
||||||
|
name: 'conversationHistorySelection',
|
||||||
|
type: 'options',
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
label: 'User Question',
|
||||||
|
name: 'user_question',
|
||||||
|
description: 'Use the user question from the historical conversation messages as input.'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Last Conversation Message',
|
||||||
|
name: 'last_message',
|
||||||
|
description: 'Use the last conversation message from the historical conversation messages as input.'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'All Conversation Messages',
|
||||||
|
name: 'all_messages',
|
||||||
|
description: 'Use all conversation messages from the historical conversation messages as input.'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Empty',
|
||||||
|
name: 'empty',
|
||||||
|
description:
|
||||||
|
'Do not use any messages from the conversation history. ' +
|
||||||
|
'Ensure to use either System Prompt, Human Prompt, or Messages History.'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
default: 'all_messages',
|
||||||
|
optional: true,
|
||||||
|
description:
|
||||||
|
'Select which messages from the conversation history to include in the prompt. ' +
|
||||||
|
'The selected messages will be inserted between the System Prompt (if defined) and ' +
|
||||||
|
'Human Prompt.',
|
||||||
|
additionalParams: true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
label: 'Human Prompt',
|
label: 'Human Prompt',
|
||||||
name: 'humanMessagePrompt',
|
name: 'humanMessagePrompt',
|
||||||
@@ -481,6 +519,9 @@ const runCondition = async (
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const historySelection = (nodeData.inputs?.conversationHistorySelection || 'all_messages') as ConversationHistorySelection
|
||||||
|
// @ts-ignore
|
||||||
|
state.messages = filterConversationHistory(historySelection, input, state)
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
state.messages = restructureMessages(model, state)
|
state.messages = restructureMessages(model, state)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user