diff --git a/packages/components/nodes/agents/ConversationalRetrievalAgent/ConversationalRetrievalAgent.ts b/packages/components/nodes/agents/ConversationalRetrievalAgent/ConversationalRetrievalAgent.ts index 01215fc2..ed39fbc8 100644 --- a/packages/components/nodes/agents/ConversationalRetrievalAgent/ConversationalRetrievalAgent.ts +++ b/packages/components/nodes/agents/ConversationalRetrievalAgent/ConversationalRetrievalAgent.ts @@ -76,12 +76,10 @@ class ConversationalRetrievalAgent_Agents implements INode { async run(nodeData: INodeData, input: string, options: ICommonObject): Promise { const executor = nodeData.instance as AgentExecutor - if (options && options.chatHistory) { - if (executor.memory) { - ;(executor.memory as any).memoryKey = 'chat_history' - ;(executor.memory as any).outputKey = 'output' - ;(executor.memory as any).chatHistory = mapChatHistory(options) - } + if (executor.memory) { + ;(executor.memory as any).memoryKey = 'chat_history' + ;(executor.memory as any).outputKey = 'output' + ;(executor.memory as any).chatHistory = mapChatHistory(options) } const loggerHandler = new ConsoleCallbackHandler(options.logger) diff --git a/packages/components/src/utils.ts b/packages/components/src/utils.ts index 2f4e7f5b..bcca834a 100644 --- a/packages/components/src/utils.ts +++ b/packages/components/src/utils.ts @@ -509,7 +509,7 @@ export const getUserHome = (): string => { */ export const mapChatHistory = (options: ICommonObject): ChatMessageHistory => { const chatHistory = [] - const histories: IMessage[] = options.chatHistory + const histories: IMessage[] = options.chatHistory ?? [] for (const message of histories) { if (message.type === 'apiMessage') {