Skip to content

Feature - Add option to start a new session with each interaction with the Chatflow tool #2633

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
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
26 changes: 22 additions & 4 deletions packages/components/nodes/tools/ChatflowTool/ChatflowTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { CallbackManagerForToolRun, Callbacks, CallbackManager, parseCallbackCon
import { StructuredTool } from '@langchain/core/tools'
import { ICommonObject, IDatabaseEntity, INode, INodeData, INodeOptionsValue, INodeParams } from '../../../src/Interface'
import { availableDependencies, defaultAllowBuiltInDep, getCredentialData, getCredentialParam } from '../../../src/utils'
import { v4 as uuidv4 } from 'uuid'

class ChatflowTool_Tools implements INode {
label: string
Expand All @@ -22,7 +23,7 @@ class ChatflowTool_Tools implements INode {
constructor() {
this.label = 'Chatflow Tool'
this.name = 'ChatflowTool'
this.version = 2.0
this.version = 3.0
this.type = 'ChatflowTool'
this.icon = 'chatflowTool.svg'
this.category = 'Tools'
Expand Down Expand Up @@ -66,6 +67,16 @@ class ChatflowTool_Tools implements INode {
optional: true,
additionalParams: true
},
{
label: 'Start new session per message',
name: 'startNewSession',
type: 'boolean',
description:
'Whether to continue the session with the Chatflow tool or start a new one with each interaction. Useful for Chatflows with memory if you want to avoid it.',
default: false,
optional: true,
additionalParams: true
},
{
label: 'Use Question from Chat',
name: 'useQuestionFromChat',
Expand Down Expand Up @@ -117,6 +128,8 @@ class ChatflowTool_Tools implements INode {
const useQuestionFromChat = nodeData.inputs?.useQuestionFromChat as boolean
const customInput = nodeData.inputs?.customInput as string

const startNewSession = nodeData.inputs?.startNewSession as boolean

const baseURL = (nodeData.inputs?.baseURL as string) || (options.baseURL as string)

const credentialData = await getCredentialData(nodeData.credential ?? '', options)
Expand All @@ -136,7 +149,7 @@ class ChatflowTool_Tools implements INode {

let name = _name || 'chatflow_tool'

return new ChatflowTool({ name, baseURL, description, chatflowid: selectedChatflowId, headers, input: toolInput })
return new ChatflowTool({ name, baseURL, description, chatflowid: selectedChatflowId, startNewSession, headers, input: toolInput })
}
}

Expand All @@ -153,6 +166,8 @@ class ChatflowTool extends StructuredTool {

chatflowid = ''

startNewSession = false

baseURL = 'http://localhost:3000'

headers = {}
Expand All @@ -166,13 +181,15 @@ class ChatflowTool extends StructuredTool {
description,
input,
chatflowid,
startNewSession,
baseURL,
headers
}: {
name: string
description: string
input: string
chatflowid: string
startNewSession: boolean
baseURL: string
headers: ICommonObject
}) {
Expand All @@ -181,6 +198,7 @@ class ChatflowTool extends StructuredTool {
this.description = description
this.input = input
this.baseURL = baseURL
this.startNewSession = startNewSession
this.headers = headers
this.chatflowid = chatflowid
}
Expand Down Expand Up @@ -240,9 +258,9 @@ class ChatflowTool extends StructuredTool {

const body = {
question: inputQuestion,
chatId: flowConfig?.chatId,
chatId: this.startNewSession ? uuidv4() : flowConfig?.chatId,
overrideConfig: {
sessionId: flowConfig?.sessionId
sessionId: this.startNewSession ? uuidv4() : flowConfig?.sessionId
}
}

Expand Down
Loading