Files
Zhichang Yu e45659868a feat(agent): ship the Go agent canvas port — eino interrupt/resume + Redis check-pointing (#16035)
Replaces the Python agent canvas runtime with a Go implementation that
runs inside `cmd/server_main`.

The canvas compiles into an eino Workflow that pauses on wait-for-user
via native Interrupt/Resume (no sentinel flag) and resumes from a
Redis-backed CheckPointStore.

All 21 Python agent components and ~35 tools are ported with functional
parity.

Sandbox providers now read their JSON config from the admin-panel
system_settings table with env fallback.

234 files / +35,413 / -6,111. All Go files are gofmt-clean (CI gate
added); drops the v2 DSL E2E step and the gap-analysis plan (both
redundant after the port ships).

## Type of change

- [x] Refactoring
- [x] New feature
- [x] Bug fix

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-17 13:24:03 +08:00

84 lines
3.6 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Package component implements the RAGFlow agent canvas components
// in Go following the 5-tier porting strategy (T1T5; see
// docs/develop/agent-go-port-design.md §4.1).
//
// Component is the runtime contract every RAGFlow component
// implements; it is a richer interface than
// internal/agent/runtime.Component (which is the minimal Invoke-only
// surface canvas needs at build time). Any concrete *Component here
// satisfies runtime.Component structurally, which is how the canvas
// builder consumes a registered component via
// runtime.DefaultFactory().
//
// ParamError and ErrNotImplemented are aliased from runtime so the
// canvas builder and the component implementations share the same
// types without a cycle.
package component
import (
"context"
"ragflow/internal/agent/runtime"
)
// Component is the runtime contract every RAGFlow component implements.
// Mirrors the Python ComponentBase.invoke / invoke_async surface
// (agent/component/base.py:365, 408, 422) plus a Stream variant for SSE
// output (the Message component).
//
// Inputs() and Outputs() return parameter metadata for tooling / docs /
// graph introspection — name → human description. Not used at runtime.
//
// Any value implementing this interface also satisfies the smaller
// runtime.Component interface (Invoke only), so the canvas builder
// can consume a *Component via runtime.DefaultFactory() without any
// extra adaptation.
type Component interface {
// Name returns the registered component name (e.g. "LLM", "Agent",
// "Switch"). Case-insensitive lookup — the registry normalizes input.
Name() string
// Invoke runs the component synchronously. inputs is the resolved
// parameter map (variable references already substituted by the canvas
// engine). Returns the output map; components should put their public
// outputs at top-level keys.
Invoke(ctx context.Context, inputs map[string]any) (map[string]any, error)
// Stream is the streaming variant. The default implementation may
// return a buffered channel that emits the same payload as Invoke, then
// closes — components that natively stream (LLM, Message) override.
// May return (nil, nil) for non-streaming components.
Stream(ctx context.Context, inputs map[string]any) (<-chan map[string]any, error)
// Inputs returns parameter metadata: param_name → description.
Inputs() map[string]string
// Outputs returns output metadata: param_name → description.
Outputs() map[string]string
}
// ParamBase is the optional parameter validation/serialization surface.
// Components that need validation can embed *BaseParam (below) or implement
// this directly. Components that don't need it (e.g. ExitLoop) can omit.
//
// Mirrors agent/component/param_base.py:ComponentParamBase (Python).
type ParamBase interface {
// Update copies conf into the receiver, validating types. Used by
// editors / APIs that hand-craft a params map.
Update(conf map[string]any) error
// Check performs deep validation (required fields, value ranges).
// Called once before Invoke — returning an error aborts the run.
Check() error
// AsDict returns the params as a plain map for serialization / debug.
AsDict() map[string]any
}
// ErrNotImplemented aliases runtime.ErrNotImplemented so component-side
// code (and the canvas builder it interoperates with) share a single
// sentinel value.
var ErrNotImplemented = runtime.ErrNotImplemented
// ParamError aliases runtime.ParamError. Existing code that constructs
// &ParamError{Field: ..., Reason: ...} continues to work; the value
// it produces is the same type runtime.SetDefaultFactory consumers see.
type ParamError = runtime.ParamError