导入 Langflow 流程
本演练将一个从 Langflow 导出的流程——Basic Prompting,即 Langflow 1.6.0 自带的入门项目——导入为一个 Aggregate、一个 Release 和一个 Manifest,它们按原样即可为 Docker Compose 构建承载该流程的 Langflow;随后构建它们并运行结果。下文的每个文件和每段输出都来自一次真实运行;流程和演练的每个阶段都位于 import-langflow 示例中,那里的检查脚本会再次运行导入,将它写入的内容、打印的内容以及本页引用的代码块与保存在那里的文件进行比较,并验证和构建导入写入的内容。
生成示例
你可以使用本页的命令运行此导入,也可以让你的 AI 助手替你运行。
将示例写入一个以其命名的新文件夹:
aggrega scaffold --example import-langflow然后它会打印接下来要运行的命令。第一条命令进入新文件夹;其后的一条命令见下文,它进入新文件夹的 source 文件夹,导入就在这里运行。该文件夹包含流程文件 basic-prompting.json,本页对其进行描述而不是引用:
cd import-langflow
流程
Basic Prompting 串联了四个节点:一个 Chat Input、一个 Prompt、一个调用 OpenAI gpt-4.1 的 Language Model,以及一个 Chat Output。按 Langflow 自带的形式,它是一个约 54 KB 的 JSON 文件 basic-prompting.json,除流程外还携带了每个组件的源代码。其 Language Model 节点从全局变量 OPENAI_API_KEY 读取密钥;在未存储该名称的变量时,Langflow 会从其环境中读取该变量。
在流程旁边,一个 .aggrega-config.yaml 使该文件夹成为工作区:
# The workspace key marks this directory as the workspace root, so an import run# here writes its drafts beside basic-prompting.json.workspace: {}# The registry the importer is fetched from the first time an import needs it.default_registry: hub.aggrega.ai而 import-answers.yaml 保存的是任何流程都无法保存的内容的答案。面向 Docker Compose 的导入不需要其中任何一个:它通过变量引用附加每个机密,由 Docker Compose 从你的 shell 中填充。面向 Kubernetes 的导入通过 Kubernetes Secret 的名称附加每个机密,而这个名称只有你能指定,因此该文件指定了该导入所要求的两个 Secret(参见 在 Kubernetes 上):
# Values the import could not draft from the source, keyed by the drafted file and the key path inside# it. Write each one beside its key; an import of the same source, and a sync, read them from here and# ask nothing. A secret is never written here: its key asks where the secret comes from — a variable# name, ${NAME}, or the name of a Kubernetes Secret.release.yaml: # The origin of the secret value, written by the operator in the Release. Read exactly as # values.origin is. Write it here or in values.origin, never in both. A secret: name where it comes # from, never the value. spec.components.langflow.features.admin_password.infra.origin: "langflow-admin" # The origin of the secret value, written by the operator in the Release. Read exactly as # values.origin is. Write it here or in values.origin, never in both. A secret: name where it comes # from, never the value. spec.components.langflow.uses.model.languagemodelcomponent-kboja.features.credential.infra.origin: "openai-api-key"每个答案都是一个 Secret 的名称,而绝不是机密本身,因此该文件可以与流程一起保存。导入答案文件 完整描述了该文件。
导入会将每个节点与工作区目录中的 Components 进行比对评估,而 --target 会根据该目录的 Recipes 起草一个 Manifest。工作区没有指定目录文件夹,因此导入会从获取其导入器的注册表中读取标准库目录:这是已发布目录的一个签名快照,由第一次导入获取、验证并保存在工作区的内容缓存中,并在导入写在其草稿旁的记录中以其摘要标明。指定了自己的目录文件夹的工作区——在 AGGREGA_CATALOG_DIRS 中,或在 workspace.catalog_dirs 下——则改为针对这些文件夹进行导入。进入 source:
cd source运行导入
aggrega import basic-prompting.json --target compose它在标准输出上列出所写的内容:
wrote aggregate.yamlwrote release.yamlwrote manifest.yamlwrote .aggrega-import.json在标准错误上,其中 <workspace> 代表你运行它的文件夹:
[… omitted: a warning that the importer runs unverified, printed where its module is read from beside its Plugin entity in a catalog folder rather than fetched]read as the langflow format, with drafted paths relative to <workspace>warn: the flow is carried in values.flow_definition with the handles of all 3 of its edges written as Langflow's editor writes them — the same handles, their keys in order with no space between them — since the editor compares an edge's handles with the ones it writes for the nodes the edge joins, character for character, when it opens the flow, and drops every edge whose handles differwarn: node LanguageModelComponent-kBOja reaches languagemodelcomponent-kboja through the model connection languagemodelcomponent-kboja of core/ai-agent/langflow: its field api_key names the variable OPENAI_API_KEY, which the platform delivers for this connection and Langflow reads as a global variable; no field of it gives its API's address, so the OpenAI client it runs takes OPENAI_BASE_URL, the address the platform delivers for this connection, from the environmentmade no choice for ChatInput-SzjnT (ChatInput)made no choice for Prompt-tOH5D (Prompt)made no choice for ChatOutput-8ZWWB (ChatOutput)mapped LanguageModelComponent-kBOja (LanguageModelComponent) to core/ai-model/openai as a reference, HIGH at 0.9 warning: node "langflow" (provider "compose"): artifact "langflow-flow/langflow-flow.yaml": skipped provenance label injection — the fragment declares no compose service. Compose carries build provenance as service labels, so a fragment contributing only top-level networks, volumes or configs carries none; the services this component emits elsewhere carry the full set.Pull complete: <workspace>/release.lock (entities=8, source_artifacts=0, external_inputs=0)
mapped行说明 Language Model 节点变成了什么:标准库的 OpenAI 模型core/ai-model/openai,以引用而非起草的方式出现,因为它以 0.9 的分数在高等级中匹配。它是一个独立的组件,连接到平台的model插槽。默认情况下,草稿在运行 Langflow 的平台上运行整个流程,只有当某个节点能被该平台的某个插槽接收——模型、工具、向量存储——且该节点被识别为此类节点时,才会为其提供独立的组件。- 第一条
warn行说明流程在携带时,每条边的句柄都按 Langflow 编辑器的写法写出。Langflow 保存其入门项目时,在边句柄中的每个冒号和逗号后都留有一个空格;而其编辑器在打开流程时,会丢弃所有句柄写法与它自己的写法不完全一致的边,然后在没有这些边的情况下保存流程。按这种方式写出后,流程打开时带有它的三个连接,并以这些连接运行。 - 指明该节点的
warn行说明流程如何到达该模型。该节点从变量OPENAI_API_KEY读取密钥,从OPENAI_BASE_URL读取地址,而平台为模型连接提供这两者,因此流程无需修改。 made no choice行列出平台的任何插槽都不接收的节点:它们保留在流程内部,由 Langflow 按导出时的原样运行。- 最后两行是拉取。没有剩下需要回答的内容,因此导入拉取了所起草 Release 的依赖项,与
aggrega pull的做法相同,并写入了release.lock;下面的构建不再需要其他任何东西。warning行构建时也会打印,验证与构建对其进行了说明。
答案文件指定了两个此次导入并未要求的 Secret:导入没有为它们留下任何空缺,因此两者都不应用,并保持该文件原样。
它写出的内容
该 Aggregate、Release 和 Manifest 命名为 imported/basic-prompting,取自流程自身的名称 Basic Prompting,缩减为 basic-prompting——没有名称的流程按其文件命名——位于导入器的 target_namespace 设置所设定的命名空间下,除非你另行设置,否则该命名空间为 imported(设置)。
aggregate.yaml——标准库 Langflow 平台 core/ai-agent/langflow 的一个实例,按导出时的原样承载流程(只有边的句柄按 Langflow 编辑器的写法写出;此处省略了其中一千多行),以及流程所连接的模型:
apiVersion: aggrega.ai/v1beta1kind: Aggregatemetadata: name: imported/basic-prompting version: 0.1.0 description: Draft Aggregate imported from a source in the langflow format.spec: components: langflow: type: core/ai-agent/langflow features: # For the compose target, the lines below declare admin_password on langflow: a secret the Release alone attaches arrives under the key value, so each is declared with a key of its own and no two arrive under one; the Release attaches its origin, naming this type or none. admin_password: type: core/secret-value values: key: LANGFLOW_SUPERUSER_PASSWORD values: flow_id: '0dbee653-41ae-4e51-af2e-55757fb24be3' flow_definition: |- { "data": { "edges": [ [… omitted: the rest of the flow] } uses: model: languagemodelcomponent-kboja: target: languagemodelcomponent-kboja # For the compose target, the lines below declare credential on languagemodelcomponent-kboja: a secret the Release alone attaches arrives under the key value, so each is declared with a key of its own and no two arrive under one; the Release attaches its origin, naming this type or none. features: credential: type: core/secret-value values: key: OPENAI_API_KEY # swap to core/ai-model/azure-openai (score 0.4000) by setting type: core/ai-model/azure-openai languagemodelcomponent-kboja: type: core/ai-model/openai values: model: |- gpt-4.1- 模型是
core/ai-model/openai,使用流程节点所选的模型gpt-4.1。其上方的注释列出了该节点与之相似的目录中另一个 Component 及其分数,供想要使用那个 Component 的读者参考。 - 两个机密——Langflow 编辑器要求的管理员密码,以及平台提供给模型的 OpenAI 密钥——在此处声明,并各自带有其在 Langflow 环境中到达时所用的变量:
LANGFLOW_SUPERUSER_PASSWORD和OPENAI_API_KEY。在 Docker Compose 上,仅由 Release 附加的机密会以键value到达,两者会发生冲突;在此处声明后,每个机密都有自己的键。Release 说明每个机密的来源。 flow_id是导出内容为该流程指定的标识符。
release.yaml——该 Release,它使用该 Manifest 部署该 Aggregate:
apiVersion: aggrega.ai/v1beta1kind: Releasemetadata: name: imported/basic-prompting # environment is a drafted default, since no source names the environment this Release deploys to; change it to name the one it deploys to. environment: development version: 0.1.0 description: Draft Release imported from a source in the langflow format.spec: aggregate: imported/basic-prompting manifest: imported/basic-prompting components: langflow: infra: # The image running core/ai-agent/langflow, at the version this importer drafts, which the catalog's Recipes for it are known to run; the import does not raise or lower it to follow the source. The source states version "1.5.0" of the platform. image: "langflowai/langflow:1.6.0" # Published on this machine's loopback address, 127.0.0.1: reachable from this machine only, by any process running on it. Delete this line to keep the service internal. published_port: 7860 features: admin_password: type: core/secret-value infra: # Attached by reference, never as a value: the administrator's password, read while values.require_authentication stays true, read from the variable LANGFLOW_ADMIN_PASSWORD, which a target substituting variable references, as Docker Compose does when the stack starts, reads from the environment, so no file carries the value. origin: "${LANGFLOW_ADMIN_PASSWORD}" uses: model: languagemodelcomponent-kboja: features: credential: type: core/secret-value infra: # Attached by reference, never as a value: the credential langflow presents to languagemodelcomponent-kboja on its model connection, read from the variable OPENAI_API_KEY, which a target substituting variable references, as Docker Compose does when the stack starts, reads from the environment, so no file carries the value. origin: "${OPENAI_API_KEY}" languagemodelcomponent-kboja: {}environment为development,这是一个默认值,其上方的注释说明应将其改为该 Release 所部署到的环境。- 镜像是 Langflow 1.6.0,即目录中用于 Langflow 的 Recipes 所运行的版本。如注释所述,该流程最后一次在 Langflow 1.5.0 上测试;导入保留 Recipes 所运行的版本,而不是沿用流程的版本。
published_port为 7860,即 Langflow 提供服务的端口,因此编辑器在你的机器上通过http://127.0.0.1:7860响应。正如其注释所说,这台机器上的任何进程都可以在那里访问它,其他任何东西都不能;删除这一行即可让 Langflow 只位于栈的网络中。- 两个机密都是变量引用,即
${LANGFLOW_ADMIN_PASSWORD}和${OPENAI_API_KEY},Docker Compose 在栈启动时从你的 shell 中填充它们,因此没有任何文件包含其中任一值。
manifest.yaml——平台和模型的 Compose Recipes,以及将机密的变量引用原样写入 Compose 文件的实现:
apiVersion: aggrega.ai/v1beta1kind: Manifestmetadata: name: imported/basic-prompting version: 0.1.0spec: mappings: components: type: core/ai-agent/langflow: compose/langflow core/ai-model/openai: compose/openai features: type: core/secret-value: compose/dotenv-secret.aggrega-import.json 记录了导入所写入的内容,供之后的 aggrega import --sync 读取;release.lock 按版本和摘要锁定该 Release 所解析到的每个目录实体。
验证并构建
aggrega validate --release release.yamlaggrega build --release release.yaml

