Skip to content

Commit cfdcceb

Browse files
authored
Feat: Fixed an issue where modifying fields in the agent operator caused the loss of structured data. #10427 (#11388)
### What problem does this PR solve? Feat: Fixed an issue where modifying fields in the agent operator caused the loss of structured data. #10427 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
1 parent 980a883 commit cfdcceb

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

web/src/locales/en.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1855,7 +1855,7 @@ Important structured information may include: names, dates, locations, events, k
18551855
desc: 'Descending',
18561856
},
18571857
variableAssignerLogicalOperatorOptions: {
1858-
overwrite: 'Overwrite',
1858+
overwrite: 'Overwritten By',
18591859
clear: 'Clear',
18601860
set: 'Set',
18611861
'+=': 'Add',

web/src/pages/agent/form/agent-form/index.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@ import { Switch } from '@/components/ui/switch';
2222
import { LlmModelType } from '@/constants/knowledge';
2323
import { useFindLlmByUuid } from '@/hooks/use-llm-request';
2424
import { zodResolver } from '@hookform/resolvers/zod';
25-
import { memo, useEffect, useMemo } from 'react';
25+
import { memo, useCallback, useEffect, useMemo } from 'react';
2626
import { useForm, useWatch } from 'react-hook-form';
2727
import { useTranslation } from 'react-i18next';
2828
import { z } from 'zod';
2929
import {
3030
AgentExceptionMethod,
31+
AgentStructuredOutputField,
3132
NodeHandleId,
3233
VariableType,
3334
} from '../../constant';
@@ -127,6 +128,17 @@ function AgentForm({ node }: INextOperatorForm) {
127128
handleStructuredOutputDialogOk,
128129
} = useShowStructuredOutputDialog(node?.id);
129130

131+
const updateNodeForm = useGraphStore((state) => state.updateNodeForm);
132+
133+
const handleShowStructuredOutput = useCallback(
134+
(val: boolean) => {
135+
if (node?.id && val) {
136+
updateNodeForm(node?.id, {}, ['outputs', AgentStructuredOutputField]);
137+
}
138+
},
139+
[node?.id, updateNodeForm],
140+
);
141+
130142
useEffect(() => {
131143
if (exceptionMethod !== AgentExceptionMethod.Goto) {
132144
if (node?.id) {
@@ -293,7 +305,10 @@ function AgentForm({ node }: INextOperatorForm) {
293305
<Switch
294306
id="airplane-mode"
295307
checked={field.value}
296-
onCheckedChange={field.onChange}
308+
onCheckedChange={(val) => {
309+
handleShowStructuredOutput(val);
310+
field.onChange(val);
311+
}}
297312
/>
298313
</div>
299314
)}

web/src/pages/agent/form/agent-form/use-watch-change.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,13 @@ export function useWatchFormChange(id?: string, form?: UseFormReturn<any>) {
1717
prompts: [{ role: PromptRole.User, content: values.prompts }],
1818
};
1919

20-
if (values.showStructuredOutput) {
21-
nextValues = {
22-
...nextValues,
23-
outputs: {
24-
...values.outputs,
25-
[AgentStructuredOutputField]:
26-
values[AgentStructuredOutputField] ?? {},
27-
},
28-
};
29-
} else {
20+
if (!values.showStructuredOutput) {
3021
nextValues = {
3122
...nextValues,
3223
outputs: omit(values.outputs, [AgentStructuredOutputField]),
3324
};
25+
} else {
26+
nextValues = omit(nextValues, 'outputs');
3427
}
3528
updateNodeForm(id, nextValues);
3629
}

0 commit comments

Comments
 (0)