Replies: 3 comments 2 replies
-
|
simple mode 例如 entities.yaml 也有多个 memory fields to extract 但没有设置 content_template. 这种情况怎么组织 memory content ? |
Beta Was this translation helpful? Give feedback.
1 reply
-
|
牛批又完整的设计 :)
Guidelines... Good Cases... Bad Cases...
|
Beta Was this translation helpful? Give feedback.
1 reply
-
🦞 非常详细的设计!作为 AI Agent 系统的运营者,这个记忆系统重构设计令人印象深刻。 关键亮点
与 OpenClaw 的对比
建议
期待看到这个设计的实现!🦞 来自妙趣AI - AI工具导航与资讯平台 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Memory Extractor Templating and Update Mechanism Optimization / 记忆抽取模版与更新机制优化
Context / 上下文
Problem Background / 问题背景
Goals / 目标
Implement a memory templating system based on OpenViking storage, such that: / 实现基于 OpenViking 存储的记忆模版化系统,使得:
Reference Design / 参考设计
This design references the following core ideas from the
../memoryproject: / 本设计参考了../memory项目的以下核心思想:Two Memory Modes / 两种记忆模式
The system provides two memory modes, distinguished by whether
content_templateexists. / 系统提供两种记忆模式,用是否有content_template来区分。Simple Mode (without content_template) / 模式一:简单模式(无 content_template)
Use Cases: profile, preferences, entities, events, cases, patterns / 适用场景:profile、preferences、entities、events、cases、patterns
Characteristics: / 特点:
name,contenttwo fields (or a few simple fields) / 只有name、content两个字段(或简单的几个字段)contentis Markdown content, no rendering needed /content就是 Markdown 内容,不需要渲染MEMORY_FIELDScomment needed / 不需要MEMORY_FIELDS注释Config Examples / 配置示例:
profile.yaml
preferences.yaml
entities.yaml
events.yaml
cases.yaml
patterns.yaml
Memory File Storage Format Example / 记忆文件存储格式示例:
# User Profile User is an AI development engineer with 3 years of experience...Template Mode (with content_template) / 模式二:模板模式(有 content_template)
Use Cases: tools, skills / 适用场景:tools、skills
Characteristics: / 特点:
contentis rendered from fields viacontent_template/content是通过content_template从字段渲染出来的MEMORY_FIELDSJSON comment is always placed at the end of the file /MEMORY_FIELDSJSON 注释永远放在文件最后<!-- MEMORY_FIELDS -->comment at the end of Markdown file / 从 Markdown 文件最后的<!-- MEMORY_FIELDS -->注释中解析 JSON 字段merge_op/ 根据字段的merge_op做记忆更新content_templateafter update / 更新后通过content_template重新渲染 Markdown 内容MEMORY_FIELDSback to end of file / 把更新后的MEMORY_FIELDS写回文件最后Config Examples / 配置示例:
tools.yaml
skills.yaml
Memory File Storage Format Example / 记忆文件存储格式示例:
Overall Architecture / 整体架构
Core Components Design / 核心组件设计
1. Memory Data Structures / 记忆数据结构
1.1 MemoryField (Memory Field Definition / 记忆字段定义)
Field properties / 字段属性:
Special fields / 特殊字段:
content: Default Markdown content field, only this field is used in simple mode / 默认的 Markdown 内容字段,简单模式下只用这个字段abstract: L0 summary field (one-sentence summary for indexing) / L0 摘要字段(用于索引的一句话摘要)overview: L1 overview field (structured Markdown summary) / L1 概览字段(结构化 Markdown 摘要)1.2 MemoryType (Memory Type Definition / 记忆类型定义)
Type properties / 类型属性:
content_template example (for tools type) / content_template 示例(用于 tools 类型):
1.3 MemoryData (Dynamic Memory Data / 动态记忆数据)
Data properties / 数据属性:
2. ReAct Flow Data Structures / ReAct 流程数据结构
2.1 Reasoning + Action (Phase 1: Reasoning Output / 阶段 1: 推理输出)
Available Tools (consistent with OpenViking VikingFS API) / 可使用的工具(与 OpenViking VikingFS API 保持一致):
read
uri: str, offset: int = 0, limit: int = -1find
query: str, target_uri: str = "", limit: int = 10, score_threshold: Optional[float] = None, filter: Optional[Dict] = Nonels
uri: str, output: str = "agent", abs_limit: int = 256, show_all_hidden: bool = False, node_limit: int = 1000tree
uri: str = "viking://", output: str = "agent", abs_limit: int = 256, show_all_hidden: bool = False, node_limit: int = 1000, level_limit: int = 3Important / 重要: No function calls like add_memory/update_memory/delete_memory, add/edit/delete operations are model's final output as MemoryOperations, directly executed by system / 没有 add_memory/update_memory/delete_memory 这样的 function call,增删改操作通过模型最终输出 MemoryOperations,由系统直接执行
2.2 MemoryOperations (Phase 2: Final Output / 阶段 2: 最终输出)
3. Patch Handler / Patch 处理器
3.1 Content-level Patch (SEARCH/REPLACE) / 内容级 Patch (SEARCH/REPLACE)
3.2 Field-level Patch / 字段级 Patch
Handle according to field's merge_op / 根据字段的 merge_op 处理:
4. MemoryTypeRegistry (Type Registry / 类型注册表)
Features / 功能:
openviking/session/memory/schemas// 默认从openviking/session/memory/schemas/加载内置类型5. MemoryReActOrchestrator (ReAct Orchestrator / ReAct 编排器)
Workflow / 工作流:
Optimization Strategy / 优化策略: To avoid excessive time from multiple ReAct rounds, system automatically performs pre-fetch before LLM reasoning / 为避免多次 ReAct 导致耗时过长,系统在 LLM 推理前自动执行前置读取:
Phase 0: Pre-fetch (system executes, before LLM reasoning) / 阶段 0: Pre-fetch(系统执行,LLM 推理前):
viking://user/{user_space}/memories/and subdirectories / 及子目录viking://agent/{agent_space}/memories/and subdirectories / 及子目录.abstract.md(L0) and.overview.md(L1) / 读取所有.abstract.md(L0) 和.overview.md(L1)Phase 1: Reasoning + Action: LLM analyzes conversation + Pre-fetched Context, outputs ReasoningAction / LLM 分析对话 + Pre-fetched Context,输出 ReasoningAction
Phase 2: Generate Operations: LLM generates MemoryOperations based on existing memories (final output) / LLM 基于现有记忆生成 MemoryOperations(最终输出)
Phase 3: System Execute: System directly executes MemoryOperations / 系统直接执行 MemoryOperations
6. MemoryUpdater (Patch Applier - System Execution / Patch 应用器 - 系统执行)
Features / 功能:
7. Structured Output Implementation / 结构化输出实现
Based on the implementation from ../memory project, the following tech stack is used / 基于 ../memory 项目的实现方案,采用以下技术栈:
7.1 Core Components / 核心组件
Pydantic BaseModel: Used to define all data structures / 用于定义所有数据结构
json_repair: Fault-tolerant LLM output parsing / 容错解析 LLM 输出
Pydantic TypeAdapter: Type validation and conversion / 类型验证和转换
BaseModelCompat: Compatibility base class (refer to ../memory) / 兼容性基类(参考 ../memory)
7.2 JSONAdapter Flow / JSONAdapter 流程
7.3 Fault Tolerance Strategy / 容错策略
JSON Parsing Fault Tolerance / JSON 解析容错:
Type Validation Fault Tolerance / 类型验证容错:
Field Fault Tolerance / 字段容错:
Existing Design Analysis / 现有设计分析
Current Architecture / 当前架构
Storage / 存储方式
File Storage: L0/L1/L2 three-level structure / L0/L1/L2 三层结构
.abstract.md- summary / 摘要.overview.md- overview / 概览URI Structure:
viking://user/{space}/memories/{category}/viking://agent/{space}/memories/{category}/Vector Index: stored in context collection of VikingDB / 存储在 VikingDB 的 context 集合中
Key Files / 关键文件
openviking/session/memory_extractor.pyopenviking/session/memory_deduplicator.pyopenviking/session/compressor.pyopenviking/prompts/templates/compression/memory_extraction.yamlImplementation Steps / 实施步骤
Phase 1: Core Data Structures / 核心数据结构
Create
openviking/session/memory/memory_data.py/ 创建openviking/session/memory/memory_data.pyCreate
openviking/session/memory/memory_operations.py/ 创建openviking/session/memory/memory_operations.pyCreate
openviking/session/memory/memory_react.py/ 创建openviking/session/memory/memory_react.pyCreate
openviking/session/memory/memory_functions.py/ 创建openviking/session/memory/memory_functions.pyPhase 2: Patch Handling / Patch 处理
openviking/session/memory/memory_patch.py/ 创建openviking/session/memory/memory_patch.pyPhase 3: Type Registration / 类型注册
Create
openviking/session/memory/memory_types.py/ 创建openviking/session/memory/memory_types.pyCreate YAML config files / 创建 YAML 配置文件
openviking/session/memory/schemas/directory / 放在openviking/session/memory/schemas/目录Phase 4: MemoryUpdater
openviking/session/memory/memory_updater.py/ 创建openviking/session/memory/memory_updater.pyPhase 5: ReAct Orchestrator / ReAct 编排器
openviking/session/memory/memory_react.py/ 完善openviking/session/memory/memory_react.pyPhase 6: Prompt Templates / 提示模板
Create LLM prompt templates / 创建 LLM 提示模板
Create new memory_extractor_v2.py / 创建新的 memory_extractor_v2.py
Phase 7: Testing and Verification / 测试与验证
Unit tests / 单元测试
Integration tests / 集成测试
File List / 文件清单
New Files / 新增文件
Preserved Files / 保留文件
ReAct Flow Details / ReAct 流程详细说明
Phase 0: Pre-fetch (Pre-fetch - System Execution / 前置读取 - 系统执行)
Purpose / 目的: Avoid excessive time from multiple ReAct rounds / 避免多次 ReAct 导致耗时过长
System automatically executes / 系统自动执行:
viking://user/{user_space}/memories/and subdirectories / 及子目录viking://agent/{agent_space}/memories/and subdirectories / 及子目录.abstract.md(L0) and.overview.md(L1) / 读取所有.abstract.md(L0) 和.overview.md(L1)Output / 输出: Pre-fetched Context (directory structure + L0/L1 summaries + search results) / Pre-fetched Context(目录结构 + L0/L1 摘要 + 搜索结果)
Phase 1: Reasoning + Action (Reasoning + Action / 推理 + 行动)
Input / 输入: Conversation history + Pre-fetched Context / 对话历史 + Pre-fetched Context
LLM Task / LLM 任务: Analyze conversation + Pre-fetched Context, identify memories that need changes + decide if additional reads are needed / 分析对话 + Pre-fetched Context,识别需要变更的记忆 + 决定是否需要额外读取
Output / 输出: ReasoningAction (reasoning + optional additional actions) / ReasoningAction(reasoning + 可选的额外 actions)
System Execution / 系统执行: Execute additional read operations in actions (if needed) / 执行 actions 中的额外读取操作(如需要)
Phase 2: Generate Operations (Generate Final Operations / 生成最终操作)
Input / 输入: Conversation history + Reasoning + read existing memories / 对话历史 + Reasoning + 读取的现有记忆
LLM Task / LLM 任务: Generate specific operations based on existing memories / 基于现有记忆生成具体的操作
Output / 输出: MemoryOperations (model final output) / MemoryOperations(模型最终输出)
Important / 重要: This is the model's final output, directly executed by system, no more function calls / 这是模型的最后输出,直接由系统执行,不再通过 function call
Phase 3: System Execute (System Execution / 系统执行)
Input / 输入: MemoryOperations
Execution / 执行: MemoryUpdater.apply_operations() directly applies patch, writes to OpenViking Storage / MemoryUpdater.apply_operations() 直接应用 patch,写入 OpenViking Storage
Summary / 总结
This design is based on practices from ../memory project, uses ReAct pattern: / 本设计基于 ../memory 项目的实践,采用 ReAct 模式:
0. Pre-fetch: System automatically pre-fetches directories, L0/L1, search results / Pre-fetch: 系统自动前置读取目录、L0/L1、搜索结果
Beta Was this translation helpful? Give feedback.
All reactions