在 Activepieces 中集成 Flowise 无代码 AI 工作流:Piece 认证、预测动作与构建指南
【免费下载链接】activepiecesAI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents项目地址: https://gitcode.com/GitHub_Trending/ac/activepieces
本文围绕 Activepieces 官方社区 Flowise Piece(README 与 src/index.ts)展开,讲解如何在 Activepieces 流程与 AI Agent 中调用 Flowise 上已部署的 Chatflow(聊天流 / RAG / Agent 工作流)完成推理预测。读完本文,你将掌握 Flowise Piece 的认证配置、Make Prediction动作的参数与请求格式、Custom API Call 的底层机制,以及该 Piece 的本地构建与多语言资源组织方式。
一、Flowise Piece 是什么
Flowise 是一款无代码 AI 工作流构建器,用户可以拖拽编排 LLM、向量数据库、检索器等节点,生成并部署一个对外提供推理能力的 Chatflow。Activepieces 中的 Flowise Piece 正是这座"桥":它把 Flowise 部署好的 Chatflow 封装成 Activepieces 的 Action,让自动化流程或 AI Agent 能直接向/api/v1/prediction/{chatflow_id}发送问题并拿回模型输出。
从 src/index.ts 的 Piece 元数据可以看出它的定位:
export const flowise = createPiece({ displayName: 'Flowise', description: 'No-Code AI workflow builder', logoUrl: 'https://cdn.activepieces.com/pieces/flowise.png', auth: flowiseAuth, minimumSupportedRelease: '0.30.0', categories: [PieceCategory.ARTIFICIAL_INTELLIGENCE], authors: ["aasimsanim","kishanprmr","MoShizzle","abuaboud"], actions: [flowisePredict, createCustomApiCallAction({ ... })], triggers: [], });关键信息:
- 分类:
PieceCategory.ARTIFICIAL_INTELLIGENCE,在动作面板的 AI 分类下展示; - 版本兼容:
minimumSupportedRelease: '0.30.0',要求 Activepieces 运行时不低于 0.30.0 版本; - 能力边界:只提供 Actions(
flowisePredict+ 通用Custom API Call),无触发器(triggers: [])——它只能被流程主动调用,不会主动向 Activepieces 推送事件; - 认证:
flowiseAuth自定义认证,统一管理 Flowise 实例地址与 API Key。
createPiece的实现位于 packages/pieces/framework/src/lib/piece.ts,它会将 actions 按名称注册到内部 Map,并在metadata()中输出displayName、actions、triggers、categories、auth、minimumSupportedRelease等完整元数据,供 Activepieces 平台加载与展示。
二、认证配置:Flowise URL 与 API Key
Flowise Piece 使用PieceAuth.CustomAuth定义认证,见 src/index.ts:
const flowiseAuth = PieceAuth.CustomAuth({ description: 'Enter your Flowise URL and API Key', props: { base_url: Property.ShortText({ displayName: 'Base URL', description: 'Enter the base URL', required: true, }), access_token: PieceAuth.SecretText({ displayName: 'API Key', description: 'Enter the API Key', required: true, }), }, required: true, });配置项说明:
| 字段 | 类型 | 必填 | 含义 |
|---|---|---|---|
base_url | Property.ShortText | 是 | Flowise 实例的根地址,例如自托管部署的http://localhost:3000或云端域名 |
access_token | PieceAuth.SecretText | 是 | Flowise 的 API Key,用于Authorization: Bearer <key>请求头 |
其中access_token使用SecretText类型,属于敏感凭据字段,在界面上以密文形式输入与存储;CustomAuth框架类型定义在 custom-auth-prop.ts 中,其 props 支持ShortText、LongText、Number、Checkbox、StaticDropdown、SecretText等组合,Flowise 正好用了最常见的"地址 + 密钥"组合。
认证提示:一个 Activepieces Connection 对应一个 Flowise 实例。若你有多套 Flowise 环境(开发/生产),可分别建立 Connection,在流程中按需选择。
三、核心动作:Make Prediction
flowisePredict是 Flowise Piece 的主动作,动作名make_prediction,显示名 "Make Prediction",负责"向指定 Chatflow 发送问题并返回预测结果",见 src/index.ts。
3.1 输入参数
props: { chatflow_id: Property.ShortText({ displayName: 'Chatflow ID', required: true }), input: Property.ShortText({ displayName: 'Input/Question', required: true }), history: Property.Json({ displayName: 'History', required: false }), overrideConfig: Property.Json({ displayName: 'Override Config', required: false }), }| 参数 | 类型 | 必填 | 作用 |
|---|---|---|---|
chatflow_id | 短文本 | 是 | 目标 Chatflow 的唯一标识(在 Flowise 的 Chatflow 页面 URL/API 面板中可见) |
input | 短文本 | 是 | 发送给 Chatflow 的问题/输入 |
history | JSON | 否 | 可选的会话历史,用于多轮对话上下文 |
overrideConfig | JSON | 否 | 运行时覆盖配置,可临时覆盖 Chatflow 内的节点配置(如切换模型参数、修改 Prompt 等) |
3.2 底层请求逻辑
run函数的实现直接印证了调用链(src/index.ts):
const url = `${base_url}/api/v1/prediction/${chatflow_id}`; const headers = { 'Content-Type': 'application/json', Authorization: `Bearer ${access_token}`, }; const body = { question: input, history: ctx.propsValue['history'], overrideConfig: ctx.propsValue['overrideConfig'], }; const response = await fetch(url, { method: 'POST', headers, body: JSON.stringify(body), }); const data = await response.json(); return data;要点:
- 端点:
POST {base_url}/api/v1/prediction/{chatflow_id},与源码注释中的/api/v1/prediction/{your-chatflowid}一致; - 请求体:
question携带问题文本,history与overrideConfig仅在配置了对应 props 时随请求体透传; - 认证方式:
BearerToken 头; - 返回值:直接返回 Flowise 的完整 JSON 响应(包含模型生成的文本、所用 Chatflow 信息等),Activepieces 不会做二次解析,下游步骤可通过变量引用其中的字段。
3.3 AI Agent 语义元数据
源码中还为该动作声明了aiMetadata(src/index.ts):
aiMetadata: { description: 'Sends a question/input to a specific Flowise chatflow by its Chatflow ID and returns the prediction, optionally passing prior conversation history and runtime override config...', idempotent: false, }这告诉 AI Agent:调用前需要明确的 Chatflow ID;由于每次调用都会生成一次全新的模型响应,该动作不是幂等的。对于把 Flowise Chatflow 作为 Agent 工具的开发者来说,这段元数据会被 Agent 用于理解何时调用、需要准备哪些参数。
四、附加能力:Custom API Call
除了专用的Make Prediction,Flowise Piece 还通过createCustomApiCallAction暴露了一个通用 HTTP 动作,覆盖 Flowise 其余 API 端点(src/index.ts):
createCustomApiCallAction({ baseUrl: (auth) => (auth?.props.base_url ?? ''), auth: flowiseAuth, authMapping: async (auth) => ({ Authorization: `Bearer ${auth.props.access_token}`, }), })其底层实现在 packages/pieces/common/src/lib/helpers/index.ts:
- 动态 URL:
baseUrl由认证连接中的base_url计算得出,URL 支持绝对地址或相对路径; - 自动注入认证:
authMapping生成的Authorization: Bearer <access_token>会被自动附加到请求头,无需手动填写; - 通用参数:
Method(GET/POST/PUT/PATCH/DELETE/HEAD 等)、Headers、Query Parameters、Body Type(JSON / Form Data / Raw / None)、Body、Timeout (in seconds)、Follow redirects、Response is Binary、No Error on Failure等; - 用途:可用于调用 Flowise 的其他管理类接口(例如查询 Chatflow 列表、上传向量数据等),作为
Make Prediction的补充。
需要说明:Make Prediction动作的 audience 为'both'(同时面向人类流程与 Agent),而createCustomApiCallAction生成的动作为'human'面向,默认分类为WRITE,这一点在编排 AI Agent 工具选择时需要注意。
五、多语言资源
Flowise Piece 内置了完整的 i18n 文案资源,位于 src/i18n 目录,包含de、es、fr、ja、nl、pt、ru、vi、zh以及默认translation.json共 10 份语言文件。以 zh.json 为例,它为 "Base URL"、"API Key"、"Make Prediction"、"Custom API Call"、"Chatflow ID"、"History"、"Override Config" 以及 Custom API Call 的 Method、Body Type、Timeout 等 UI 文案提供了本地化映射。因此,不同语言环境下的用户界面会呈现对应的本地化标签,而动作名称(make_prediction)与接口行为保持一致。
六、构建与发布
根据 Piece 的 README,构建该库的唯一必需命令是:
turbo run build --filter=@activepieces/piece-flowise该命令利用 Turborepo 按包名@activepieces/piece-flowise过滤并构建。结合 package.json 中的脚本,可以进一步了解完整工具链:
{ "name": "@activepieces/piece-flowise", "version": "0.1.7", "scripts": { "build": "tsc -p tsconfig.lib.json && cp package.json dist/", "bundle": "node ../../../../dist/packages/cli/src/index.js pieces bundle", "lint": "eslint 'src/**/*.ts'" }, "dependencies": { "@activepieces/pieces-common": "workspace:*", "@activepieces/pieces-framework": "workspace:*", "@activepieces/core-piece-types": "workspace:*", "@activepieces/core-utils": "workspace:*" } }- build:先用
tsc按tsconfig.lib.json编译 TypeScript 源码到dist/,再把package.json复制进产物目录; - bundle:调用 Activepieces CLI 的
pieces bundle命令打包该 Piece 的产物与资源,供平台分发给安装方; - lint:对
src/**/*.ts执行 ESLint 检查; - 依赖:均以 workspace 形式引用
pieces-common、pieces-framework、core-piece-types、core-utils等仓库内包,保证与当前 Activepieces 主版本 API 对齐。
在仓库中构建该 Piece 时,先确保根目录依赖已安装(仓库使用 bun + turbo 工作区),再执行上述turbo run build --filter=@activepieces/piece-flowise即可得到dist/产物。Piece 的版本号(当前 0.1.7)由package.json维护,升级行为与构建打包在发布流程中由仓库的发布脚本统一处理。
七、典型应用场景
把 Flowise Piece 放进 Activepieces 流程或 Agent 工具集中,常见的组合方式包括:
- RAG 问答自动化:当收到新消息(Webhook / 邮件 / 表单触发)时,把消息内容作为
input传给已部署的 Flowise RAG Chatflow,再把返回的答案写回 Slack、发邮件或入库; - AI Agent 的领域工具:将
Make Prediction注册为 Agent 工具,让 Agent 在需要领域推理(如内部知识库问答)时调用 Flowise Chatflow,history支持携带对话上下文,overrideConfig可临时切换模型或 Prompt; - 多轮对话:把上一轮
history透传给 Chatflow,实现有记忆的连续会话,history采用 JSON 结构,由上游步骤的变量填充。
需要留意:Make Prediction每次调用都会触发一次真实模型推理,产生新的响应(非幂等),在编排重试或批处理任务时需考虑调用成本与频次;所有请求均以BearerToken 认证,API Key 通过 Activepieces 的连接(Connection)机制加密保存,不应以明文形式出现在流程变量中。
结语
Flowise Piece 是 Activepieces AI 生态中连接"无代码工作流构建器"与"自动化编排平台"的典型实现:通过CustomAuth统一管理实例地址与密钥,通过Make Prediction动作封装/api/v1/prediction/{chatflow_id}推理接口,并用Custom API Call保留对 Flowise 全量 API 的访问能力。其源码结构清晰(认证定义、动作实现、Piece 注册、i18n 资源分层),是阅读与二次开发 Activepieces 社区 Piece 的良好范本。
【免费下载链接】activepiecesAI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents项目地址: https://gitcode.com/GitHub_Trending/ac/activepieces
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考