fix: agent node toolbox

This commit is contained in:
AkaraChen 2024-12-30 13:30:57 +08:00
parent 08a1f241ca
commit 2ac6f00efb
5 changed files with 17 additions and 15 deletions

View File

@ -83,7 +83,6 @@ export const AgentStrategySelector = (props: AgentStrategySelectorProps) => {
}, [query, list])
// TODO: should be replaced by real data
const isExternalInstalled = true
// TODO: 验证这玩意写对了没
const icon = list?.find(
coll => coll.tools?.find(tool => tool.name === value?.agent_strategy_name),
)?.icon as string | undefined
@ -125,9 +124,10 @@ export const AgentStrategySelector = (props: AgentStrategySelectorProps) => {
onChange({
agent_strategy_name: tool!.tool_name,
agent_strategy_provider_name: tool!.provider_name,
agent_parameters: tool!.params,
agent_strategy_label: tool!.tool_label,
agent_output_schema: tool!.output_schema,
agent_configurations: {},
agent_parameters: {},
})
setOpen(false)
}}

View File

@ -19,7 +19,8 @@ export type Strategy = {
agent_strategy_provider_name: string
agent_strategy_name: string
agent_strategy_label: string
agent_parameters?: ToolVarInputs
agent_configurations?: Record<string, any>
agent_parameters?: Record<string, ToolVarInputs>
agent_output_schema: Record<string, any>
}

View File

@ -13,7 +13,6 @@ import { FormTypeEnum } from '@/app/components/header/account-setting/model-prov
const AgentNode: FC<NodeProps<AgentNodeType>> = (props) => {
const { inputs, currentStrategy } = useConfig(props.id, props.data)
const { t } = useTranslation()
// TODO: Implement models
const models = useMemo(() => {
if (!inputs) return []
// if selected, show in node
@ -22,7 +21,7 @@ const AgentNode: FC<NodeProps<AgentNodeType>> = (props) => {
const models = currentStrategy?.parameters
.filter(param => param.type === FormTypeEnum.modelSelector)
.reduce((acc, param) => {
const item = inputs.agent_parameters?.[param.name]
const item = inputs.agent_configurations?.[param.name]
if (!item) {
if (param.required) {
acc.push({ param: param.name })
@ -41,18 +40,18 @@ const AgentNode: FC<NodeProps<AgentNodeType>> = (props) => {
currentStrategy?.parameters.forEach((param) => {
if (param.type === FormTypeEnum.toolSelector) {
const field = param.name
const value = inputs.agent_parameters?.[field]
const value = inputs.agent_configurations?.[field]
if (value) {
tools.push({
providerName: value.provider_name,
providerName: value.provider_name as any,
})
}
}
if (param.type === FormTypeEnum.multiToolSelector) {
const field = param.name
const value = inputs.agent_parameters?.[field]
const value = inputs.agent_configurations?.[field]
if (value) {
(value as any[]).forEach((item) => {
(value as unknown as any[]).forEach((item) => {
tools.push({
providerName: item.provider_name,
})
@ -61,7 +60,7 @@ const AgentNode: FC<NodeProps<AgentNodeType>> = (props) => {
}
})
return tools
}, [currentStrategy, inputs.agent_parameters])
}, [currentStrategy?.parameters, inputs.agent_configurations])
return <div className='mb-1 px-3 py-1 space-y-1'>
{inputs.agent_strategy_name
? <SettingItem

View File

@ -28,25 +28,27 @@ const AgentPanel: FC<NodePanelProps<AgentNodeType>> = (props) => {
strategy={inputs.agent_strategy_name ? {
agent_strategy_provider_name: inputs.agent_strategy_provider_name!,
agent_strategy_name: inputs.agent_strategy_name!,
agent_parameters: inputs.agent_parameters,
agent_configurations: inputs.agent_configurations,
agent_strategy_label: inputs.agent_strategy_label!,
agent_output_schema: inputs.output_schema,
agent_parameters: inputs.agent_parameters,
} : undefined}
onStrategyChange={(strategy) => {
setInputs({
...inputs,
agent_strategy_provider_name: strategy?.agent_strategy_provider_name,
agent_strategy_name: strategy?.agent_strategy_name,
agent_configurations: strategy?.agent_configurations,
agent_parameters: strategy?.agent_parameters,
agent_strategy_label: strategy?.agent_strategy_label,
output_schema: strategy!.agent_output_schema,
})
}}
formSchema={currentStrategy?.parameters?.map(strategyParamToCredientialForm) || []}
formValue={inputs.agent_parameters || {}}
formValue={inputs.agent_configurations || {}}
onFormValueChange={value => setInputs({
...inputs,
agent_parameters: value,
agent_configurations: value,
})}
/>
</Field>

View File

@ -5,7 +5,7 @@ export type AgentNodeType = CommonNodeType & {
agent_strategy_provider_name?: string
agent_strategy_name?: string
agent_strategy_label?: string
agent_parameters?: Record<string, any>
agent_configurations?: Record<string, ToolVarInputs>
agent_parameters?: Record<string, ToolVarInputs>
agent_configurations?: Record<string, any>
output_schema: Record<string, any>
}