Fix ai agent node prompt and variables (#18275)

- prompt stored on workflow lvl so input variables can be resolved and
it can evolves with versions
- make ai agent node output available as variables
This commit is contained in:
Thomas Trompette
2026-02-26 17:17:48 +01:00
committed by GitHub
parent 81698ff32c
commit def5ea5764
6 changed files with 69 additions and 84 deletions
@@ -13,6 +13,7 @@ import { SettingsAgentModelCapabilities } from '~/pages/settings/ai/components/S
import { SettingsAgentResponseFormat } from '~/pages/settings/ai/components/SettingsAgentResponseFormat';
type WorkflowAiAgentPromptTabProps = {
prompt: string;
readonly: boolean;
aiModelOptions: SelectOption[];
onPromptChange: (value: string) => void;
@@ -25,6 +26,7 @@ type WorkflowAiAgentPromptTabProps = {
};
export const WorkflowAiAgentPromptTab = ({
prompt,
readonly,
aiModelOptions,
onPromptChange,
@@ -42,7 +44,7 @@ export const WorkflowAiAgentPromptTab = ({
VariablePicker={WorkflowVariablePicker}
label={t`Instructions for AI`}
placeholder={t`Describe what you want the AI to do...`}
defaultValue={workflowAiAgentActionAgent?.prompt || ''}
defaultValue={prompt}
onChange={onPromptChange}
readonly={readonly}
/>
@@ -4,19 +4,21 @@ import { TabList } from '@/ui/layout/tab-list/components/TabList';
import { activeTabIdComponentState } from '@/ui/layout/tab-list/states/activeTabIdComponentState';
import { type SingleTabProps } from '@/ui/layout/tab-list/types/SingleTabProps';
import { useAtomComponentStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomComponentStateValue';
import { useAtomState } from '@/ui/utilities/state/jotai/hooks/useAtomState';
import { useFlowOrThrow } from '@/workflow/hooks/useFlowOrThrow';
import { type WorkflowAiAgentAction } from '@/workflow/types/Workflow';
import { WorkflowStepBody } from '@/workflow/workflow-steps/components/WorkflowStepBody';
import { WorkflowStepFooter } from '@/workflow/workflow-steps/components/WorkflowStepFooter';
import { useUpdateWorkflowVersionStep } from '@/workflow/workflow-steps/hooks/useUpdateWorkflowVersionStep';
import { WorkflowAiAgentPermissionsTab } from '@/workflow/workflow-steps/workflow-actions/ai-agent-action/components/WorkflowAiAgentPermissionsTab';
import { WORKFLOW_AI_AGENT_TAB_LIST_COMPONENT_ID } from '@/workflow/workflow-steps/workflow-actions/ai-agent-action/constants/WorkflowAiAgentTabListComponentId';
import { WORKFLOW_AI_AGENT_TABS } from '@/workflow/workflow-steps/workflow-actions/ai-agent-action/constants/WorkflowAiAgentTabs';
import { useResetWorkflowAiAgentPermissionsStateOnCommandMenuClose } from '@/workflow/workflow-steps/workflow-actions/ai-agent-action/hooks/useResetWorkflowAiAgentPermissionsStateOnCommandMenuClose';
import { useAtomState } from '@/ui/utilities/state/jotai/hooks/useAtomState';
import { workflowAiAgentActionAgentState } from '@/workflow/workflow-steps/workflow-actions/ai-agent-action/states/workflowAiAgentActionAgentState';
import { workflowAiAgentPermissionsIsAddingPermissionState } from '@/workflow/workflow-steps/workflow-actions/ai-agent-action/states/workflowAiAgentPermissionsIsAddingPermissionState';
import styled from '@emotion/styled';
import { useLingui } from '@lingui/react/macro';
import { useState } from 'react';
import {
type AgentResponseSchema,
type ModelConfiguration,
@@ -32,7 +34,6 @@ import {
} from '~/generated-metadata/graphql';
import { useNavigateSettings } from '~/hooks/useNavigateSettings';
import { RightDrawerSkeletonLoader } from '~/loading/components/RightDrawerSkeletonLoader';
import { WORKFLOW_AI_AGENT_TAB_LIST_COMPONENT_ID } from '@/workflow/workflow-steps/workflow-actions/ai-agent-action/constants/WorkflowAiAgentTabListComponentId';
import { WorkflowAiAgentPromptTab } from './WorkflowAiAgentPromptTab';
export type WorkflowAiAgentTabId =
@@ -82,31 +83,30 @@ export const WorkflowEditActionAiAgent = ({
const { updateWorkflowVersionStep } = useUpdateWorkflowVersionStep();
const flow = useFlowOrThrow();
const handleAgentPromptChange = useDebouncedCallback(
async (newPrompt: string) => {
if (
actionOptions.readonly === true ||
!isDefined(workflowAiAgentActionAgent)
) {
return;
}
const actionPrompt = action.settings.input.prompt || '';
const [prompt, setPrompt] = useState(actionPrompt);
const response = await updateAgent({
variables: {
input: {
id: workflowAiAgentActionAgent.id,
prompt: newPrompt,
},
const savePrompt = useDebouncedCallback((newPrompt: string) => {
if (actionOptions.readonly === true) {
return;
}
actionOptions.onActionUpdate({
...action,
settings: {
...action.settings,
input: {
...action.settings.input,
prompt: newPrompt,
},
});
},
});
}, 500);
setWorkflowAiAgentActionAgent({
...workflowAiAgentActionAgent,
...response.data?.updateOneAgent,
});
},
500,
);
const handleAgentPromptChange = (newPrompt: string) => {
setPrompt(newPrompt);
savePrompt(newPrompt);
};
const handleAgentModelChange = async (modelId: string) => {
if (
@@ -291,6 +291,7 @@ export const WorkflowEditActionAiAgent = ({
) : (
<WorkflowStepBody>
<WorkflowAiAgentPromptTab
prompt={prompt}
readonly={actionOptions.readonly === true}
aiModelOptions={aiModelOptions}
onPromptChange={handleAgentPromptChange}