Skip to content

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

fix(agent): propagate provider failures before downstream execution (#20968)

Sbaaoui Idrissf7d9bce148a6
diff --git a/internal/agent/component/agent.go b/internal/agent/component/agent.go
index 8b987a97bb..21ab299143 100644
--- a/internal/agent/component/agent.go
+++ b/internal/agent/component/agent.go
@@ -1061,12 +1061,9 @@ func (c *AgentComponent) invokeNow(ctx context.Context, db *gorm.DB, inputs map[
}
}
if err != nil {
- // Python's LLM layer turns model/tool execution failures into an
- // ``**ERROR**`` response, which Agent exposes as the `_ERROR`
- // component output. Preserve cancellation as a real graph error,
- // but keep ordinary ReAct failures in the component data flow so
- // Canvas exception branches can handle them.
- if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) || !isAgentGraphRunError(err) {
+ // Only step exhaustion is an _ERROR output. Model/tool failures must
+ // stop execution before downstream nodes read an absent content output.
+ if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) || !errors.Is(err, compose.ErrExceedMaxSteps) {
return nil, fmt.Errorf("component: Agent.Invoke: %w", err)
}
return map[string]any{"_ERROR": "**ERROR**: " + runtime.MarkdownSafeErrorText(err)}, nil
@@ -1140,18 +1137,6 @@ func (c *AgentComponent) invokeNow(ctx context.Context, db *gorm.DB, inputs map[
return out, nil
}
-// isAgentGraphRunError identifies ReAct graph failures that Python exposes
-// through the Agent component's _ERROR output. Construction/configuration
-// errors must remain real component errors so invalid canvases still fail
-// fast; only the graph execution limit/error is routed to exception branches.
-func isAgentGraphRunError(err error) bool {
- if err == nil {
- return false
- }
- msg := strings.ToLower(err.Error())
- return strings.Contains(msg, "[graphrunerror]") || strings.Contains(msg, "exceeds max steps")
-}
-
// Stream implements Component.Stream. Mirrors Invoke then pushes the
// single payload through the channel.
func (c *AgentComponent) Stream(ctx context.Context, db *gorm.DB, inputs map[string]any) (<-chan map[string]any, error) {
diff --git a/internal/agent/component/agent_test.go b/internal/agent/component/agent_test.go
index d6e6e362c1..55b01a9f82 100644
--- a/internal/agent/component/agent_test.go
+++ b/internal/agent/component/agent_test.go
@@ -803,7 +803,7 @@ func TestAgent_ToolCallRound(t *testing.T) {
func TestAgent_ExhaustRoundsError(t *testing.T) {
withAgentRunner(t, func(_ context.Context, _ AgentParam) (*schema.Message, error) {
- return nil, errors.New("[GraphRunError] exceeds max steps")
+ return nil, fmt.Errorf("[GraphRunError] %w", compose.ErrExceedMaxSteps)
})
c := NewAgentComponent(AgentParam{ModelID: "stub", MaxRounds: 2})
@@ -814,7 +814,7 @@ func TestAgent_ExhaustRoundsError(t *testing.T) {
t.Fatalf("Invoke: %v", err)
}
if got := out["_ERROR"]; got != "**ERROR**: [GraphRunError] exceeds max steps" {
- t.Fatalf("_ERROR = %v, want Python-compatible error envelope", got)
+ t.Fatalf("_ERROR = %v, want step-exhaustion error envelope", got)
}
}
diff --git a/internal/agent/component/message.go b/internal/agent/component/message.go
index d3f55ff476..fbc0b5f9e5 100644
--- a/internal/agent/component/message.go
+++ b/internal/agent/component/message.go
@@ -32,6 +32,7 @@ package component
import (
"context"
+ "errors"
"fmt"
"strings"
@@ -455,7 +456,12 @@ func (m *MessageComponent) resolveDeferredTemplate(ctx context.Context, text str
runtime.EmitCanvasMessageEvent(ctx, "", false, true)
}
if err != nil {
- return "", true, &runtime.DeferredStreamError{Err: err}
+ if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
+ return "", true, &runtime.DeferredStreamError{Err: err}
+ }
+ // Eino reuses nested graph errors, discarding outer wrappers; keep
+ // ordinary stream failures as text so the deferred marker survives.
+ return "", true, &runtime.DeferredStreamError{Text: "**ERROR**: " + runtime.MarkdownSafeErrorText(err)}
}
if resultErr, _ := result["_ERROR"].(string); strings.TrimSpace(resultErr) != "" {
return "", true, &runtime.DeferredStreamError{Text: resultErr}
diff --git a/internal/agent/component/message_test.go b/internal/agent/component/message_test.go
index 433bf0595b..864c22a736 100644
--- a/internal/agent/component/message_test.go
+++ b/internal/agent/component/message_test.go
@@ -18,6 +18,8 @@ package component
import (
"context"
+ "errors"
+ "fmt"
"strings"
"testing"
@@ -434,6 +436,32 @@ func TestMessage_DeferredStreamSurfacesResultError(t *testing.T) {
}
}
+func TestMessage_DeferredStreamOpenFailure(t *testing.T) {
+ for _, cause := range []error{errors.New("model unavailable"), context.Canceled, context.DeadlineExceeded} {
+ t.Run(cause.Error(), func(t *testing.T) {
+ c, _ := NewMessageComponent(nil)
+ state := canvas.NewCanvasState("run-deferred-open-error", "task-deferred-open-error")
+ state.SetVar("agent_0", "content", &runtime.DeferredStream{
+ Open: func(context.Context, runtime.AgentDeltaSink) (map[string]any, error) {
+ return nil, fmt.Errorf("agent failed: %w", cause)
+ },
+ })
+ _, err := c.Invoke(withStateForTest(t.Context(), state), nil, map[string]any{"text": "{{agent_0@content}}"})
+ deferred, ok := errors.AsType[*runtime.DeferredStreamError](err)
+ if !ok {
+ t.Fatalf("Invoke error = %v, want DeferredStreamError", err)
+ }
+ if cause == context.Canceled || cause == context.DeadlineExceeded {
+ if !errors.Is(err, cause) {
+ t.Fatalf("Invoke error = %v, want preserved %v", err, cause)
+ }
+ } else if got := deferred.FailureText(); got != "**ERROR**: agent failed: model unavailable" {
+ t.Fatalf("failure text = %q, want chat error envelope", got)
+ }
+ })
+ }
+}
+
func TestMessage_FormalizedContentFallback(t *testing.T) {
c, _ := NewMessageComponent(nil)
state := canvas.NewCanvasState("run-5", "task-5")
diff --git a/internal/agent/component/sampler_params_test.go b/internal/agent/component/sampler_params_test.go
index dfc1423c29..a23f92c337 100644
--- a/internal/agent/component/sampler_params_test.go
+++ b/internal/agent/component/sampler_params_test.go
@@ -236,8 +236,8 @@ func TestAgent_DisabledSamplersStayOffAtRuntime(t *testing.T) {
mu.Lock()
bodies = append(bodies, body)
mu.Unlock()
- w.Header().Set("Content-Type", "application/json")
- _, _ = w.Write([]byte(`{"choices":[{"message":{"content":"ok"}}]}`))
+ w.Header().Set("Content-Type", "text/event-stream")
+ _, _ = w.Write([]byte("data: {\"choices\":[{\"index\":0,\"delta\":{\"content\":\"ok\"},\"finish_reason\":\"stop\"}]}\n\ndata: [DONE]\n\n"))
}))
defer server.Close()