diff --git a/web/app/components/workflow/block-selector/index-bar.tsx b/web/app/components/workflow/block-selector/index-bar.tsx
index 3c5bf8d6e2..8d4b3de10e 100644
--- a/web/app/components/workflow/block-selector/index-bar.tsx
+++ b/web/app/components/workflow/block-selector/index-bar.tsx
@@ -6,6 +6,7 @@ import classNames from '@/utils/classnames'
export const CUSTOM_GROUP_NAME = '@@@custom@@@'
export const WORKFLOW_GROUP_NAME = '@@@workflow@@@'
+export const AGENT_GROUP_NAME = '@@@agent@@@'
/*
{
A: {
@@ -46,8 +47,10 @@ export const groupItems = (items: ToolWithProvider[], getFirstChar: (item: ToolW
groupName = item.author
else if (item.type === CollectionType.custom)
groupName = CUSTOM_GROUP_NAME
- else
+ else if (item.type === CollectionType.workflow)
groupName = WORKFLOW_GROUP_NAME
+ else
+ groupName = AGENT_GROUP_NAME
if (!acc[letter][groupName])
acc[letter][groupName] = []
diff --git a/web/app/components/workflow/block-selector/tool/tool-list-tree-view/list.tsx b/web/app/components/workflow/block-selector/tool/tool-list-tree-view/list.tsx
index 8bf5095833..a8fd34b98a 100644
--- a/web/app/components/workflow/block-selector/tool/tool-list-tree-view/list.tsx
+++ b/web/app/components/workflow/block-selector/tool/tool-list-tree-view/list.tsx
@@ -6,7 +6,7 @@ import type { BlockEnum } from '../../../types'
import type { ToolDefaultValue } from '../../types'
import Item from './item'
import { useTranslation } from 'react-i18next'
-import { CUSTOM_GROUP_NAME, WORKFLOW_GROUP_NAME } from '../../index-bar'
+import { AGENT_GROUP_NAME, CUSTOM_GROUP_NAME, WORKFLOW_GROUP_NAME } from '../../index-bar'
type Props = {
payload: Record
@@ -27,6 +27,9 @@ const ToolListTreeView: FC = ({
if (name === WORKFLOW_GROUP_NAME)
return t('workflow.tabs.workflowTool')
+ if (name === AGENT_GROUP_NAME)
+ return t('workflow.tabs.agent')
+
return name
}, [t])
diff --git a/web/app/components/workflow/block-selector/tools.tsx b/web/app/components/workflow/block-selector/tools.tsx
index 060f6dfa2c..5b5d1da20b 100644
--- a/web/app/components/workflow/block-selector/tools.tsx
+++ b/web/app/components/workflow/block-selector/tools.tsx
@@ -60,7 +60,6 @@ const Blocks = ({
Object.keys(withLetterAndGroupViewToolsData[letter]).forEach((groupName) => {
if (!result[groupName])
result[groupName] = []
-
result[groupName].push(...withLetterAndGroupViewToolsData[letter][groupName])
})
})
diff --git a/web/app/components/workflow/hooks/use-checklist.ts b/web/app/components/workflow/hooks/use-checklist.ts
index 36201ddfef..9646b0da87 100644
--- a/web/app/components/workflow/hooks/use-checklist.ts
+++ b/web/app/components/workflow/hooks/use-checklist.ts
@@ -24,6 +24,7 @@ import { useNodesExtraData } from './use-nodes-data'
import { useToastContext } from '@/app/components/base/toast'
import { CollectionType } from '@/app/components/tools/types'
import { useGetLanguage } from '@/context/i18n'
+import type { AgentNodeType } from '../nodes/agent/types'
export const useChecklist = (nodes: Node[], edges: Edge[]) => {
const { t } = useTranslation()
@@ -33,6 +34,7 @@ export const useChecklist = (nodes: Node[], edges: Edge[]) => {
const buildInTools = useStore(s => s.buildInTools)
const customTools = useStore(s => s.customTools)
const workflowTools = useStore(s => s.workflowTools)
+ const agentStrategies = useStore(s => s.agentStrategies)
const needWarningNodes = useMemo(() => {
const list = []
@@ -57,6 +59,18 @@ export const useChecklist = (nodes: Node[], edges: Edge[]) => {
toolIcon = workflowTools.find(tool => tool.id === node.data.provider_id)?.icon
}
+ if (node.data.type === BlockEnum.Agent) {
+ const data = node.data as AgentNodeType
+ const provider = agentStrategies.find(s => s.plugin_unique_identifier === data.plugin_unique_identifier)
+ const strategy = provider?.declaration.strategies.find(s => s.identity.name === data.agent_strategy_name)
+ // debugger
+ moreDataForCheckValid = {
+ provider,
+ strategy,
+ language,
+ }
+ }
+
if (node.type === CUSTOM_NODE) {
const { errorMessage } = nodesExtraData[node.data.type].checkValid(node.data, t, moreDataForCheckValid)
@@ -92,7 +106,7 @@ export const useChecklist = (nodes: Node[], edges: Edge[]) => {
}
return list
- }, [t, nodes, edges, nodesExtraData, buildInTools, customTools, workflowTools, language, isChatMode])
+ }, [nodes, edges, isChatMode, buildInTools, customTools, workflowTools, language, nodesExtraData, t, agentStrategies])
return needWarningNodes
}
diff --git a/web/app/components/workflow/hooks/use-workflow.ts b/web/app/components/workflow/hooks/use-workflow.ts
index 0f6ae59b6e..8ce31b8acf 100644
--- a/web/app/components/workflow/hooks/use-workflow.ts
+++ b/web/app/components/workflow/hooks/use-workflow.ts
@@ -58,6 +58,7 @@ import I18n from '@/context/i18n'
import { CollectionType } from '@/app/components/tools/types'
import { CUSTOM_ITERATION_START_NODE } from '@/app/components/workflow/nodes/iteration-start/constants'
import { useWorkflowConfig } from '@/service/use-workflow'
+import { fetchStrategyList } from '@/service/strategy'
export const useIsChatMode = () => {
const appDetail = useAppStore(s => s.appDetail)
@@ -459,6 +460,21 @@ export const useFetchToolsData = () => {
}
}
+export const useFetchAgentStrategy = () => {
+ const workflowStore = useWorkflowStore()
+ const handleFetchAllAgentStrategies = useCallback(async () => {
+ const agentStrategies = await fetchStrategyList()
+
+ workflowStore.setState({
+ agentStrategies: agentStrategies || [],
+ })
+ }, [workflowStore])
+
+ return {
+ handleFetchAllAgentStrategies,
+ }
+}
+
export const useWorkflowInit = () => {
const workflowStore = useWorkflowStore()
const {
@@ -466,6 +482,7 @@ export const useWorkflowInit = () => {
edges: edgesTemplate,
} = useWorkflowTemplate()
const { handleFetchAllTools } = useFetchToolsData()
+ const { handleFetchAllAgentStrategies } = useFetchAgentStrategy()
const appDetail = useAppStore(state => state.appDetail)!
const setSyncWorkflowDraftHash = useStore(s => s.setSyncWorkflowDraftHash)
const [data, setData] = useState()
@@ -545,7 +562,8 @@ export const useWorkflowInit = () => {
handleFetchAllTools('builtin')
handleFetchAllTools('custom')
handleFetchAllTools('workflow')
- }, [handleFetchPreloadData, handleFetchAllTools])
+ handleFetchAllAgentStrategies()
+ }, [handleFetchPreloadData, handleFetchAllTools, handleFetchAllAgentStrategies])
useEffect(() => {
if (data) {
diff --git a/web/app/components/workflow/nodes/_base/components/agent-strategy-selector.tsx b/web/app/components/workflow/nodes/_base/components/agent-strategy-selector.tsx
index 9a4944080b..1cf9fc23ef 100644
--- a/web/app/components/workflow/nodes/_base/components/agent-strategy-selector.tsx
+++ b/web/app/components/workflow/nodes/_base/components/agent-strategy-selector.tsx
@@ -1,5 +1,5 @@
import { PortalToFollowElem, PortalToFollowElemContent, PortalToFollowElemTrigger } from '@/app/components/base/portal-to-follow-elem'
-import { useMemo, useState } from 'react'
+import { memo, useMemo, useState } from 'react'
import type { Strategy } from './agent-strategy'
import classNames from '@/utils/classnames'
import { RiArrowDownSLine, RiArrowRightUpLine, RiErrorWarningFill } from '@remixicon/react'
@@ -38,7 +38,7 @@ const ExternalNotInstallWarn = () => {
function formatStrategy(input: StrategyPluginDetail[], getIcon: (i: string) => string): ToolWithProvider[] {
return input.map((item) => {
const res: ToolWithProvider = {
- id: item.provider,
+ id: item.plugin_unique_identifier,
author: item.declaration.identity.author,
name: item.declaration.identity.name,
description: item.declaration.identity.description as any,
@@ -69,7 +69,7 @@ export type AgentStrategySelectorProps = {
onChange: (value?: Strategy) => void,
}
-export const AgentStrategySelector = (props: AgentStrategySelectorProps) => {
+export const AgentStrategySelector = memo((props: AgentStrategySelectorProps) => {
const { value, onChange } = props
const [open, setOpen] = useState(false)
const [viewType, setViewType] = useState(ViewType.flat)
@@ -126,6 +126,7 @@ export const AgentStrategySelector = (props: AgentStrategySelectorProps) => {
agent_strategy_provider_name: tool!.provider_name,
agent_strategy_label: tool!.tool_label,
agent_output_schema: tool!.output_schema,
+ plugin_unique_identifier: tool!.provider_id,
})
setOpen(false)
}}
@@ -147,4 +148,6 @@ export const AgentStrategySelector = (props: AgentStrategySelectorProps) => {
*/}
-}
+})
+
+AgentStrategySelector.displayName = 'AgentStrategySelector'
diff --git a/web/app/components/workflow/nodes/_base/components/agent-strategy.tsx b/web/app/components/workflow/nodes/_base/components/agent-strategy.tsx
index 454c84833b..4ec46a6d61 100644
--- a/web/app/components/workflow/nodes/_base/components/agent-strategy.tsx
+++ b/web/app/components/workflow/nodes/_base/components/agent-strategy.tsx
@@ -12,16 +12,20 @@ import Slider from '@/app/components/base/slider'
import ToolSelector from '@/app/components/plugins/plugin-detail-panel/tool-selector'
import MultipleToolSelector from '@/app/components/plugins/plugin-detail-panel/multiple-tool-selector'
import Field from './field'
-import type { ComponentProps } from 'react'
-import { useDefaultModel, useLanguage } from '@/app/components/header/account-setting/model-provider-page/hooks'
+import { type ComponentProps, memo } from 'react'
+import { useDefaultModel } from '@/app/components/header/account-setting/model-provider-page/hooks'
import Editor from './prompt/editor'
import { useWorkflowStore } from '../../../store'
+import { useRenderI18nObject } from '@/hooks/use-i18n'
+import type { NodeOutPutVar } from '../../../types'
+import type { Node } from 'reactflow'
export type Strategy = {
agent_strategy_provider_name: string
agent_strategy_name: string
agent_strategy_label: string
agent_output_schema: Record