ARTICLE DETAIL

资讯详情

深耕网站视觉设计与运营推广的一线实战洞察。

Hindsight × Flowise 集成指南:在 Flowise 工作流中接入 Retain / Recall / Reflect 长期记忆工具

Hindsight × Flowise 集成指南:在 Flowise 工作流中接入 Retain / Recall / Reflect 长期记忆工具 Hindsight × Flowise 集成指南在 Flowise 工作流中接入 Retain / Recall / Reflect 长期记忆工具【免费下载链接】hindsightHindsight: Agent Memory That Learns项目地址: https://gitcode.com/GitHub_Trending/hindsight2/hindsight导读vectorize-io/flowise-nodes-hindsightv0.1.0 是 Hindsight 官方发布的 Flowise 集成包它把 Hindsight 的长期记忆能力封装成三个可直接拖入 Flowise 画布的 Tool 节点——Hindsight Retain记忆写入、Hindsight Recall记忆检索、Hindsight Reflect记忆问答让任何 Flowise chatflow 或 Agent 流都能获得跨会话的持久记忆。本文将围绕该集成的 0.1.0 版本发布完整梳理其安装方式、凭据配置、三个节点的输入/输出 schema、示例对话流程并结合仓库源码剖析其底层实现与测试保障帮助你在 Flowise 中快速落地会学习的 Agent 记忆。一、版本发布概览v0.1.0 带来了什么根据 Hindsight 官方 changelog 页面 flowise.md 的记录v0.1.0 是 Flowise 集成的首个版本核心特性是Added Flowise integration for Hindsight, enabling use of Hindsight memory tools within Flowise workflows.即在 Flowise 工作流内直接使用 Hindsight 记忆工具。该版本由 benfrank241 贡献commit41ad2b55以 npm 包vectorize-io/flowise-nodes-hindsight的形式对外分发。集成包的定位见 package.json非常明确名称vectorize-io/flowise-nodes-hindsight描述Flowise tool nodes for Hindsight - persistent memory for any Flowise chatflow or agent许可证MIT运行要求Node.js 20.15核心依赖langchain/core^1.1.48提供DynamicStructuredTool、vectorize-io/hindsight-client^0.5.6Hindsight 官方 TypeScript 客户端、zod^3.23.0用于声明工具输入 schema与仓库中其他集成如 aider、claude-code 等不同Flowise 集成采用三个 Tool 节点 一个共享凭据类的形态节点以 LangChain 工具的形式插槽到 Flowise 的工具连接点中可被任何 LangChain Agent 直接调用。二、仓库结构与源码布局集成源码位于 hindsight-integrations/flowise目录组织如下hindsight-integrations/flowise/ ├── credentials/ │ └── HindsightApi.credential.ts # Hindsight API 凭据类 ├── nodes/ │ └── tools/ │ ├── HindsightRetain/ # 记忆写入节点 │ ├── HindsightRecall/ # 记忆检索节点 │ └── HindsightReflect/ # 记忆问答节点 ├── src/ │ ├── Interface.ts # Flowise 上游类型的本地 shim │ └── utils.ts # 工具函数 shim转发自 Interface.ts ├── tests/ │ ├── credential.test.ts # 凭据类测试 │ └── nodes.test.ts # 三个节点的单测 ├── CHANGELOG.md # 集成自身的变更日志 ├── README.md # 安装与使用说明 ├── package.json / tsconfig.json / vitest.config.ts一个值得注意的设计细节三个节点源文件里使用的是上游相对导入如../../../src/Interface、../src/Interface这正是 Flowise 官方 monorepopackages/components/内的深路径导入方式。为了让这些源文件能1:1 原样复制进 Flowise 官方仓库src/Interface.ts 和 src/utils.ts 提供了本地 shim在构建与测试时通过vitest.config.ts/tsconfig.json的路径别名将上游相对导入重定向到本地实现。也就是说同一个源文件既能在本仓库独立开发测试也能不加修改地提交到 Flowise 上游对应 CHANGELOG.md 中Source files use upstream-relative imports and copy 1:1 into FlowiseAI/Flowise/packages/components/的描述。三、安装在本地 Flowise 开发分支中使用节点由于 Flowise 官方只在主 monorepo 内分发节点集成包的上游 PR 尚未合入前READMEhindsight-integrations/flowise/README.md给出了一套复制到 Flowise checkout的本地安装流程# 1. 克隆 Flowise 官方仓库仓库地址请自行获取官方源并进入目录 cd Flowise # 2. 复制三个工具节点到 Flowise 组件目录 cp -r hindsight 仓库路径/hindsight-integrations/flowise/nodes/tools/Hindsight* \ packages/components/nodes/tools/ # 3. 复制凭据类 cp hindsight 仓库路径/hindsight-integrations/flowise/credentials/HindsightApi.credential.ts \ packages/components/credentials/ # 4. 在 components 包中添加 Hindsight 客户端依赖 cd packages/components pnpm add vectorize-io/hindsight-client # 5. 安装依赖并构建 cd ../.. pnpm install pnpm build # 6. 启动 Flowise浏览器打开 http://localhost:3000 pnpm start安装完成后在 Flowise 画布的工具Tools分类下即可找到Hindsight Retain、Hindsight Recall、Hindsight Reflect三个节点节点元数据中category: Tools、icon: hindsight.png见各节点源码构造函数。四、凭据配置Hindsight API三个节点共享同一个凭据类hindsightApiHindsightApi.credential.ts在 Flowise 中创建Hindsight API类型的凭据即可复用字段类型默认值说明API URLstringhttps://api.hindsight.vectorize.ioHindsight API 的 Base URL。默认指向 Hindsight Cloud自托管实例请改为自己的地址如http://localhost:8888API Keypassword空Hindsight Cloud 的 API 密钥以hsk_开头可选——未启用鉴权的自托管实例可留空从源码看节点在init()中通过getCredentialParam(apiUrl, credentialData, nodeData)读取凭据若未配置则回退到 Cloud 默认地址API Key 仅在非空时传给客户端...(apiKey ? { apiKey } : {})见三个节点的init()实现。关于凭据解析src/Interface.ts 的getCredentialParam实现明确了取值优先级节点 inputs 中显式配置的值优先于凭据记录中的值nodeData.inputs优先其次才读credentialData。这意味着你可以在节点级覆盖凭据里的 URL 或 Key实现同一凭据、不同端点的灵活部署。五、三个工具节点详解三个节点都通过init()返回一个 LangChainDynamicStructuredTool用 zod schema 声明输入并调用vectorize-io/hindsight-client的对应方法。下面逐一拆解。5.1 Hindsight Retain把对话内容写进记忆库节点标识labelHindsight RetainnamehindsightRetainversion 1.0工具名hindsight_retain节点级输入Default Bank ID可选——当 Agent 未传 bankId 时使用的默认记忆库记忆库首次使用时自动创建工具输入 schemaAgent 传入见 HindsightRetain.ts参数类型必填说明bankIdstring是要写入的 Hindsight 记忆库 IDcontentstring是要存储的自由文本内容。调用返回后Hindsight 会异步抽取结构化事实tagsstring[]否附加到该条记忆上的标签列表实现原理func内部先做 bankId 兜底bankId || defaultBankId若两者都为空则返回错误提示Error: bankId is required (no default bank configured on the node).随后仅在 tags 非空时构造{ tags }选项并调用client.retain(targetBank, content, opts)最终返回{ bankId, success: true, response }的 JSON 字符串。注意其工具描述明确提示 Agent在调用返回后事实抽取是异步发生的——写入接口不阻塞对话后续记忆由 Hindsight 后台管线消化。5.2 Hindsight Recall按查询检索相关记忆节点标识labelHindsight RecallnamehindsightRecallversion 1.0工具名hindsight_recall节点级输入Default Bank ID可选Default Budget枚举low/mid/high默认mid工具输入 schema见 HindsightRecall.ts参数类型必填说明bankIdstring是要检索的记忆库 IDquerystring是描述检索意图的自然语言查询budgetenum(low,mid,high)否检索预算越高搜索越多记忆、成本也越高maxTokensnumber正整数否检索结果最多返回的 token 数tagsstring[]否按标签过滤检索结果实现原理func同样先解析目标 bankId缺失则报错然后构造{ budget: budget || defaultBudget }选项按需追加maxTokens与tags最后调用client.recall(targetBank, query, opts)并将完整响应序列化为 JSON 字符串返回给 Agent。从工具描述看它的定位是在回答用户之前先检索过往上下文——即记忆的读取侧为对话提供 grounding 依据。5.3 Hindsight Reflect跨记忆生成 LLM 综合回答节点标识labelHindsight ReflectnamehindsightReflectversion 1.0工具名hindsight_reflect节点级输入Default Bank ID可选Default Budgetlow/mid/high默认mid工具输入 schema见 HindsightReflect.ts参数类型必填说明bankIdstring是要反思的记忆库 IDquerystring是要基于记忆库回答的问题budgetenum(low,mid,high)否反思预算越高考虑更多记忆、成本越高实现原理与 Recall 的返回排名结果不同Reflect 调用client.reflect(targetBank, query, { budget })返回的是LLM 综合后的回答——它会跨多条记忆合成答案适合what do we know about X? 或 what should we do? 这类开放式问题。工具描述中将其定位为记忆的消化/推理侧。5.4 三个节点的共性机制统一凭据三者共享hindsightApi凭据credentialNames: [hindsightApi]一次配置全节点可用结构化工具baseClasses为[节点类型, DynamicStructuredTool, StructuredTool, BaseTool, Tool]由getBaseClasses(DynamicStructuredTool)推导因此能插入 Flowise 的 Tool 插槽并被任意 LangChain Agent 调用默认值兜底所有节点都遵循Agent 传参优先、节点默认值兜底策略且都通过zod做运行时 schema 校验非法入参如负数maxTokens会在进入客户端前被拦截。六、典型示例会记住用户的对话 AgentREADME 给出了一个可直接复刻的对话式 Agent 配方hindsight-integrations/flowise/README.mdChatOpenAI或任意聊天 LLM作为语言模型Conversational Agent并挂载三个工具Hindsight Retain Hindsight Recall Hindsight Reflect在每个工具上把Default Bank ID设为user-${sessionId}按会话隔离每个用户的记忆库在 Agent 的系统提示中引导其回答前先调用 Recall、有意义的交流后调用 Retain——这样 Agent 就能跨会话记住用户偏好、历史决策与事实并基于记忆作答。这套配方充分利用了三个工具的分工Retain 负责写、Recall 负责查、Reflect 负责综合推理配合按sessionId划分的记忆库即可实现每个用户一个独立长期记忆空间的多租户记忆方案。七、测试与质量保障集成仓库内置了 Vitest 单元测试npm test运行vitest run配置见 vitest.config.ts测试对客户端做了 mockvi.mock(vectorize-io/hindsight-client)因此init()不会产生真实 HTTP 调用。credential.test.ts 验证凭据类name 为hindsightApi、label 为Hindsight API、apiUrl默认指向 Cloud、apiKey为 password 类型且可选覆盖自托管免鉴权场景nodes.test.ts 验证三个节点元数据正确label / name / category / icon / versioninit()返回名为hindsight_retain/hindsight_recall/hindsight_reflect的结构化工具且 schema 存在参数透传如client.retain收到(bankId, content, { tags })、client.recall收到(bankId, query, { budget, maxTokens, tags })、client.reflect收到(bankId, query, { budget })默认值兜底Agent 不传 bankId 时回退到节点配置的默认库不传 budget 时使用节点默认值。这些测试从侧面印证了 5.15.3 中描述的调用链与兜底逻辑也意味着你可以放心地把三个节点接入生产级 chatflow。八、版本演进与后续关注集成自身的变更日志记录在 hindsight-integrations/flowise/CHANGELOG.md0.1.0初始脚手架三个 Tool 节点Hindsight Retain / Recall / Reflect 共享hindsightApi凭据每个节点在init()中返回 LangChainDynamicStructuredTool可插入 Flowise 工具插槽与任意 LangChain Agent基于vectorize-io/hindsight-client^0.5.6 构建源文件使用上游相对导入可 1:1 复制进FlowiseAI/Flowise/packages/components/。由于 Flowise 官方仅在其主 monorepo 内分发节点用户可见的最终分发形态是合入 Flowise 上游的 PR节点位于packages/components/。因此后续关注两个来源即可本仓库 hindsight-integrations/flowise源码真相源含新版本变更日志与 Flowise 上游的组件更新。结语vectorize-io/flowise-nodes-hindsightv0.1.0 用最小的复杂度完成了 Hindsight 与 Flowise 的打通三个语义清晰的结构化工具节点覆盖记忆的写入—检索—综合完整链路共享一套凭据遵循 LangChain 工具标准且源码设计为可直接上游合入。无论你是想给 Flowise 对话流加上跨会话记忆还是研究如何为低代码 Agent 平台编写官方级工具节点这个集成都是一个值得直接上手的参考实现。【免费下载链接】hindsightHindsight: Agent Memory That Learns项目地址: https://gitcode.com/GitHub_Trending/hindsight2/hindsight创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
返回列表