This document describes the component system architecture that forms the foundation of RAGFlow's Agent and Workflow system. Components are the building blocks of Canvas workflows—self-contained, configurable units that perform specific tasks such as LLM invocation, retrieval, categorization, and string transformation. This page covers the base classes, parameter validation, the component factory pattern, and dynamic registration in both Python and Go.
For information about how components are orchestrated in workflows, see Canvas Engine and DSL For details on specific built-in components, see Built-in Components
The component system is built on foundational abstract classes that define configuration and execution logic. In Python, these are defined in agent/component/base.py. In Go, the system uses a native Component interface and specialized parameter structures.
Sources: agent/component/base.py43-365 agent/component/llm.py34-86 agent/component/agent_with_tools.py40-74 agent/component/message.py46-65 agent/component/categorize.py30-90 agent/tools/base.py98
ComponentParamBase defines the parameter schema and validation rules. Every component has an associated parameter class that handles the merging of runtime configuration with defaults.
| Attribute | Description | Defined In |
|---|---|---|
inputs | Dictionary defining expected input parameters and their types. | agent/component/base.py46 |
outputs | Dictionary storing the output values and types after execution. | agent/component/base.py47 |
max_retries | Number of times to retry on failure (default: 0). | agent/component/base.py49 |
delay_after_error | Seconds to wait between retries (default: 2.0). | agent/component/base.py50 |
The update(conf) method in agent/component/base.py performs a recursive update of the parameter object from a configuration dictionary agent/component/base.py136-187 It tracks which parameters were "user-fed" versus defaults and handles deprecated parameters agent/component/base.py166-172
Each parameter class must implement a check() method to enforce constraints. For example:
LLMParam.check() validates numeric constraints for temperature, presence_penalty, frequency_penalty, and top_p agent/component/llm.py53-60MessageParam.check() ensures content is not empty and validates boolean flags agent/component/message.py59-62CategorizeParam.check() ensures category descriptions and "to" destinations are valid agent/component/categorize.py42-50Sources: agent/component/base.py43-187 agent/component/llm.py53-60 agent/component/message.py59-62 agent/component/categorize.py42-50
RAGFlow uses a dynamic discovery mechanism to register and load components at runtime. This avoids hard-coding imports and allows the system to be extended easily.
The Graph.load() method in agent/canvas.py uses the component_class factory to instantiate components from the DSL:
component_class(name): A factory function that resolves component names to their Python classes agent/canvas.py30Graph.load(): Iterates through the DSL components dictionary, instantiates the parameter object, calls param.check(), and then instantiates the execution object agent/canvas.py102-115In the Go port, components are implemented as structs satisfying a Component interface. The AgentComponent and MessageComponent are primary examples.
AgentComponent: Implements a multi-turn ReAct agent powered by eino's flow/agent/react package internal/agent/component/agent.go72-76 It resolves AgentParam which includes model IDs, tools, and sub-agents internal/agent/component/agent.go79-108MessageComponent: Acts as the canvas terminal output node, resolving Jinja2-style templates against the CanvasState internal/agent/component/message.go54-63EinoChatModel: A bridge that adapts RAGFlow's internal ChatModel to eino's model.ToolCallingChatModel interface internal/entity/models/llm.go48-52Sources: agent/canvas.py30-115 internal/agent/component/agent.go72-108 internal/agent/component/message.go54-63 internal/entity/models/llm.go48-52
This diagram bridges the gap between the high-level DSL concepts and the concrete code entities in both Python and Go.
Sources: agent/canvas.py51-115 agent/component/base.py365 internal/agent/component/agent.go74 internal/agent/component/message.go54 internal/entity/models/llm.go48
Components implement logic in _invoke() or _stream().
Categorize: Uses an LLM to classify a query into defined categories, then sets the _next output to route the workflow agent/component/categorize.py101-150Message: Extracts downloads, stringifies values, and handles Jinja2 template rendering agent/component/message.py103-180 It supports streaming via _stream() agent/component/message.py188Go components utilize the Invoke method and context-based state management.
AgentComponent: Executes the ReAct loop using runEinoReActAgent internal/agent/component/agent.go159 It can defer execution for downstream Message components using runtime.DeferredStream internal/agent/component/agent_test.go154-171MessageComponent.Invoke: Resolves templates against CanvasState internal/agent/component/message.go174-198 It handles TTS via audio.Synthesizer and memory persistence internal/agent/component/message.go164-169Sources: agent/component/llm.py43 agent/component/message.py188-206 internal/agent/component/agent.go159 internal/agent/component/agent_test.go154-171
The Agent component bridges the gap between standard LLM generation and external capability invocation.
Agent dynamically loads tool objects and binds them to an LLMBundle agent/component/agent_with_tools.py79-116 Go AgentComponent builds tools which are resolved into Eino BaseTool instances internal/agent/component/agent.go164cite is enabled, the agent performing a second LLM call to insert [ID:N] tags based on retrieval chunks agent/component/agent_with_tools.py35 internal/agent/component/agent.go98-104Sources: agent/component/agent_with_tools.py79-116 internal/agent/component/agent.go98-164
The component architecture includes built-in mechanisms for task management and failure recovery.
check_if_canceled() (e.g., in Message._stream and Categorize._invoke_async) to stop execution if the task has been aborted via Redis agent/component/message.py194-215 agent/component/categorize.py102-135AgentComponent exposes errors through a Python-compatible _ERROR output if rounds are exhausted or the runner fails internal/agent/component/agent_test.go10-11LLM.fit_messages ensures system and user prompts fit within the model's context budget, trimming content if necessary agent/component/llm.py154-159 rag/prompts/generator.py69-136Sources: agent/component/message.py194-215 agent/component/categorize.py102-135 internal/agent/component/agent_test.go10-11 agent/component/llm.py154-159 rag/prompts/generator.py69-136
Refresh this wiki
This wiki was recently refreshed. Please wait 4 days to refresh again.