Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

fix(agent): prefill block test inputs from settings (#21566)

Sbaaoui Idriss5966db46ab4a
diff --git a/web/src/hooks/use-agent-request.ts b/web/src/hooks/use-agent-request.ts
index 285f832647..036f32be31 100644
--- a/web/src/hooks/use-agent-request.ts
+++ b/web/src/hooks/use-agent-request.ts
@@ -137,6 +137,8 @@ export const AgentKeys = {
: ([AgentApiAction.FetchAgentTags, canvasCategory] as const),
detail: (agentId?: string) =>
[AgentApiAction.FetchAgentDetail, agentId] as const,
+ inputForm: (agentId?: string, componentId?: string) =>
+ [AgentApiAction.FetchInputForm, agentId, componentId] as const,
versionList: (agentId?: string) =>
[AgentApiAction.FetchVersionList, agentId] as const,
version: (agentId?: string, versionId?: string) =>
@@ -757,7 +759,7 @@ export const useFetchInputForm = (componentId?: string) => {
const { id } = useParams();
const { data } = useQuery<Record<string, any>>({
- queryKey: [AgentApiAction.FetchInputForm],
+ queryKey: AgentKeys.inputForm(id, componentId),
initialData: {},
enabled: !!id && !!componentId,
queryFn: async () => {
diff --git a/web/src/pages/agent/debug-content/index.tsx b/web/src/pages/agent/debug-content/index.tsx
index 838447c375..d241e75b9a 100644
--- a/web/src/pages/agent/debug-content/index.tsx
+++ b/web/src/pages/agent/debug-content/index.tsx
@@ -32,6 +32,7 @@ const StringFields = [
interface IProps {
parameters: BeginQuery[];
+ initialValues?: Record<string, unknown>;
message?: IMessage;
ok(parameters: any[]): void;
isNext?: boolean;
@@ -44,6 +45,7 @@ interface IProps {
const DebugContent = ({
parameters,
+ initialValues,
message,
ok,
isNext = true,
@@ -102,6 +104,15 @@ const DebugContent = ({
const form = useForm<z.infer<typeof formSchemaValues.schema>>({
defaultValues: formSchemaValues.values,
+ values: initialValues
+ ? Object.fromEntries(
+ Object.entries(formSchemaValues.values).map(([key, value]) => [
+ key,
+ initialValues[key] ?? value,
+ ]),
+ )
+ : undefined,
+ resetOptions: { keepDirtyValues: true },
resolver: zodResolver(formSchemaValues.schema),
});
diff --git a/web/src/pages/agent/form-sheet/single-debug-sheet/index.tsx b/web/src/pages/agent/form-sheet/single-debug-sheet/index.tsx
index a105d6137d..7724ac8988 100644
--- a/web/src/pages/agent/form-sheet/single-debug-sheet/index.tsx
+++ b/web/src/pages/agent/form-sheet/single-debug-sheet/index.tsx
@@ -12,13 +12,13 @@ import JsonView from 'react18-json-view';
import 'react18-json-view/src/style.css';
import DebugContent from '../../debug-content';
import { transferInputsArrayToObject } from '../../form/begin-form/use-watch-change';
-import { buildBeginInputListFromObject } from '../../form/begin-form/utils';
import {
deserializeCodeOutputContract,
getBusinessOutputs,
} from '../../form/code-form/utils';
import useGraphStore from '../../store';
import {
+ buildDebugInputList,
groupCodeExecDebugOutput,
shouldUseCodeExecDebugLayout,
} from './utils';
@@ -97,8 +97,12 @@ const SingleDebugSheet = ({
);
const list = useMemo(() => {
- return buildBeginInputListFromObject(inputForm);
- }, [inputForm]);
+ return buildDebugInputList(inputForm, node?.data.form);
+ }, [inputForm, node?.data.form]);
+ const initialValues = useMemo(
+ () => Object.fromEntries(list.map((input, index) => [index, input.value])),
+ [list],
+ );
const onOk = useCallback(
(nextValues: any[]) => {
@@ -162,7 +166,9 @@ const SingleDebugSheet = ({
</SheetHeader>
<section className="overflow-y-auto px-5 pt-4">
<DebugContent
+ key={componentId}
parameters={list}
+ initialValues={initialValues}
ok={onOk}
isNext={false}
loading={loading}
diff --git a/web/src/pages/agent/form-sheet/single-debug-sheet/utils.ts b/web/src/pages/agent/form-sheet/single-debug-sheet/utils.ts
index e01b898f78..7f3fce3c86 100644
--- a/web/src/pages/agent/form-sheet/single-debug-sheet/utils.ts
+++ b/web/src/pages/agent/form-sheet/single-debug-sheet/utils.ts
@@ -1,6 +1,25 @@
-import { Operator } from '../../constant';
+import { Operator, VariableRegex } from '../../constant';
+import { buildBeginInputListFromObject } from '../../form/begin-form/utils';
import { CodeOutputContract } from '../../form/code-form/utils';
+export function buildDebugInputList(
+ inputForm: Record<string, any>,
+ configuredValues: Record<string, any> = {},
+) {
+ return buildBeginInputListFromObject(inputForm).map((input) => {
+ const value = configuredValues[input.key] ?? input.value;
+ // A single-block test needs concrete runtime inputs, not unresolved templates.
+ const unresolved =
+ typeof value === 'string' &&
+ (value.match(VariableRegex) !== null ||
+ value.includes('{%') ||
+ /^(?:begin@\S+|[A-Za-z][A-Za-z0-9_]*:[A-Za-z0-9][A-Za-z0-9_-]*@\S+|(?:sys|env)\.\S+)$/.test(
+ value,
+ ));
+ return { ...input, value: unresolved ? undefined : value };
+ });
+}
+
const SYSTEM_OUTPUT_NAMES = new Set([
'_ERROR',
'_ARTIFACTS',