Skip to content

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

refactor(components): remove the empty Answer stub (#20454)

Sbaaoui Idriss267f5898b5da
diff --git a/internal/agent/canvas/compile_test.go b/internal/agent/canvas/compile_test.go
index 7527c13e9a..7adc4ba385 100644
--- a/internal/agent/canvas/compile_test.go
+++ b/internal/agent/canvas/compile_test.go
@@ -194,26 +194,23 @@ func TestCompile_RejectsUserFillUpInResumeMode(t *testing.T) {
}
// TestCompile_PropagatesCheckPointID verifies Compile stores the stable id
-// on the returned CompiledCanvas. The assertion only fires when the canvas
-// actually compiles end-to-end in this environment (component factories /
-// DB may be unavailable in unit scope) — matching the repo convention in
-// the other Compile tests that ignore compile errors. The option-side
-// contract is independently covered by TestWithCheckPointID_OptionSetsField.
+// on the returned CompiledCanvas. Compilation constructs components but does
+// not invoke them, so this test requires the canvas to compile successfully.
func TestCompile_PropagatesCheckPointID(t *testing.T) {
c := &Canvas{
Components: map[string]CanvasComponent{
"begin": {Obj: CanvasComponentObj{ComponentName: "Begin", Params: map[string]any{}}},
"llm:0": {Obj: CanvasComponentObj{ComponentName: "LLM", Params: map[string]any{}}, Downstream: []string{"answer:0"}},
- "answer:0": {Obj: CanvasComponentObj{ComponentName: "Answer", Params: map[string]any{}}},
+ "answer:0": {Obj: CanvasComponentObj{ComponentName: "Message", Params: map[string]any{}}},
},
}
ctx := t.Context()
compiled, err := Compile(ctx, c, WithCheckPointID("task-9"))
if err != nil {
- t.Skipf("skipping propagation assertion: canvas did not compile in unit scope: %v", err)
+ t.Fatalf("Compile: %v", err)
}
if compiled == nil {
- t.Skip("skipping propagation assertion: nil CompiledCanvas")
+ t.Fatal("Compile returned nil CompiledCanvas")
}
if compiled.CheckPointID != "task-9" {
t.Errorf("CompiledCanvas.CheckPointID = %q, want %q", compiled.CheckPointID, "task-9")
diff --git a/internal/agent/component/fixture_stubs.go b/internal/agent/component/fixture_stubs.go
index bf6f5f9fe2..19f0c4e7e8 100644
--- a/internal/agent/component/fixture_stubs.go
+++ b/internal/agent/component/fixture_stubs.go
@@ -17,7 +17,7 @@
// Package component contains e2e fixture stubs used directly by tests.
//
// The test fixtures under internal/agent/dsl/testdata reference
-// fixture-backed component names that are registered here: Generate, Answer,
+// fixture-backed component names that are registered here: Generate,
// Iteration, and IterationItem. The fixture stub bodies are deliberately trivial — they
// echo a stable, template-friendly output shape and never call
// the network or DB. The contract is "registered, non-panicking,
@@ -37,8 +37,6 @@ import (
"context"
"fmt"
- "ragflow/internal/agent/runtime"
-
"gorm.io/gorm"
)
@@ -132,65 +130,6 @@ func buildLLMParamFromV1Params(p map[string]any) (LLMParam, error) {
return out, nil
}
-// ----- Answer -----
-
-const componentNameAnswer = "Answer"
-
-// AnswerStub is a fixture stub for the Answer component. Answer
-// is the agent's "wait for user" node (it pairs with ExeSQL or
-// Message in conversational flows). The real implementation
-// pauses the run and resumes on user input via the eino
-// interrupt path (see canvas/interrupt_resume.go); the stub
-// returns an empty answer immediately so the e2e flow can
-// complete.
-type AnswerStub struct{}
-
-// NewAnswerStub constructs an Answer stub.
-func NewAnswerStub(_ map[string]any) (Component, error) {
- return &AnswerStub{}, nil
-}
-
-// Name returns the registered component name.
-func (a *AnswerStub) Name() string { return componentNameAnswer }
-
-// Invoke returns an empty answer. Real implementation will block
-// until the user provides input; the stub is fire-and-forget so
-// the e2e flow doesn't deadlock.
-func (a *AnswerStub) Invoke(ctx context.Context, db *gorm.DB, _ map[string]any) (map[string]any, error) {
- // Mirror the no-state-check pattern of Message/Retrieval: we
- // don't read state, but the signature must match.
- if _, err := runtime.GetStateFromContext(ctx); err != nil {
- return nil, fmt.Errorf("Answer: %w", err)
- }
- return map[string]any{"answer": ""}, nil
-}
-
-// Stream mirrors Invoke.
-func (a *AnswerStub) Stream(ctx context.Context, db *gorm.DB, inputs map[string]any) (<-chan map[string]any, error) {
- out, err := a.Invoke(ctx, db, inputs)
- if err != nil {
- return nil, err
- }
- ch := make(chan map[string]any, 1)
- ch <- out
- close(ch)
- return ch, nil
-}
-
-// Inputs returns the DSL param surface.
-func (a *AnswerStub) Inputs() map[string]string {
- return map[string]string{
- "question": "Optional clarification question to surface to the user.",
- }
-}
-
-// Outputs returns the public output surface.
-func (a *AnswerStub) Outputs() map[string]string {
- return map[string]string{
- "answer": "User's response text.",
- }
-}
-
// ----- Iteration / IterationItem (alias to Parallel) -----
// componentNameIteration / componentNameIterationItem are the legacy
@@ -318,7 +257,6 @@ func init() {
Register("search_my_dateset", newRetrievalComponent)
Register(componentNameCodeExec, newCodeExecComponent)
Register(componentNameGenerate, NewGenerateStub)
- Register(componentNameAnswer, NewAnswerStub)
Register(componentNameIteration, NewIterationStub)
Register(componentNameIterationItem, NewIterationItemStub)
}
diff --git a/internal/agent/component/fixture_stubs_test.go b/internal/agent/component/fixture_stubs_test.go
new file mode 100644
index 0000000000..5540289645
--- /dev/null
+++ b/internal/agent/component/fixture_stubs_test.go
@@ -0,0 +1,32 @@
+package component_test
+
+import (
+ "strings"
+ "testing"
+
+ "ragflow/internal/agent/canvas"
+ _ "ragflow/internal/agent/component"
+)
+
+func TestCompileRejectsAnswerComponent(t *testing.T) {
+ c := &canvas.Canvas{
+ Components: map[string]canvas.CanvasComponent{
+ "begin": {
+ Obj: canvas.CanvasComponentObj{ComponentName: "Begin"},
+ Downstream: []string{"answer"},
+ },
+ "answer": {
+ Obj: canvas.CanvasComponentObj{ComponentName: "Answer"},
+ Upstream: []string{"begin"},
+ },
+ },
+ }
+
+ _, err := canvas.Compile(t.Context(), c)
+ if err == nil {
+ t.Fatal("Compile accepted unsupported Answer component")
+ }
+ if !strings.Contains(err.Error(), `unknown component "Answer"`) {
+ t.Fatalf("Compile error = %q, want unknown Answer component", err)
+ }
+}
diff --git a/internal/agent/component/verify_p1_test.go b/internal/agent/component/verify_p1_test.go
index f5f54968da..83e4758c17 100644
--- a/internal/agent/component/verify_p1_test.go
+++ b/internal/agent/component/verify_p1_test.go
@@ -11,7 +11,7 @@ import (
// read from plan §2.11.10 — P0 (8) + P1 (5) + P2 (4) + P3 (2) + P4 (3) = 22
// at plan completion, plus v1 fixture wrappers/stubs (including Retrieval,
// TavilySearch, TavilyExtract, ExeSQL, CodeExec, Google, BGPT, YahooFinance,
-// Wikipedia, GoogleScholar, ArXiv, PubMed, DuckDuckGo, Generate, Answer,
+// Wikipedia, GoogleScholar, ArXiv, PubMed, DuckDuckGo, Generate,
// Iteration, and IterationItem) registered by fixture_stubs.go to keep the
// dsl-examples and canvas tool surface compiling. The test allows counts
// between 12 (P0+P1 minus the removed ExitLoop) and 55 to roll forward as
diff --git a/internal/handler/agent_component_test.go b/internal/handler/agent_component_test.go
index 3755d30b17..6c968ac077 100644
--- a/internal/handler/agent_component_test.go
+++ b/internal/handler/agent_component_test.go
@@ -265,9 +265,9 @@ func TestGetComponentInputForm_NoInputForm(t *testing.T) {
ID: "c1",
DSL: map[string]any{
"components": map[string]any{
- "answer": map[string]any{
+ "message": map[string]any{
"obj": map[string]any{
- "component_name": "Answer",
+ "component_name": "Message",
// no params.inputs
},
},
@@ -276,10 +276,10 @@ func TestGetComponentInputForm_NoInputForm(t *testing.T) {
}
h := &AgentHandler{loader: &fakeCanvasLoader{canvas: cv}}
- c, w := componentCtx(t, "GET", "/api/v1/agents/c1/components/answer/input-form", "")
+ c, w := componentCtx(t, "GET", "/api/v1/agents/c1/components/message/input-form", "")
c.Params = gin.Params{
{Key: "canvas_id", Value: "c1"},
- {Key: "component_id", Value: "answer"},
+ {Key: "component_id", Value: "message"},
}
h.GetComponentInputForm(c)