Skip to main content

AgentBuilder

tip

Podman 可以用來替代 Docker 執行這裡顯示的所有命令。更多資訊,請參閱 Podman 文件

在 Docker 容器中運行應用程式可確保在不同系統間的一致行為,並消除依賴衝突。

您可以使用 AgentBuilder Docker 映像來啟動 AgentBuilder 容器。

本指南演示了使用 DockerDocker Compose 部署 AgentBuilder 的幾種方法:

  • 快速開始:使用預設值啟動 AgentBuilder 容器。
  • 使用 Docker Compose:複製 AgentBuilder 儲存庫,然後使用 Docker Compose 建置 AgentBuilder Docker 容器。 此選項提供更多對配置的控制,包括持久性 PostgreSQL 資料庫服務,同時仍使用基礎 AgentBuilder Docker 映像。
  • 建立自訂FLOW映像:使用 Dockerfile 將FLOW打包為 Docker 映像。
  • 建立自訂 AgentBuilder 映像:使用 Dockerfile 打包包含您自己程式碼、自訂依賴或其他修改的自訂 AgentBuilder Docker 映像。

快速開始:使用預設值啟動 AgentBuilder 容器

在您的系統上安裝並運行 Docker 後,執行以下命令:


_10
docker 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 中取得。

  1. 複製 AgentBuilder 儲存庫:


    _10
    git clone https://github.com/langflow-ai/langflow.git

  2. 導航到 docker_example 目錄:


    _10
    cd langflow/docker_example

  3. 運行 Docker Compose 檔案:


    _10
    docker compose up

  4. http://localhost:7860/ 存取 AgentBuilder。

自訂您的部署

您可以自訂 Docker Compose 配置以適合您的特定部署。

例如,要使用 .env 檔案配置容器的資料庫憑證,請執行以下操作:

  1. 在與 docker-compose.yml 相同的目錄中建立包含資料庫憑證的 .env 檔案:


    _10
    # Database credentials
    _10
    POSTGRES_USER=myuser
    _10
    POSTGRES_PASSWORD=mypassword
    _10
    POSTGRES_DB=langflow
    _10
    _10
    # AgentBuilder configuration
    _10
    LANGFLOW_DATABASE_URL=postgresql://myuser:mypassword@postgres:5432/langflow
    _10
    LANGFLOW_CONFIG_DIR=/app/langflow

  2. 修改 docker-compose.yml 檔案以參考 langflowpostgres 服務的 .env 檔案:


    _10
    services:
    _10
    langflow:
    _10
    environment:
    _10
    - LANGFLOW_DATABASE_URL=${LANGFLOW_DATABASE_URL}
    _10
    - LANGFLOW_CONFIG_DIR=${LANGFLOW_CONFIG_DIR}
    _10
    postgres:
    _10
    environment:
    _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的自訂映像建置。

  1. 建立專案目錄,並變更目錄到其中。


    _10
    mkdir langflow-custom && cd langflow-custom

  2. 將您的FLOW JSON 檔案新增到目錄。您可以下載範例,或使用您自己的:


    _10
    # Download an example flow
    _10
    wget 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
    _10
    cp /path/to/your/flow.json .

  3. 建立 Dockerfile 以建置您的自訂映像:


    _10
    FROM langflowai/langflow:latest
    _10
    RUN mkdir /app/flows
    _10
    COPY ./*.json /app/flows/
    _10
    ENV LANGFLOW_LOAD_FLOWS_PATH=/app/flows

此 Dockerfile 使用官方 AgentBuilder 映像作為基礎,建立FLOW目錄,將您的 JSON FLOW檔案複製到目錄中,並設定環境變數告訴 AgentBuilder 在哪裡找到FLOW。

  1. 建置並測試您的自訂映像:


    _10
    docker build -t myuser/langflow-custom:1.0.0 .
    _10
    docker run -p 7860:7860 myuser/langflow-custom:1.0.0

  2. 推送您的映像到 Docker Hub(可選):


    _10
    docker push myuser/langflow-custom:1.0.0

您的自訂映像現在包含您的FLOW,可以在任何運行 Docker 的地方部署。如需 Kubernetes 部署,請參閱在 Kubernetes 上部署 AgentBuilder 生產環境

使用您自己的程式碼自訂 AgentBuilder Docker 映像

雖然上一節展示了如何將FLOW與 Docker 映像打包,但本節展示了如何自訂 AgentBuilder 應用程式本身。這對於您需要新增自訂 Python 套件或依賴、修改 AgentBuilder 的配置或設定、包含自訂Components或工具,或新增您自己的程式碼來擴展 AgentBuilder 功能時很有用。

此範例演示如何自訂 Message History Components,但相同的方法可以用於任何程式碼修改。


_27
FROM langflowai/langflow:latest
_27
_27
# Set working directory
_27
WORKDIR /app
_27
_27
# Copy your modified memory component
_27
COPY src/backend/base/langflow/components/helpers/memory.py /tmp/memory.py
_27
_27
# Find the site-packages directory where langflow is installed
_27
RUN python -c "import site; print(site.getsitepackages()[0])" > /tmp/site_packages.txt
_27
_27
# Replace the file in the site-packages location
_27
RUN 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
_27
RUN 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
_27
EXPOSE 7860
_27
_27
# Command to run Langflow
_27
CMD ["python", "-m", "langflow", "run", "--host", "0.0.0.0", "--port", "7860"]

要使用此自訂 Dockerfile,請執行以下操作:

  1. 為您的自訂 AgentBuilder 設定建立目錄:


    _10
    mkdir langflow-custom && cd langflow-custom

  2. 為您的自訂程式碼建立必要的目錄結構。 在此範例中,AgentBuilder 期望 memory.py 存在於 /helpers 目錄中,因此您在該位置建立目錄。


    _10
    mkdir -p src/backend/base/langflow/components/helpers

  3. 將您的修改後的 memory.py 檔案放在 /helpers 目錄中。

  4. 在您的 langflow-custom 目錄中建立名為 Dockerfile 的新檔案,然後將上面顯示的 Dockerfile 內容複製到其中。

  5. 建置並運行映像:


    _10
    docker build -t myuser/langflow-custom:1.0.0 .
    _10
    docker run -p 7860:7860 myuser/langflow-custom:1.0.0

此方法可以透過修改檔案路徑和Components名稱來適應您想要新增到 AgentBuilder 的任何其他Components或自訂程式碼。

Search