Files
ragflow/README_tzh.md
Zhichang Yu 3f805a64f1 feat(agent): align Go agent behavior with Python (except retrieval component) (#16225)
## Summary

Aligns the **Go agent runtime/canvas/components/tools** behavior with
the **Python `agent/` implementation** so the same stored canvas DSL
produces the same execution result on either side. Every component,
tool, and runtime primitive in `internal/agent/` is now driven by the
same semantics as its Python counterpart — variable resolution, template
substitution, control flow, error reporting, retry/cancel, and stream
event shapes.

The **retrieval component is the one explicit exception** in this PR. It
is being reworked in a separate change and is excluded from this
alignment pass; the wrapper slot (`universe_a_wrappers.go →
newRetrievalComponent`) is preserved.

## Scope of alignment

### Components (all aligned with `agent/component/`)
`Begin` · `Message` · `LLM` (incl. ChatTemplateKwargs,
MessageHistoryWindowSize, VisualFiles, Cite, OutputStructure,
JSONOutput, TopP, MaxRetries, DelayAfterError, credentials) · `Agent`
(react + tool artifact capture + `Reset()` interface-assert) · `Switch`
(12/12 operators, Python-equivalent semantics) · `Categorize` · `Invoke`
· `Iteration` · `Loop` (macro-expansion through `workflowx.AddLoopNode`)
· `UserFillUp` (Python-equivalent interrupt/resume via eino
`compose.Interrupt`/`ResumeWithData`) · `FillUp` · `DataOperations` ·
`ListOperations` · `StringTransform` · `VariableAggregator` ·
`VariableAssigner` · `Browser` (full stagehand runtime parity) ·
`DocsGenerator` · `ExcelProcessor`.

### Tools (all aligned with `agent/tools/`)
`Retrieval` (wrapper slot only — logic out of scope) · `MCPToolAdapter`
(streamable-HTTP) · `CodeExec` (sandbox bridge with
`code_exec_contract.go` matching Python contract) · `AkShare` · `ArXiv`
· `Crawler` · `DeepL` · `DuckDuckGo` · `Email` · `ExeSQL` · `GitHub` ·
`Google` · `GoogleScholar` · `Jin10` · `PubMed` · `QWeather` · `SearXNG`
· `Tavily` · `Tushare` · `Wencai` · `Wikipedia` · `YahooFinance` —
uniform `eino tool.InvokableTool` interface, SSRF protection, shared
HTTP client.

### Canvas execution engine (`internal/agent/canvas/`)
Aligned with Python's `agent/canvas.py`:
- **Scheduler** (`scheduler.go`): state pre/post handlers, node lambdas,
per-component timeout resolver (4-level: per-class env → per-class table
→ uniform env → 600s fallback), `legacyNoOpNames`.
- **Loop subgraph** (`loop_subgraph.go`): Python-equivalent
`AddLoopNode` macro expansion + condition translation.
- **Multibranch** (`multibranch.go`): `Switch` / `Categorize` routing
via `compose.NewGraphMultiBranch` — same branch selection semantics as
Python.
- **Parallel subgraph** (`parallel_subgraph.go`): matches Python's
parallel fan-out contract.
- **Interrupt/Resume** (`interrupt_resume.go`): `UserFillUpNodeBody` /
`IsInterruptError` / `ExtractInterruptContexts` — replaces the
deprecated Python sentinel chain with eino's native interrupt API,
preserving the same external behavior.
- **Checkpoint** (`checkpoint_store.go`): `RedisCheckPointStore`
Get/Set/Delete, with business metadata (status / canvas_id /
parent_run_id) on a parallel Redis Hash.
- **RunTracker** (`run_tracker.go`): Start / MarkSucceeded / MarkFailed
/ MarkCancelled / AttachCheckpoint — same lifecycle as the Python run
record.
- **Cancel** (`cancel.go`): Redis pub/sub watch.
- **Stream** (`stream.go`): SSE channel with `messages` / `waiting` /
`errors` / `done` events, same shape as Python's `agent.canvas.RunEvent`
payload.

### DSL bridge (`internal/agent/dsl/`)
- `normalize.go`: v1↔v2 collapsed into a single wire format — Python and
Go consume the same stored JSON.
- `reset.go`: per-run state reset matches Python's `Canvas.reset()`
semantics.
- Testdata mirrors Python's `agent_msg.json` / `all.json` / etc.

### Runtime (`internal/agent/runtime/`)
- `CanvasState` / `NewCanvasState` / `GetVar` / `SetVar` / `ReadVars`:
same `{{cpn_id@param}}` resolution model.
- `ResolveTemplate` (regex fast path + gonja fallback) — Python
Jinja-style semantics.
- `selector.go`, `metrics.go`, `component.go`: shared runtime contracts.

## Out of scope (intentionally)

- **`Retrieval` component logic** — wrapped only; full parity lands in a
follow-up PR.
- **Frontend** — only minor dsl-bridge / canvas UX fixes ride along.
- **CLI / admin / model registry** — orthogonal to agent behavior.

## How alignment is verified

`internal/service/agent_run_e2e_test.go` exercises the **full production
chain** against real Python-shaped DSL fixtures:
```
loadCanvasForUser → versionDAO.GetLatest → decodeCanvasFromDSL →
canvas.Compile → cc.Workflow.Invoke → answer extraction
```
using in-memory SQLite + miniredis (no Docker). Covers:
- `TestRunAgent_RealCanvas_BeginMessage` — happy path, `{{sys.query}}`
resolution
- `TestRunAgent_RealCanvas_WaitForUserResume` — two-run resume cycle
(Python-equivalent)
- `TestRunAgent_RealCanvas_CompileFails` — unknown component name →
sanitized error (Python-equivalent)
- `TestRunAgent_RealCanvas_InvokeFails` — unresolvable template ref
(Python-equivalent)
- `TestRunAgent_RunTracker_AttachCheckpoint_CallSequence` —
Start→AttachCheckpoint→MarkSucceeded lifecycle

`internal/handler/agent_test.go` — SSE streaming parity (`Content-Type:
text/event-stream`, `data: {…}\n\n`, trailing `data: [DONE]\n\n`,
OpenAI-compatible non-stream `choices`).

`internal/agent/canvas/fixture_compile_test.go` + per-component tests
pin the Python-equivalent outputs.

```
go test -count=1 -v -run 'TestRunAgent_RealCanvas|TestRunAgent_RunTracker' ./internal/service/
```

## Design reference

`docs/develop/agent-go-port-design.md` (1329 lines, last cross-checked
2026-06-17) — module layout, per-component / per-tool inventory,
corner-case catalogue, and the actionable backlog (Section 14, including
the retrieval alignment follow-up).

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-22 11:58:29 +08:00

17 KiB
Raw Permalink Blame History

README in English 简体中文版自述文件 繁體版中文自述文件 日本語のREADME 한국어 README en Français Bahasa Indonesia Português(Brasil) README in Arabic Türkçe README

follow on X(Twitter) Static Badge docker pull infiniflow/ragflow:v0.26.1 Latest Release license Ask DeepWiki

Cloud | Document | Roadmap | Discord

infiniflow%2Fragflow | Trendshift
📕 目錄

💡 RAGFlow 是什麼?

RAGFlow 是一款領先的開源 RAGRetrieval-Augmented Generation引擎通過融合前沿的 RAG 技術與 Agent 能力,為大型語言模型提供卓越的上下文層。它提供可適配任意規模企業的端到端 RAG 工作流,憑藉融合式上下文引擎與預置的 Agent 模板,助力開發者以極致效率與精度將複雜數據轉化為高可信、生產級的人工智能系統。

🎮 快速開始

請登入網址 https://cloud.ragflow.io 試用雲服務。

🔥 近期更新

  • 2026-06-15 支援飛書、Discord、Telegram、Line 等多種聊天管道。
  • 2026-04-24 支援 DeepSeek v4 版本。
  • 2026-03-24 發布 RAGFlow 官方 Skill — 提供官方 Skill 以透過 OpenClaw 訪問 RAGFlow 數據集。
  • 2025-12-26 支援AI代理的「記憶」功能。
  • 2025-11-19 支援 Gemini 3 Pro。
  • 2025-11-12 支援從 Confluence、S3、Notion、Discord、Google Drive 進行資料同步。
  • 2025-10-23 支援 MinerU 和 Docling 作為文件解析方法。
  • 2025-10-15 支援可編排的資料管道。
  • 2025-08-08 支援 OpenAI 最新的 GPT-5 系列模型。
  • 2025-08-01 支援 agentic workflow 和 MCP。
  • 2025-05-23 為 Agent 新增 Python/JS 程式碼執行器元件。
  • 2025-03-19 PDF和DOCX中的圖支持用多模態大模型去解析得到描述。

🎉 關注項目

點擊右上角的 Star 追蹤 RAGFlow可以取得最新發布的即時通知 !🌟

🌟 主要功能

🍭 "Quality in, quality out"

  • 基於深度文件理解,能夠從各類複雜格式的非結構化資料中提取真知灼見。
  • 真正在無限上下文token的場景下快速完成大海撈針測試。

🍱 基於模板的文字切片

  • 不只是智能,更重要的是可控可解釋。
  • 多種文字範本可供選擇

🌱 有理有據、最大程度降低幻覺hallucination

  • 文字切片過程視覺化,支援手動調整。
  • 有理有據:答案提供關鍵引用的快照並支持追根溯源。

🍔 相容各類異質資料來源

  • 支援豐富的文件類型,包括 Word 文件、PPT、excel 表格、txt 檔案、圖片、PDF、影印件、複印件、結構化資料、網頁等。

🛀 全程無憂、自動化的 RAG 工作流程

  • 全面優化的 RAG 工作流程可以支援從個人應用乃至超大型企業的各類生態系統。
  • 大語言模型 LLM 以及向量模型皆支援配置。
  • 基於多路召回、融合重排序。
  • 提供易用的 API可輕鬆整合到各類企業系統。

🔎 系統架構

🎬 自行架設

📝 前提條件

  • CPU >= 4 核
  • RAM >= 16 GB
  • Disk >= 50 GB
  • Docker >= 24.0.0 & Docker Compose >= v2.26.1
  • Python >= 3.13
  • gVisor: 僅在您打算使用 RAGFlow 的代碼執行器(沙箱)功能時才需要安裝。

Tip

如果你並沒有在本機安裝 DockerWindows、Mac或 Linux, 可以參考文件 Install Docker Engine 自行安裝。

🚀 啟動伺服器

  1. 確保 vm.max_map_count 不小於 262144

    如需確認 vm.max_map_count 的大小:

    $ sysctl vm.max_map_count
    

    如果 vm.max_map_count 的值小於 262144可以進行重設

    # 這裡我們設為 262144:
    $ sudo sysctl -w vm.max_map_count=262144
    

    你的改動會在下次系統重新啟動時被重置。如果希望做永久改動,還需要在 /etc/sysctl.conf 檔案裡把 vm.max_map_count 的值再相應更新一遍:

    vm.max_map_count=262144
    
  2. 克隆倉庫:

    $ git clone https://github.com/infiniflow/ragflow.git
    
  3. 進入 docker 資料夾,利用事先編譯好的 Docker 映像啟動伺服器:

Caution

所有 Docker 映像檔都是為 x86 平台建置的。目前,我們不提供 ARM64 平台的 Docker 映像檔。 如果您使用的是 ARM64 平台,請使用 這份指南 來建置適合您系統的 Docker 映像檔。

執行以下指令會自動下載 RAGFlow Docker 映像 v0.26.1。請參考下表查看不同 Docker 發行版的說明。如需下載不同於 v0.26.1 的 Docker 映像,請在執行 docker compose 啟動服務之前先更新 docker/.env 檔案內的 RAGFLOW_IMAGE 變數。

   $ cd ragflow/docker

   # git checkout v0.26.1
   # 可選使用穩定版標籤查看發佈https://github.com/infiniflow/ragflow/releases
   # 此步驟確保程式碼中的 entrypoint.sh 檔案與 Docker 映像版本一致。

   # Use CPU for DeepDoc tasks:
   $ docker compose -f docker-compose.yml up -d

   # To use GPU to accelerate DeepDoc tasks:
   # sed -i '1i DEVICE=gpu' .env
   # docker compose -f docker-compose.yml up -d

注意:在 v0.22.0 之前的版本,我們會同時提供包含 embedding 模型的映像和不含 embedding 模型的 slim 映像。具體如下:

RAGFlow image tag Image size (GB) Has embedding models? Stable?
v0.21.1 ≈9 ✔️ Stable release
v0.21.1-slim ≈2 Stable release

v0.22.0 開始,我們只發佈 slim 版本,並且不再在映像標籤後附加 -slim 後綴。

Tip

如果你遇到 Docker 映像檔拉不下來的問題,可以在 docker/.env 檔案內根據變數 RAGFLOW_IMAGE 的註解提示選擇華為雲或阿里雲的對應映像。

  • 華為雲鏡像名:swr.cn-north-4.myhuaweicloud.com/infiniflow/ragflow
  • 阿里雲鏡像名:registry.cn-hangzhou.aliyuncs.com/infiniflow/ragflow
  1. 伺服器啟動成功後再次確認伺服器狀態:

    $ docker logs -f docker-ragflow-cpu-1
    

    出現以下介面提示說明伺服器啟動成功:

         ____   ___    ______ ______ __
        / __ \ /   |  / ____// ____// /____  _      __
       / /_/ // /| | / / __ / /_   / // __ \| | /| / /
      / _, _// ___ |/ /_/ // __/  / // /_/ /| |/ |/ /
     /_/ |_|/_/  |_|\____//_/    /_/ \____/ |__/|__/
    
     * Running on all addresses (0.0.0.0)
    

    如果您跳過這一步驟系統確認步驟就登入 RAGFlow你的瀏覽器有可能會提示 network abnormal網路異常,因為 RAGFlow 可能並未完全啟動成功。

  2. 在你的瀏覽器中輸入你的伺服器對應的 IP 位址並登入 RAGFlow。

    上面這個範例中,您只需輸入 http://IP_OF_YOUR_MACHINE 即可:未改動過設定則無需輸入連接埠(預設的 HTTP 服務連接埠 80

  3. service_conf.yaml.template 檔案的 user_default_llm 欄位設定 LLM factory並在 API_KEY 欄填入和你選擇的大模型相對應的 API key。

    詳見 llm_api_key_setup

    _好戲開始接著奏樂接著舞 _

🔧 系統配置

系統配置涉及以下三份文件:

請務必確保 .env 檔案中的變數設定與 service_conf.yaml.template 檔案中的設定保持一致!

如果無法存取映像網站 hub.docker.com 或模型網站 huggingface.co請依照 .env 註解修改 RAGFLOW_IMAGEHF_ENDPOINT

./docker/README 解釋了 service_conf.yaml.template 用到的環境變數設定和服務配置。

如需更新預設的 HTTP 服務連接埠(80), 可以在docker-compose.yml 檔案中將配置 80:80 改為 <YOUR_SERVING_PORT>:80

所有系統配置都需要透過系統重新啟動生效:

$ docker compose -f docker-compose.yml up -d

###把文檔引擎從 Elasticsearch 切換成為 Infinity

RAGFlow 預設使用 Elasticsearch 儲存文字和向量資料. 如果要切換為 Infinity, 可以按照下面步驟進行:

  1. 停止所有容器運作:

    $ docker compose -f docker/docker-compose.yml down -v
    

    Note: -v 將會刪除 docker 容器的 volumes已有的資料會被清空。

  2. 設定 docker/.env 目錄中的 DOC_ENGINEinfinity.

  3. 啟動容器:

    $ docker compose -f docker-compose.yml up -d
    

Warning

Infinity 目前官方並未正式支援在 Linux/arm64 架構下的機器上運行.

🔧 原始碼編譯 Docker 映像

本 Docker 映像大小約 2 GB 左右並且依賴外部的大模型和 embedding 服務。

git clone https://github.com/infiniflow/ragflow.git
cd ragflow/
docker build --platform linux/amd64 -f Dockerfile -t infiniflow/ragflow:nightly .

若您位於代理環境,可傳遞代理參數:

docker build --platform linux/amd64 \
  --build-arg http_proxy=http://YOUR_PROXY:PORT \
  --build-arg https_proxy=http://YOUR_PROXY:PORT \
  -f Dockerfile -t infiniflow/ragflow:nightly .

🔨 以原始碼啟動服務

  1. 安裝 uvpre-commit。如已安裝,可跳過此步驟:

    pipx install uv pre-commit
    export UV_INDEX=https://mirrors.aliyun.com/pypi/simple
    
  2. 下載原始碼並安裝 Python 依賴:

    git clone https://github.com/infiniflow/ragflow.git
    cd ragflow/
    uv sync --python 3.13 # install RAGFlow dependent python modules
    uv run python3 ragflow_deps/download_deps.py
    pre-commit install
    
  3. 透過 Docker Compose 啟動依賴的服務MinIO, Elasticsearch, Redis, and MySQL

    docker compose -f docker/docker-compose-base.yml up -d
    

    /etc/hosts 中加入以下程式碼,將 conf/service_conf.yaml 檔案中的所有 host 位址都解析為 127.0.0.1

    127.0.0.1       es01 infinity mysql minio redis sandbox-executor-manager
    
  4. 如果無法存取 HuggingFace可以把環境變數 HF_ENDPOINT 設為對應的鏡像網站:

    export HF_ENDPOINT=https://hf-mirror.com
    
  5. 如果你的操作系统没有 jemalloc请按照如下方式安装

    # ubuntu
    sudo apt-get install libjemalloc-dev
    # centos
    sudo yum install jemalloc
    # mac
    sudo brew install jemalloc
    
  6. 啟動後端服務:

    source .venv/bin/activate
    export PYTHONPATH=$(pwd)
    bash docker/launch_backend_service.sh
    
  7. 安裝前端依賴:

    cd web
    npm install
    
  8. 啟動前端服務:

    npm run dev
    

    以下界面說明系統已成功啟動_

    
    
  9. 開發完成後停止 RAGFlow 前端和後端服務:

    pkill -f "ragflow_server.py|task_executor.py"
    

📚 技術文檔

📜 路線圖

詳見 RAGFlow Roadmap 2026

🏄 開源社群

🙌 貢獻指南

RAGFlow 只有透過開源協作才能蓬勃發展。秉持這項精神,我們歡迎來自社區的各種貢獻。如果您有意參與其中,請查閱我們的 貢獻者指南

🤝 商務合作

👥 加入社區

掃二維碼加入 RAGFlow 小助手,進 RAGFlow 交流群。