验证打印:
notice: LINT: Feature "core/secret-value" at core/secret-value:1.0.0 declares property "origin" in both values: and infra: pillars (path: origin)release dependency validation passed: release.yaml (schema-pillar + dependency pillars)以及构建,其中 <workspace> 代表包含草稿的文件夹:
warning: node "langflow" (provider "compose"): artifact "langflow-flow/langflow-flow.yaml": skipped provenance label injection — the fragment declares no compose service. Compose carries build provenance as service labels, so a fragment contributing only top-level networks, volumes or configs carries none; the services this component emits elsewhere carry the full set. notice: LINT: Feature "core/secret-value" at core/secret-value:1.0.0 declares property "origin" in both values: and infra: pillars (path: origin)[… omitted: a total build time, which differs per run]Build completed: 1 file written to <workspace>/distwarning 行涉及 Compose 文件中承载流程的部分,即一个顶层 configs 条目,它没有可供放置构建标签的服务。notice 行仅供参考:机密 Feature 从 Aggregate 的 values 或 Release 的 infra 接收其 origin,该通知报告有一个叶子节点在两处都有声明。两者都不会改变判定结果。
dist/compose/docker-compose.yaml 包含 Langflow,以及一个在它之前运行一次的服务:
services: langflow: image: langflowai/langflow:1.6.0 environment: LANGFLOW_CONFIG_DIR: /app/langflow LANGFLOW_SAVE_DB_IN_CONFIG_DIR: "true" LANGFLOW_AUTO_LOGIN: "false" LANGFLOW_SUPERUSER: admin LANGFLOW_SUPERUSER_PASSWORD: ${LANGFLOW_ADMIN_PASSWORD} OPENAI_BASE_URL: https://api.openai.com/v1 OPENAI_API_KEY: ${OPENAI_API_KEY} LANGFLOW_LOAD_FLOWS_PATH: /app/flows ports: - 127.0.0.1:7860:7860 [… omitted: the labels the build writes on every service, naming the Aggregate, the component, the environment and the compiler's version] volumes: - type: volume source: langflow--data target: /app/langflow networks: - compose depends_on: langflow--data-owner: condition: service_completed_successfully [… omitted: the service's health check] configs: - source: langflow-flow target: /app/flows/flow.json langflow--data-owner: image: langflowai/langflow:1.6.0 entrypoint: - chown - "1000:0" - /app/langflow [… omitted: the labels the build writes on every service] volumes: - type: volume source: langflow--data target: /app/langflow networks: - compose restart: "no" user: "0"流程以 /app/flows/flow.json 的形式到达 Langflow,来源是一个保存 Aggregate 所携带流程的 configs 条目,Langflow 在每次启动时从 LANGFLOW_LOAD_FLOWS_PATH 加载它。密钥和密码都是变量引用,在栈启动时从你的 shell 中填入。只有当 Release 在 Langflow 的 infra 中设置了 published_port 时,Langflow 的 Compose Recipe 才会在你的机器上发布端口,而且只发布在回环地址 127.0.0.1 上;没有该设置时,只能在栈的网络中访问该服务。
langflow--data-owner 以 root 身份运行 Langflow 的镜像,将数据卷交给用户 1000、组 0,也就是 Langflow 镜像运行时所用的身份,然后退出。该服务完成之后 Langflow 才会启动:Docker 创建的卷归 root 所有,否则 Langflow 无法在其中写入数据。
借助 AI 助手
配置了 Aggrega 工具的 AI 助手也可以完成同样的操作:将下面的提示词粘贴给它。
只使用 Aggrega 工具,不要自行创建任何文件夹。如果 Workspace 文件夹中还没有 `import-langflow` 文件夹,请调用一次 `scaffold` 工具,将 `example` 设为 `import-langflow`,且不设 `dir`:它会把示例写入新的 `import-langflow` 文件夹,其中的 `source` 文件夹包含本页导入的内容。然后调用 `import` 工具,将 `workspace_root` 设为 `import-langflow/source`,`source` 设为 `basic-prompting.json`,`target` 设为 `compose`:它会从 `basic-prompting.json` 旁边的 `import-answers.yaml` 读取所需的回答,将草稿写入 `import-langflow/source`,并拉取草稿所需的内容。然后调用 `validate` 工具,将 `workspace_root` 设为 `import-langflow/source`,`release` 设为 `release.yaml`;再调用 `build` 工具,将 `workspace_root` 设为 `import-langflow/source`,`release` 设为 `release.yaml`,`write` 设为 true。告诉我构建写出了哪些文件;它们位于 `import-langflow/source/dist/` 下。在 VS Code 中打开
安装 Visual Studio Code 的 Aggrega 扩展 后,在 VS Code 中打开导入写入草稿的文件夹 import-langflow/source。该文件夹只包含一个 Release,即生成的 release.yaml,因此编辑器会为你选中它,并在你编辑草稿时根据该 Release 检查草稿,在文件中和“问题”面板中标出发现的内容。命令面板中的 Aggrega: Show topology graph 会绘制该 Release 的组件及其之间的连接。Aggrega: Build、Aggrega: Preview build 和 Aggrega: Pull 作用于同一个 Release,并且每个命令也是活动栏中 Aggrega 视图的 Commands 面板上的一个按钮;Build 会将文件写入该文件夹的 dist/ 中。其余内容见 在 Visual Studio Code 中使用 Aggrega。
运行
在你的 shell 中设置密钥和管理员密码,然后启动栈:
export OPENAI_API_KEY='your OpenAI key'export LANGFLOW_ADMIN_PASSWORD='a password of your own'docker compose -p basic-prompting -f dist/compose/docker-compose.yaml up -d --wait-p 为项目命名,如 导入如何运行 的运行步骤所述。--wait 会在 langflow--data-owner 完成且 Langflow 报告健康状态后返回。
测试
打开 http://127.0.0.1:7860(即 published_port 发布的地址),并使用你设置的密码以 admin 身份登录:Basic Prompting 就在编辑器中,带有它的三个连接。
Langflow 只为 API 密钥通过其 API 运行流程,该密钥由管理员登录后创建。登录:
curl -sS -X POST http://127.0.0.1:7860/api/v1/login \ -d username=admin --data-urlencode "password=$LANGFLOW_ADMIN_PASSWORD"{"access_token":"[… omitted: the access token]","refresh_token":"[… omitted: the refresh token]","token_type":"bearer"}使用访问令牌创建一个密钥:
curl -sS -X POST http://127.0.0.1:7860/api/v1/api_key/ \ -H 'Authorization: Bearer <access_token>' -H 'Content-Type: application/json' -d '{"name": "test-it"}'{"name":"test-it","last_used_at":null,"total_uses":0,"is_active":true,"id":"[… omitted: the key's identifier]","api_key":"[… omitted: the key]","user_id":"[… omitted: the owner's identifier]"}然后使用该密钥运行流程:
curl -sS -X POST 'http://127.0.0.1:7860/api/v1/run/0dbee653-41ae-4e51-af2e-55757fb24be3?stream=false' \ -H 'x-api-key: <api_key>' -H 'Content-Type: application/json' \ -d '{"input_value": "In one short sentence: what is Docker Compose?", "input_type": "chat", "output_type": "chat"}'本次运行为 OpenAI 密钥使用了占位符,因此得到的回答是 OpenAI 对该密钥的拒绝,这表明流程一直运行到了调用模型这一步:
{"detail":"{\"message\":\"Error running graph: Error building Component Language Model: \\n\\nError code: 401 - {'error': {'message': 'Incorrect API key provided: sk-place*****************-key. You can find your API key at https://platform.openai.com/account/api-keys.', 'type': 'invalid_request_error', 'code': 'invalid_api_key', 'param': None}, 'status': 401}\",[… omitted: three empty fields, and a suggestion to update three of the flow's components]}"}使用你的密钥时,回复会在 outputs[0].outputs[0].results.message.text 处携带模型的回答。
在 Kubernetes 上,应用 在 Kubernetes 上 所述的构建后,将一个本地端口转发到你所应用的命名空间中 Langflow 的 Service langflow-default,并让该命令保持运行:
kubectl port-forward -n <namespace> svc/langflow-default 7860:7860在另一个终端中,上面的三个请求原样通过同一地址到达 Langflow;本次运行得到了对占位符密钥的同样拒绝。
使用下面的命令停止栈。-v 还会删除 Langflow 的数据卷,连同管理员账户、API 密钥和流程的运行历史一起删除:
docker compose -p basic-prompting -f dist/compose/docker-compose.yaml down -v在 Kubernetes 上
同一个流程可以使用 helm 目标为 Kubernetes 导入。面向 Docker Compose 的草稿已经位于 source 中,而导入从不覆盖那里的 Aggregate,因此请使用 --output-dir 将这些草稿生成到单独的文件夹中,然后从该文件夹进行验证和构建:
aggrega import basic-prompting.json --target helm --output-dir helmcd helmaggrega validate --release release.yamlaggrega build --release release.yaml草稿在目标不同的地方有所不同。Manifest 将平台映射到 helm/langflow,将模型映射到 helm/openai,并将每个 secret 映射到 helm/k8s-existing-secret,后者从命名空间中已有的 Secret 读取它。Release 将这两个 secret 作为 core/referenced-secret 附加,每个都指明对应的 Secret,而这些名称正是应答文件所保存的内容:
features: admin_password: type: core/referenced-secret infra: # Left for the Release, since the source cannot supply it: the name of a Kubernetes Secret already in the namespace holding, under the data key value, the administrator's password, read while values.require_authentication stays true. origin: "langflow-admin"如果没有应答文件,导入会在终端中询问这两个名称,并将你的回答写入一个新的应答文件。在无法询问的情况下,它会写入包含这两个键且回答为空的该文件,并以状态 1 和下面这一行结束,其中 <workspace> 代表你运行它的文件夹:
2 values the drafts leave empty are still owed, listed in the answers file <workspace>/import-answers.yaml: write each beside its key there, then run the import again构建会在工作区根目录 source 下的 dist/helm/ 中写出普通的 Kubernetes 清单,从 helm 来看即 ../dist/helm/。在你要应用到的命名空间中创建这两个 Secret,每个都在数据键 value 下保存其值,然后按照 导入如何运行 中运行步骤的说明应用该文件夹。