Skip to content

[WIP](先别和入)Refactor memory extract#1045

Open
chenjw wants to merge 51 commits intomainfrom
refactor_memory_extract
Open

[WIP](先别和入)Refactor memory extract#1045
chenjw wants to merge 51 commits intomainfrom
refactor_memory_extract

Conversation

@chenjw
Copy link
Copy Markdown
Collaborator

@chenjw chenjw commented Mar 27, 2026

Description

Related Issue

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Performance improvement
  • Test update

Changes Made

Testing

  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have tested this on the following platforms:
    • Linux
    • macOS
    • Windows

Checklist

  • My code follows the project's coding style
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

Screenshots (if applicable)

Additional Notes

chenjw and others added 30 commits March 18, 2026 00:45
…on design document

- Add bilingual (English/Chinese) design document for memory templating system
- Include YAML-based MemoryTypeRegistry with 8 built-in types
- Detail ReAct 3+1 phase flow with pre-fetch optimization
- Describe 3-operation Schema: write/edit/delete
- Document RoocodePatch SEARCH/REPLACE format
- Explain dual-mode design: simple mode vs template mode
- Cover pre-fetch optimization: ls directories + read .abstract.md/.overview.md + search once
- Include merge operations: patch, sum, avg, immutable
- Address #578: allow custom prompt template addition and specification

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add YAML-configurable memory schemas (cards, events, entities, etc.)
- Implement MemoryReAct with tool use (read/find/ls)
- Add schema-driven memory operations (write_uris/edit_uris/delete_uris)
- Implement memory patch handler for incremental updates
- Add comprehensive test suite
## Summary

Implement memory templating system (GitHub Issue #578) - a complete
rewrite of the memory extractor subsystem to support YAML-configurable
memory types instead of hardcoded categories.

## Key Changes

### Architecture
- Replace hardcoded 8 memory types with YAML-configurable schema system
- Add MemoryTypeRegistry to load memory type definitions from YAML files
- Dynamic Pydantic model generation from schema for type safety
- Field-level merge operations: PATCH, SUM, IMMUTABLE

### Memory Extraction Flow
- Implement ReAct orchestrator for single-pass memory updates
- MemoryUpdater for applying operations to storage
- Memory tools (read, search, ls) for ReAct loop
- Stable JSON parser with 5-layer fault tolerance

### File Naming & Storage
- Semantic filenames from template ({topic}.md instead of random IDs)
- Two memory modes: simple mode and template mode
- MEMORY_FIELDS HTML comment for structured metadata

### Configuration
- 9 YAML templates in openviking/prompts/templates/memory/
- memory_config.py for memory system configuration
- Dual-threshold compact upload mechanism in design doc

### Deletions
- Remove old memory_content.py, memory_data.py, memory_operations.py
- Remove memory_types.py, memory_utils.py, memory_patch.py
- Remove corresponding old test files

### Updated Components
- VLM backends (litellm, openai, volcengine) for new interfaces
- Session and service core integration
- Test suite for new architecture

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
## Summary

Fix missing parameters in commit_async() when calling extract_long_term_memories().
The synchronous commit() method correctly passes these parameters, but the async
version was missing them, causing memory extraction to be skipped.

## Changes

- Pass user=self.user, session_id=self.session_id, ctx=self.ctx
  in commit_async() when calling extract_long_term_memories()

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
## Summary

Fix JSON serialization error by converting FindResult object to dict
using its to_dict() method before returning from MemorySearchTool.

## Changes

- In MemorySearchTool.execute(), return search_result.to_dict()
  instead of search_result directly

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Also rename schema_models.py to schema_model_generator.py for clarity.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…zation

- Add edit_overview_operations to MemoryUpdater for updating .overview.md files
- Optimize MemoryTypeRegistry initialization in SessionCompressorV2 (load once)
- Various memory templating system improvements

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Also fix duplicate line in system prompt.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- MemoryUpdater now vectorizes written/edited memory files after apply_operations
- MemoryReAct generates overview following semantic.overview_generation.yaml format
- Auto-extract and write .abstract.md from overview in memory_updater
- Fix import: VikingURI is from openviking_cli.utils.uri

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Change vikingbot gateway to openviking-server --with-bot
- Change vikingbot chat to ov chat
- Update --no-markdown to --no-format
- Remove --logs flag (not available)
- Simplify CLI Reference table
- Also update Chinese README_CN.md

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Convert from pytest to standalone script with:
- SyncHTTPClient instead of AsyncHTTPClient
- Rich for pretty console output
- Phase control (ingest/verify/all)
- Better error handling and progress display

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Remove duplicate logger and create_session_compressor in session/__init__.py
- Remove duplicate MemoryConfig import in open_viking_config.py

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Parse function_call type responses (Responses API format)
- Fix cache key logic to use consistent "current" messages
- Fix previous_response_id not being passed when tools exist
- Fix tool call parsing to handle both tc.name and tc.function.name
- Preserve tool role info and image content in message conversion

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

Failed to generate code suggestions for PR

chenjw and others added 13 commits March 28, 2026 01:55
- search 工具无论是否有结果都记录到 messages 中
- refetch 时如果已达最大迭代次数,允许额外增加一次迭代
- 使用局部变量 max_iterations 避免修改实例属性

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- 优化 tools.py 工具定义和消息格式
- memory_react.py 支持 refetch 时额外迭代
- 更新 memory_updater, patch, utils 等模块
- 更新测试文件

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- 参考 vikingdb BaseModelCompat 创建 FaultTolerantBaseModel
- 在 model_validator(mode='before') 中自动做字段容错
- schema_model_generator 动态模型继承 FaultTolerantBaseModel
- extract_loop 删除 fallback 代码
- 修复 skills.yaml 模板变量缺失问题

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
在模板变量中始终传入 extract_context,避免 Jinja2 访问时 undefined

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- 简化模板,移除复杂表达式计算
- 添加 default 过滤器处理缺失变量

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
移除 extract_context 调用,添加 default 过滤器

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
用 {% if extract_context %} 判断避免 None 时报错

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- 使用 jinja2.DebugUndefined,未定义变量保留在输出中而不是报错
- 修复测试文件添加 extract_context 参数

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
使用 parse_memory_file_with_fields 清理内容后再提取 abstract

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- 使用 parse_memory_file_with_fields 清理内容后再提取 abstract
- 修复 _extract_abstract_from_overview 和向量索引两处

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
支持 "7,9,11,13" 格式的单个索引,与范围格式混用

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

1 participant