mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-22 09:01:09 +03:00
Feature/Add message history to agents (#3031)
add message history to agents
This commit is contained in:
@@ -25,7 +25,8 @@ import {
|
||||
getVM,
|
||||
processImageMessage,
|
||||
transformObjectPropertyToFunction,
|
||||
restructureMessages
|
||||
restructureMessages,
|
||||
checkMessageHistory
|
||||
} from '../commonUtils'
|
||||
import { ChatGoogleGenerativeAI } from '../../chatmodels/ChatGoogleGenerativeAI/FlowiseChatGoogleGenerativeAI'
|
||||
|
||||
@@ -130,6 +131,31 @@ return {
|
||||
aggregate: [result.content]
|
||||
};`
|
||||
|
||||
const messageHistoryExample = `const { AIMessage, HumanMessage, ToolMessage } = require('@langchain/core/messages');
|
||||
|
||||
return [
|
||||
new HumanMessage("What is 333382 🦜 1932?"),
|
||||
new AIMessage({
|
||||
content: "",
|
||||
tool_calls: [
|
||||
{
|
||||
id: "12345",
|
||||
name: "calulator",
|
||||
args: {
|
||||
number1: 333382,
|
||||
number2: 1932,
|
||||
operation: "divide",
|
||||
},
|
||||
},
|
||||
],
|
||||
}),
|
||||
new ToolMessage({
|
||||
tool_call_id: "12345",
|
||||
content: "The answer is 172.558.",
|
||||
}),
|
||||
new AIMessage("The answer is 172.558."),
|
||||
]`
|
||||
|
||||
class LLMNode_SeqAgents implements INode {
|
||||
label: string
|
||||
name: string
|
||||
@@ -147,7 +173,7 @@ class LLMNode_SeqAgents implements INode {
|
||||
constructor() {
|
||||
this.label = 'LLM Node'
|
||||
this.name = 'seqLLMNode'
|
||||
this.version = 2.0
|
||||
this.version = 3.0
|
||||
this.type = 'LLMNode'
|
||||
this.icon = 'llmNode.svg'
|
||||
this.category = 'Sequential Agents'
|
||||
@@ -178,6 +204,17 @@ class LLMNode_SeqAgents implements INode {
|
||||
optional: true,
|
||||
additionalParams: true
|
||||
},
|
||||
{
|
||||
label: 'Messages History',
|
||||
name: 'messageHistory',
|
||||
description:
|
||||
'Return a list of messages between System Prompt and Human Prompt. This is useful when you want to provide few shot examples',
|
||||
type: 'code',
|
||||
hideCodeExecute: true,
|
||||
codeExample: messageHistoryExample,
|
||||
optional: true,
|
||||
additionalParams: true
|
||||
},
|
||||
{
|
||||
label: 'Start | Agent | Condition | LLM | Tool Node',
|
||||
name: 'sequentialNode',
|
||||
@@ -355,6 +392,8 @@ class LLMNode_SeqAgents implements INode {
|
||||
state,
|
||||
llm,
|
||||
agent: await createAgent(
|
||||
nodeData,
|
||||
options,
|
||||
llmNodeName,
|
||||
state,
|
||||
bindModel || llm,
|
||||
@@ -394,6 +433,8 @@ class LLMNode_SeqAgents implements INode {
|
||||
}
|
||||
|
||||
async function createAgent(
|
||||
nodeData: INodeData,
|
||||
options: ICommonObject,
|
||||
llmNodeName: string,
|
||||
state: ISeqAgentsState,
|
||||
llm: BaseChatModel,
|
||||
@@ -438,7 +479,9 @@ async function createAgent(
|
||||
if (systemPrompt) promptArrays.unshift(['system', systemPrompt])
|
||||
if (humanPrompt) promptArrays.push(['human', humanPrompt])
|
||||
|
||||
const prompt = ChatPromptTemplate.fromMessages(promptArrays)
|
||||
let prompt = ChatPromptTemplate.fromMessages(promptArrays)
|
||||
prompt = await checkMessageHistory(nodeData, options, prompt, promptArrays, systemPrompt)
|
||||
|
||||
if (multiModalMessageContent.length) {
|
||||
const msg = HumanMessagePromptTemplate.fromTemplate([...multiModalMessageContent])
|
||||
prompt.promptMessages.splice(1, 0, msg)
|
||||
|
||||
Reference in New Issue
Block a user