AgentBuilder
Podman 可以用來替代 Docker 執行這裡顯示的所有命令。更多資訊,請參閱 Podman 文件。
在 Docker 容器中運行應用程式可確保在不同系統間的一致行為,並消除依賴衝突。
您可以使用 AgentBuilder Docker 映像來啟動 AgentBuilder 容器。
本指南演示了使用 Docker 和 Docker Compose 部署 AgentBuilder 的幾種方法:
- 快速開始:使用預設值啟動 AgentBuilder 容器。
- 使用 Docker Compose:複製 AgentBuilder 儲存庫,然後使用 Docker Compose 建置 AgentBuilder Docker 容器。 此選項提供更多對配置的控制,包括持久性 PostgreSQL 資料庫服務,同時仍使用基礎 AgentBuilder Docker 映像。
- 建立自訂FLOW映像:使用 Dockerfile 將FLOW打包為 Docker 映像。
- 建立自訂 AgentBuilder 映像:使用 Dockerfile 打包包含您自己程式碼、自訂依賴或其他修改的自訂 AgentBuilder Docker 映像。
快速開始:使用預設值啟動 AgentBuilder 容器
在您的系統上安裝並運行 Docker 後,執行以下命令:
_10docker run -p 7860:7860 langflowai/langflow:latest
然後,在 http://localhost:7860/ 存取 AgentBuilder。
此容器運行具有預設設定的預建 Docker 映像。 如需更多對配置的控制,請參閱複製儲存庫並運行 AgentBuilder Docker 容器。
複製儲存庫並運行 AgentBuilder Docker 容器
複製 AgentBuilder 儲存庫並使用 Docker Compose 讓您對配置有更多控制,允許您自訂環境變數、使用持久性 PostgreSQL 資料庫服務(而不是預設的 SQLite 資料庫),並包含自訂依賴。
使用 Docker Compose 的預設部署包括以下內容:
- AgentBuilder 服務:使用 PostgreSQL 作為資料庫運行最新的 AgentBuilder 映像。
- PostgreSQL 服務:為FLOW、使用者及設定提供持久性資料儲存。
- 持久性 磁碟區:確保您的資料在容器重新啟動後仍然存在。
完整的 Docker Compose 配置可在 docker_example/docker-compose.yml 中取得。
-
複製 AgentBuilder 儲存庫:
_10git clone https://github.com/langflow-ai/langflow.git -
導航到
docker_example目錄:_10cd langflow/docker_example -
運行 Docker Compose 檔案:
_10docker compose up -
在
http://localhost:7860/存取 AgentBuilder。
自訂您的部署
您可以自訂 Docker Compose 配置以適合您的特定部署。
例如,要使用 .env 檔案配置容器的資料庫憑證,請執行以下操作:
-
在與
docker-compose.yml相同的目錄中建立包含資料庫 憑證的.env檔案:_10# Database credentials_10POSTGRES_USER=myuser_10POSTGRES_PASSWORD=mypassword_10POSTGRES_DB=langflow_10_10# AgentBuilder configuration_10LANGFLOW_DATABASE_URL=postgresql://myuser:mypassword@postgres:5432/langflow_10LANGFLOW_CONFIG_DIR=/app/langflow -
修改
docker-compose.yml檔案以參考langflow和postgres服務的.env檔案:_10services:_10langflow:_10environment:_10- LANGFLOW_DATABASE_URL=${LANGFLOW_DATABASE_URL}_10- LANGFLOW_CONFIG_DIR=${LANGFLOW_CONFIG_DIR}_10postgres:_10environment:_10- POSTGRES_USER=${POSTGRES_USER}_10- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}_10- POSTGRES_DB=${POSTGRES_DB}
如需可用環境變數的完整清單,請參閱 AgentBuilder 環境變數。
如需更多自訂選項,請參閱使用您自己的程式碼自訂 AgentBuilder Docker 映像。
將您的FLOW打包為 Docker 映像
本節向您展示如何建立建置包含您的 AgentBuilder FLOW的 Docker 映像的 Dockerfile。此方法對於您想要將特定FLOW作為獨立容器分發或部署到 Kubernetes 等環境時很有用。
與之前使用預建映像的章節不同,此方法使用嵌入FLOW的自訂映像建置。
-
建立專案目錄,並變更目錄到其中。
_10mkdir langflow-custom && cd langflow-custom -
將您的FLOW JSON 檔案新增到目錄。您可以下載範例,或使用您自己的:
_10# Download an example flow_10wget https://raw.githubusercontent.com/langflow-ai/langflow-helm-charts/refs/heads/main/examples/flows/basic-prompting-hello-world.json_10_10# Or copy your own flow file_10cp /path/to/your/flow.json . -
建立 Dockerfile 以建置您的自訂映像:
_10FROM langflowai/langflow:latest_10RUN mkdir /app/flows_10COPY ./*.json /app/flows/_10ENV LANGFLOW_LOAD_FLOWS_PATH=/app/flows
此 Dockerfile 使用官方 AgentBuilder 映像作為基礎,建立FLOW目錄,將您的 JSON FLOW檔案複製到目錄中,並設定環境變數告訴 AgentBuilder 在哪裡找到FLOW。
-
建置並測試您的自訂映像:
_10docker build -t myuser/langflow-custom:1.0.0 ._10docker run -p 7860:7860 myuser/langflow-custom:1.0.0 -
推送您的映像到 Docker Hub(可選):
_10docker push myuser/langflow-custom:1.0.0
您的自訂映像現在包含您的FLOW,可以在任何運行 Docker 的地方部署。如需 Kubernetes 部署,請參閱在 Kubernetes 上部署 AgentBuilder 生產環境。
使用您自己的程式碼自訂 AgentBuilder Docker 映像
雖然上一節展示了如何將FLOW與 Docker 映像打包,但本節展示了如何自訂 AgentBuilder 應用程式本身。這對於您需要新增自訂 Python 套件或依賴、修改 AgentBuilder 的配置或設定、包含自訂Components或工具,或新增您自己的程式碼來擴展 AgentBuilder 功能時很有用。
此範例演示如何自訂 Message History Components,但相同的方法可以用於任何程式碼修改。
_27FROM langflowai/langflow:latest_27_27# Set working directory_27WORKDIR /app_27_27# Copy your modified memory component_27COPY src/backend/base/langflow/components/helpers/memory.py /tmp/memory.py_27_27# Find the site-packages directory where langflow is installed_27RUN python -c "import site; print(site.getsitepackages()[0])" > /tmp/site_packages.txt_27_27# Replace the file in the site-packages location_27RUN SITE_PACKAGES=$(cat /tmp/site_packages.txt) && \_27 echo "Site packages at: $SITE_PACKAGES" && \_27 mkdir -p "$SITE_PACKAGES/langflow/components/helpers" && \_27 cp /tmp/memory.py "$SITE_PACKAGES/langflow/components/helpers/"_27_27# Clear Python cache in the site-packages directory only_27RUN SITE_PACKAGES=$(cat /tmp/site_packages.txt) && \_27 find "$SITE_PACKAGES" -name "*.pyc" -delete && \_27 find "$SITE_PACKAGES" -name "__pycache__" -type d -exec rm -rf {} +_27_27# Expose the default Langflow port_27EXPOSE 7860_27_27# Command to run Langflow_27CMD ["python", "-m", "langflow", "run", "--host", "0.0.0.0", "--port", "7860"]
要 使用此自訂 Dockerfile,請執行以下操作:
-
為您的自訂 AgentBuilder 設定建立目錄:
_10mkdir langflow-custom && cd langflow-custom -
為您的自訂程式碼建立必要的目錄結構。 在此範例中,AgentBuilder 期望
memory.py存在於/helpers目錄中,因此您在該位置建立目錄。_10mkdir -p src/backend/base/langflow/components/helpers -
將您的修改後的
memory.py檔案放在/helpers目錄中。 -
在您的
langflow-custom目錄中建立名為Dockerfile的新檔案,然後將上面顯示的 Dockerfile 內容複製到其中。 -
建置並運行映像:
_10docker build -t myuser/langflow-custom:1.0.0 ._10docker run -p 7860:7860 myuser/langflow-custom:1.0.0
此方法可以透過修改檔案路徑和Components名稱來適應您想要新增到 AgentBuilder 的任何其他Components或自訂程式碼。