Files
Flowise/packages/components/nodes/agentflow/Start/Start.ts
T
Henry Heng 7924fbce0d Feature/agentflow v2 (#4298)
* agent flow v2

* chat message background

* conditon agent flow

* add sticky note

* update human input dynamic prompt

* add HTTP node

* add default tool icon

* fix export duplicate agentflow v2

* add agentflow v2 marketplaces

* refractor memoization, add iteration nodes

* add agentflow v2 templates

* add agentflow generator

* add migration scripts for mysql, mariadb, posrgres and fix date filters for executions

* update agentflow chat history config

* fix get all flows error after deletion and rename

* add previous nodes from parent node

* update generator prompt

* update run time state when using iteration nodes

* prevent looping connection, prevent duplication of start node, add executeflow node, add nodes agentflow, chat history variable

* update embed

* convert form input to string

* bump openai version

* add react rewards

* add prompt generator to prediction queue

* add array schema to overrideconfig

* UI touchup

* update embedded chat version

* fix node info dialog

* update start node and loop default iteration

* update UI fixes for agentflow v2

* fix async drop down

* add export import to agentflowsv2, executions, fix UI bugs

* add default empty object to flowlisttable

* add ability to share trace link publicly, allow MCP tool use for Agent and Assistant

* add runtime message length to variable, display conditions on UI

* fix array validation

* add ability to add knowledge from vector store and embeddings for agent

* add agent tool require human input

* add ephemeral memory to start node

* update agent flow node to show vs and embeddings icons

* feat: add import chat data functionality for AgentFlowV2

* feat: set chatMessage.executionId to null if not found in import JSON file or database

* fix: MariaDB execution migration script to utf8mb4_unicode_520_ci

---------

Co-authored-by: Ong Chung Yau <33013947+chungyau97@users.noreply.github.com>
Co-authored-by: chungyau97 <chungyau97@gmail.com>
2025-05-10 10:21:26 +08:00

218 lines
7.1 KiB
TypeScript

import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface'
class Start_Agentflow implements INode {
label: string
name: string
version: number
description: string
type: string
icon: string
category: string
color: string
hideInput: boolean
baseClasses: string[]
documentation?: string
credential: INodeParams
inputs: INodeParams[]
constructor() {
this.label = 'Start'
this.name = 'startAgentflow'
this.version = 1.0
this.type = 'Start'
this.category = 'Agent Flows'
this.description = 'Starting point of the agentflow'
this.baseClasses = [this.type]
this.color = '#7EE787'
this.hideInput = true
this.inputs = [
{
label: 'Input Type',
name: 'startInputType',
type: 'options',
options: [
{
label: 'Chat Input',
name: 'chatInput',
description: 'Start the conversation with chat input'
},
{
label: 'Form Input',
name: 'formInput',
description: 'Start the workflow with form inputs'
}
],
default: 'chatInput'
},
{
label: 'Form Title',
name: 'formTitle',
type: 'string',
placeholder: 'Please Fill Out The Form',
show: {
startInputType: 'formInput'
}
},
{
label: 'Form Description',
name: 'formDescription',
type: 'string',
placeholder: 'Complete all fields below to continue',
show: {
startInputType: 'formInput'
}
},
{
label: 'Form Input Types',
name: 'formInputTypes',
description: 'Specify the type of form input',
type: 'array',
show: {
startInputType: 'formInput'
},
array: [
{
label: 'Type',
name: 'type',
type: 'options',
options: [
{
label: 'String',
name: 'string'
},
{
label: 'Number',
name: 'number'
},
{
label: 'Boolean',
name: 'boolean'
},
{
label: 'Options',
name: 'options'
}
],
default: 'string'
},
{
label: 'Label',
name: 'label',
type: 'string',
placeholder: 'Label for the input'
},
{
label: 'Variable Name',
name: 'name',
type: 'string',
placeholder: 'Variable name for the input (must be camel case)',
description: 'Variable name must be camel case. For example: firstName, lastName, etc.'
},
{
label: 'Add Options',
name: 'addOptions',
type: 'array',
show: {
'formInputTypes[$index].type': 'options'
},
array: [
{
label: 'Option',
name: 'option',
type: 'string'
}
]
}
]
},
{
label: 'Ephemeral Memory',
name: 'startEphemeralMemory',
type: 'boolean',
description: 'Start fresh for every execution without past chat history',
optional: true
},
{
label: 'Flow State',
name: 'startState',
description: 'Runtime state during the execution of the workflow',
type: 'array',
optional: true,
array: [
{
label: 'Key',
name: 'key',
type: 'string',
placeholder: 'Foo'
},
{
label: 'Value',
name: 'value',
type: 'string',
placeholder: 'Bar',
optional: true
}
]
}
]
}
async run(nodeData: INodeData, input: string | Record<string, any>, options: ICommonObject): Promise<any> {
const _flowState = nodeData.inputs?.startState as string
const startInputType = nodeData.inputs?.startInputType as string
const startEphemeralMemory = nodeData.inputs?.startEphemeralMemory as boolean
let flowStateArray = []
if (_flowState) {
try {
flowStateArray = typeof _flowState === 'string' ? JSON.parse(_flowState) : _flowState
} catch (error) {
throw new Error('Invalid Flow State')
}
}
let flowState: Record<string, any> = {}
for (const state of flowStateArray) {
flowState[state.key] = state.value
}
const inputData: ICommonObject = {}
const outputData: ICommonObject = {}
if (startInputType === 'chatInput') {
inputData.question = input
outputData.question = input
}
if (startInputType === 'formInput') {
inputData.form = {
title: nodeData.inputs?.formTitle,
description: nodeData.inputs?.formDescription,
inputs: nodeData.inputs?.formInputTypes
}
let form = input
if (options.agentflowRuntime?.form && Object.keys(options.agentflowRuntime.form).length) {
form = options.agentflowRuntime.form
}
outputData.form = form
}
if (startEphemeralMemory) {
outputData.ephemeralMemory = true
}
const returnOutput = {
id: nodeData.id,
name: this.name,
input: inputData,
output: outputData,
state: flowState
}
return returnOutput
}
}
module.exports = { nodeClass: Start_Agentflow }