feat: agent node add memory (#15976)

This commit is contained in:
Novice
2025-04-03 16:40:58 +08:00
committed by GitHub
parent 3d76f09c3a
commit dcdec98c8e
7 changed files with 116 additions and 20 deletions

View File

@@ -1,7 +1,7 @@
import type { FC } from 'react'
import { memo, useMemo } from 'react'
import type { NodePanelProps } from '../../types'
import type { AgentNodeType } from './types'
import { AgentFeature, type AgentNodeType } from './types'
import Field from '../_base/components/field'
import { AgentStrategy } from '../_base/components/agent-strategy'
import useConfig from './use-config'
@@ -16,6 +16,8 @@ import { useLogs } from '@/app/components/workflow/run/hooks'
import type { Props as FormProps } from '@/app/components/workflow/nodes/_base/components/before-run-form/form'
import { toType } from '@/app/components/tools/utils/to-form-schema'
import { useStore } from '../../store'
import Split from '../_base/components/split'
import MemoryConfig from '../_base/components/memory-config'
const i18nPrefix = 'workflow.nodes.agent'
@@ -35,10 +37,10 @@ const AgentPanel: FC<NodePanelProps<AgentNodeType>> = (props) => {
currentStrategy,
formData,
onFormChange,
isChatMode,
availableNodesWithParent,
availableVars,
readOnly,
isShowSingleRun,
hideSingleRun,
runningStatus,
@@ -49,6 +51,7 @@ const AgentPanel: FC<NodePanelProps<AgentNodeType>> = (props) => {
setRunInputData,
varInputs,
outputSchema,
handleMemoryChange,
} = useConfig(props.id, props.data)
const { t } = useTranslation()
const nodeInfo = useMemo(() => {
@@ -106,6 +109,20 @@ const AgentPanel: FC<NodePanelProps<AgentNodeType>> = (props) => {
nodeId={props.id}
/>
</Field>
<div className='px-4 py-2'>
{isChatMode && currentStrategy?.features.includes(AgentFeature.HISTORY_MESSAGES) && (
<>
<Split />
<MemoryConfig
className='mt-4'
readonly={readOnly}
config={{ data: inputs.memory }}
onChange={handleMemoryChange}
canSetRoleName={false}
/>
</>
)}
</div>
<div>
<OutputVars>
<VarItem

View File

@@ -1,4 +1,4 @@
import type { CommonNodeType } from '@/app/components/workflow/types'
import type { CommonNodeType, Memory } from '@/app/components/workflow/types'
import type { ToolVarInputs } from '../tool/types'
export type AgentNodeType = CommonNodeType & {
@@ -8,4 +8,9 @@ export type AgentNodeType = CommonNodeType & {
agent_parameters?: ToolVarInputs
output_schema: Record<string, any>
plugin_unique_identifier?: string
memory?: Memory
}
export enum AgentFeature {
HISTORY_MESSAGES = 'history-messages',
}

View File

@@ -4,14 +4,16 @@ import useVarList from '../_base/hooks/use-var-list'
import useOneStepRun from '../_base/hooks/use-one-step-run'
import type { AgentNodeType } from './types'
import {
useIsChatMode,
useNodesReadOnly,
} from '@/app/components/workflow/hooks'
import { useCallback, useMemo } from 'react'
import { type ToolVarInputs, VarType } from '../tool/types'
import { useCheckInstalled, useFetchPluginsInMarketPlaceByIds } from '@/service/use-plugins'
import type { Var } from '../../types'
import type { Memory, Var } from '../../types'
import { VarType as VarKindType } from '../../types'
import useAvailableVarList from '../_base/hooks/use-available-var-list'
import produce from 'immer'
export type StrategyStatus = {
plugin: {
@@ -175,6 +177,13 @@ const useConfig = (id: string, payload: AgentNodeType) => {
return res
}, [inputs.output_schema])
const handleMemoryChange = useCallback((newMemory?: Memory) => {
const newInputs = produce(inputs, (draft) => {
draft.memory = newMemory
})
setInputs(newInputs)
}, [inputs, setInputs])
const isChatMode = useIsChatMode()
return {
readOnly,
inputs,
@@ -202,6 +211,8 @@ const useConfig = (id: string, payload: AgentNodeType) => {
runResult,
varInputs,
outputSchema,
handleMemoryChange,
isChatMode,
}
}