Memori Extension Skill
Memory augmentation and LLM call interception using the Memori Python library with optional Zhipu AI API integration.
Overview
This skill provides memory augmentation and LLM call interception capabilities using the Memori Python library. It enables agents to retrieve relevant knowledge from a memory database and inject it into conversations.
Security & Privacy Notice
⚠️ Important: This skill performs the following operations:
File Operations (Always Enabled)
- - Read/Write: Local SQLite database (default:
./memori.db) - Read/Write: Optional tech terms configuration file (default:
./config/tech_terms.txt) - These operations are entirely local and do not transmit data externally.
External API Calls (Optional - Requires Explicit Configuration)
- - Condition: Only if
ZHIPUAI_API_KEY environment variable is set - Data Transmitted: Conversation text (user messages, system prompts, and assistant responses) is sent to Zhipu AI's servers for analysis and augmentation
- Purpose: To enhance conversation understanding using Zhipu AI's language models
- Control: If
ZHIPUAI_API_KEY is NOT set, the skill operates 100% locally with NO external network calls
Recommendations
- 1. Start Local-Only: Test the skill without
ZHIPUAI_API_KEY first to verify local functionality - Explicit Consent: Only set
ZHIPUAI_API_KEY if you explicitly consent to sending conversation data to external services - Review Data: Consider what conversation data you're comfortable transmitting before enabling external API features
- Sandbox Testing: If providing API keys, test in a sandbox environment first to understand the data flow
Dependencies
This skill requires the following Python packages:
CODEBLOCK0
The memori library is licensed under Apache License Version 2.0.
Optional Dependencies
For Zhipu API augmentation (optional):
CODEBLOCK1
Warning: Installing zhipuai and providing ZHIPUAI_API_KEY enables conversation content to be sent to external servers.
Environment Variables
All Supported Environment Variables
| Variable | Description | Required | Default | Privacy Note |
|---|
| INLINECODE8 | Zhipu AI API key for conversation augmentation | No | - | ⚠️ Enables external API calls - conversation text will be sent to Zhipu AI servers |
| INLINECODE9 |
Zhipu AI model name |
No |
glm-4.7 | Only used if
ZHIPUAI_API_KEY is set |
|
MEMORI_TECH_TERMS | Comma-separated technical terms for LLM interception |
No | - | Local only |
|
MEMORI_TECH_TERMS_FILE | Path to file containing technical terms (one per line) |
No |
./config/tech_terms.txt | Local only - read/write |
|
MEMORI_DB_PATH | Path to Memori database |
No |
./memori.db | Local only - read/write |
Privacy & Data Flow Notes:
- - ⚠️ External API: Only
ZHIPUAI_API_KEY enables external network calls. All other variables control local file operations. - ✅ Local-Only Mode: If you omit
ZHIPUAI_API_KEY, the skill operates 100% locally with no external data transmission. - 📁 File Operations: The skill reads/writes the database (
memori.db) and optionally the tech terms file (tech_terms.txt). These are stored on your local filesystem. - 🔒 Best Practice: Start without
ZHIPUAI_API_KEY to test local functionality. Only enable external API if you need enhanced features and consent to the data transmission.
Configuration Examples
System environment:
CODEBLOCK2
OpenClaw configuration (openclaw.json):
CODEBLOCK3
Technical terms file (optional):
CODEBLOCK4
Quick Start
Method 1: Direct Memori Library (Recommended)
CODEBLOCK5
Method 2: Skill Convenience API
CODEBLOCK6
API Reference
Memori Class
__init__(db_path, entity_id)
Initialize Memori instance.
Parameters:
- -
db_path (str | Path, optional): Database path - INLINECODE25 (str, optional): Entity ID, default INLINECODE26
search(query, limit, entity_id)
Search for relevant memories.
Returns: INLINECODE28
augment(query, limit, entity_id)
Augment query with retrieved memories.
Returns: INLINECODE30
store(content, entity_id, metadata)
Store a new memory.
Returns: int - Memory ID
get_stats(entity_id)
Get statistics.
Returns: INLINECODE34
close()
Close database connection.
Memory Class
Memory object with attributes:
- -
id (int): Memory ID - INLINECODE37 (str): Entity ID
- INLINECODE38 (str): Memory content
- INLINECODE39 (str): Creation timestamp
- INLINECODE40 (dict, optional): Metadata
AugmentedContext Class
Augmented context with:
- -
original_query (str): Original query - INLINECODE42 (List[Memory]): Retrieved memories
- INLINECODE43 (str): Augmented prompt
- INLINECODE44 (bool): Whether memories were retrieved
- INLINECODE45 (int): Number of retrieved memories
Configuration
Database
Default database path: INLINECODE46
The skill will:
- - ✅ Read from the database to retrieve memories
- ✅ Write to the database when storing new memories
- ✅ Create the database file if it doesn't exist
Technical Terms
The skill uses configurable technical terms for LLM call interception. You can customize these via:
1. Environment variable (comma-separated):
CODEBLOCK7
2. Configuration file (one term per line):
CODEBLOCK8
Note: If neither is set, the skill will still work but may not intercept technical queries as effectively.
Security Considerations
File Operations
This skill performs the following file operations:
| Operation | File | Description |
|---|
| Read | INLINECODE47 (default) | Retrieve stored memories |
| Write |
./memori.db (default) | Store new memories |
| Read |
MEMORI_TECH_TERMS_FILE | Load technical terms |
| Write |
MEMORI_TECH_TERMS_FILE | Persist terms (if enabled) |
External API Calls
⚠️ Important: If ZHIPUAI_API_KEY is set, this skill may send conversation text to Zhipu AI's servers for augmentation.
To disable external API calls:
- - Simply don't set INLINECODE52
- The skill will work normally using local memory retrieval only
Recommendations
- 1. Review the code before enabling external API features
- Test in a sandbox first if providing API keys
- Use file permissions to protect database and config files
- Only enable features you explicitly need
File Structure
CODEBLOCK9
License
This skill is licensed under Apache License Version 2.0.
This skill uses the memori Python library, which is also licensed under Apache License Version 2.0.
Attribution
This skill incorporates the Memori Python library, which is licensed under the Apache License 2.0.
See the LICENSE file for the complete license text.
Memori Library:
- - Copyright 2025 Memori Team
- License: Apache License 2.0
- Repository:
Memori 扩展技能
使用 Memori Python 库实现记忆增强和 LLM 调用拦截,可选配智谱 AI API 集成。
概述
本技能利用 Memori Python 库提供记忆增强和 LLM 调用拦截功能。它使智能体能够从记忆数据库中检索相关知识并将其注入对话中。
安全与隐私声明
⚠️ 重要提示:本技能执行以下操作:
文件操作(始终启用)
- - 读取/写入:本地 SQLite 数据库(默认路径:./memori.db)
- 读取/写入:可选的技术术语配置文件(默认路径:./config/tech_terms.txt)
- 这些操作完全在本地进行,不会向外部传输数据。
外部 API 调用(可选 - 需要显式配置)
- - 条件:仅当设置了 ZHIPUAIAPIKEY 环境变量时
- 传输数据:对话文本(用户消息、系统提示和助手回复)将被发送至智谱 AI 服务器进行分析和增强
- 目的:利用智谱 AI 的语言模型增强对话理解能力
- 控制:如果未设置 ZHIPUAIAPIKEY,本技能将 100% 在本地运行,不进行任何外部网络调用
建议
- 1. 先本地运行:在不设置 ZHIPUAIAPIKEY 的情况下测试技能,验证本地功能
- 明确同意:仅在您明确同意将对话数据发送至外部服务时才设置 ZHIPUAIAPIKEY
- 审查数据:在启用外部 API 功能前,考虑您愿意传输哪些对话数据
- 沙箱测试:如果提供 API 密钥,先在沙箱环境中测试以了解数据流向
依赖项
本技能需要以下 Python 包:
bash
pip install memori
memori 库采用 Apache License Version 2.0 许可。
可选依赖项
用于智谱 API 增强(可选):
bash
pip install zhipuai
警告:安装 zhipuai 并提供 ZHIPUAIAPIKEY 将使对话内容被发送至外部服务器。
环境变量
所有支持的环境变量
| 变量 | 描述 | 必需 | 默认值 | 隐私说明 |
|---|
| ZHIPUAIAPIKEY | 用于对话增强的智谱 AI API 密钥 | 否 | - | ⚠️ 启用外部 API 调用 - 对话文本将被发送至智谱 AI 服务器 |
| ZHIPUAIMODEL |
智谱 AI 模型名称 |
否 | glm-4.7 | 仅在设置了 ZHIPUAIAPI_KEY 时使用 |
| MEMORI
TECHTERMS | 用于 LLM 拦截的逗号分隔技术术语 |
否 | - | 仅本地 |
| MEMORI
TECHTERMS
FILE | 包含技术术语的文件路径(每行一个) | 否 | ./config/techterms.txt | 仅本地 - 读取/写入 |
| MEMORI
DBPATH | Memori 数据库路径 |
否 | ./memori.db | 仅本地 - 读取/写入 |
隐私与数据流说明:
- - ⚠️ 外部 API:仅 ZHIPUAIAPIKEY 启用外部网络调用。所有其他变量控制本地文件操作。
- ✅ 仅本地模式:如果省略 ZHIPUAIAPIKEY,本技能将 100% 在本地运行,不进行外部数据传输。
- 📁 文件操作:本技能读取/写入数据库(memori.db)和可选的技术术语文件(techterms.txt)。这些文件存储在您的本地文件系统中。
- 🔒 最佳实践:先在不设置 ZHIPUAIAPI_KEY 的情况下测试本地功能。仅在需要增强功能且同意数据传输时才启用外部 API。
配置示例
系统环境:
bash
可选:启用智谱 API 增强
export ZHIPUAI
APIKEY=your-api-key
export ZHIPUAI_MODEL=glm-4.7
可选:自定义技术术语
export MEMORI
TECHTERMS=FFI,Rust,Linux,kernel,spinlock
可选:使用自定义数据库路径
export MEMORI
DBPATH=/path/to/memori.db
OpenClaw 配置(openclaw.json):
json
{
skills: {
entries: {
memori-extension: {
enabled: true,
env: {
ZHIPUAIAPIKEY: your-api-key,
ZHIPUAI_MODEL: glm-4.7,
MEMORITECHTERMS: FFI,Rust,Linux,kernel,
MEMORIDBPATH: ./memori.db
}
}
}
}
}
技术术语文件(可选):
bash
创建配置目录
mkdir -p config
创建术语文件
cat > config/tech_terms.txt << EOF
FFI
Rust
Linux
kernel
spinlock
mutex
unsafe
EOF
设置环境变量
export MEMORI
TECHTERMS
FILE=config/techterms.txt
快速开始
方法 1:直接使用 Memori 库(推荐)
python
from memori import Memori
memori = Memori(
db_path=memori.db,
entity_id=knowledge-base
)
搜索记忆
memories = memori.search(query, limit=5)
增强查询
context = memori.augment(如何处理自旋锁冲突?, limit=3)
存储记忆
memory_id = memori.store(新内容)
获取统计信息
stats = memori.get_stats()
关闭连接
memori.close()
方法 2:技能便捷 API
python
from skills.memoriextension import search, augment, interceptllm
搜索
memories = search(FFI 绑定, limit=5)
增强
enhanced = augment(如何处理自旋锁冲突?)
if enhanced:
print(enhanced)
拦截 LLM
messages = [{role: user, content: FFI 问题}]
enhanced = intercept_llm(messages)
API 参考
Memori 类
init(dbpath, entityid)
初始化 Memori 实例。
参数:
- - dbpath(str | Path,可选):数据库路径
- entityid(str,可选):实体 ID,默认值为 default
search(query, limit, entity_id)
搜索相关记忆。
返回: List[Memory]
augment(query, limit, entity_id)
使用检索到的记忆增强查询。
返回: AugmentedContext
store(content, entity_id, metadata)
存储新记忆。
返回: int - 记忆 ID
getstats(entityid)
获取统计信息。
返回: dict
close()
关闭数据库连接。
Memory 类
具有以下属性的记忆对象:
- - id(int):记忆 ID
- entityid(str):实体 ID
- content(str):记忆内容
- createdat(str):创建时间戳
- metadata(dict,可选):元数据
AugmentedContext 类
增强上下文包含:
- - originalquery(str):原始查询
- retrievedmemories(List[Memory]):检索到的记忆
- enhancedprompt(str):增强后的提示
- hasmemories(bool):是否检索到记忆
- memories_count(int):检索到的记忆数量
配置
数据库
默认数据库路径:./memori.db
本技能将:
- - ✅ 读取数据库以检索记忆
- ✅ 写入数据库以存储新记忆
- ✅ 创建数据库文件(如果不存在)
技术术语
本技能使用可配置的技术术语进行 LLM 调用拦截。您可以通过以下方式自定义:
1. 环境变量(逗号分隔):
bash
export MEMORITECHTERMS=FFI,Rust,Linux,kernel,spinlock,mutex,unsafe
2. 配置文件(每行一个术语):
bash
创建配置文件
mkdir -p config
cat > config/tech_terms.txt << EOF
FFI
Rust
Linux
kernel
spinlock
mutex
unsafe
EOF
设置环境变量
export MEMORI
TECHTERMS
FILE=config/techterms.txt
注意:如果两者均未设置,技能仍可