ClawSkills logoClawSkills

Vanar Neutron Memory

使用 Vanar Neutron API 存储和检索代理记忆。用于通过语义搜索保存信息,并在会话之间持久化代理上下文。

介绍

# Vanar Neutron Memory

为 AI 智能体提供的具有语义搜索功能的持久化内存存储。将文本作为种子(seeds)保存,进行语义搜索,并在会话之间持久化智能体上下文。

## 功能特性

- **自动回忆 (Auto-Recall)**:在每个 AI 轮次前自动查询相关记忆并注入为上下文 - **自动捕获 (Auto-Capture)**:在每个 AI 轮次后自动保存对话 - **语义搜索**:使用 Jina Embeddings v4 (1024 维) 通过含义查找记忆 - **记忆类型**:情景记忆、语义记忆、程序记忆和工作记忆 - **区块链证明**:带有交易哈希的防篡改记忆存储

## 前置条件

在以下地址获取您的 API 密钥:**https://openclaw.vanarchain.com/**

通过环境变量提供 API 凭证: ```bash export NEUTRON_API_KEY=your_key export NEUTRON_AGENT_ID=your_agent_id export YOUR_AGENT_IDENTIFIER=your_agent_name_or_id # agent_id name or defaults to 1 ```

或存储在 `~/.config/neutron/credentials.json` 中: ```json { "api_key": "your_key_here", "agent_id": "your_agent_id_here", "your_agent_identifier": "your_agent_name_or_id" } ```

## 测试

验证您的设置: ```bash ./scripts/neutron-memory.sh test # Test API connection ```

## 钩子 (自动捕获 & 自动回忆)

该技能包含用于自动内存管理的 OpenClaw 钩子:

- `hooks/pre-tool-use.sh` - **自动回忆**:在 AI 轮次前查询记忆,注入相关上下文 - `hooks/post-tool-use.sh` - **自动捕获**:在 AI 轮次后保存对话

### 配置

这两项功能**默认启用**。如需禁用:

```bash export VANAR_AUTO_RECALL=false # Disable auto-recall export VANAR_AUTO_CAPTURE=false # Disable auto-capture ```

或添加到您的凭证文件中: ```json { "api_key": "your_key_here", "agent_id": "your_agent_id_here", "your_agent_identifier": "your_agent_name_or_id", "auto_recall": true, "auto_capture": true } ```

## 脚本

使用 `scripts/` 目录中提供的 bash 脚本: - `neutron-memory.sh` - 主 CLI 工具

## 常用操作

### 将文本保存为种子 ```bash ./scripts/neutron-memory.sh save "Content to remember" "Title of this memory" ```

### 语义搜索 ```bash ./scripts/neutron-memory.sh search "what do I know about blockchain" 10 0.5 ```

### 创建智能体上下文 ```bash ./scripts/neutron-memory.sh context-create "my-agent" "episodic" '{"key":"value"}' ```

### 列出智能体上下文 ```bash ./scripts/neutron-memory.sh context-list "my-agent" ```

### 获取特定上下文 ```bash ./scripts/neutron-memory.sh context-get abc-123 ```

## 交互种子 (双重存储)

当 NeutronMemoryBot 处理交互时,它会将数据存储在两个位置:

1. **智能体上下文** - 用于结构化元数据和会话跟踪的截断摘要 2. **种子** - 用于语义搜索的完整线程快照

每次机器人回复评论时,**完整线程**(原始帖子 + 所有评论 + 机器人的回复)都会被保存为一个种子。这意味着:

- 每个种子都是一个完整的对话快照 - 后续的种子比早期的种子包含更多的上下文 - 语义搜索可以找到最相关的对话状态 - 仅追加:添加新的快照,旧的快照保持不变

### 种子格式

``` Thread snapshot - {timestamp}

Post: {full post content}

Comments: {author1}: {comment text} {author2}: {comment text} NeutronMemoryBot: {reply text} ```

## API 端点

- `POST /seeds` - 保存文本内容 (multipart/form-data) - `POST /seeds/query` - 语义搜索 (JSON body) - `POST /agent-contexts` - 创建智能体上下文 - `GET /agent-contexts` - 列出上下文 (可选 `agentId` 过滤器) - `GET /agent-contexts/{id}` - 获取特定上下文

**认证:** 所有请求都需要 `Authorization: Bearer $NEUTRON_API_KEY` 请求头和 `appId`/`externalUserId` 查询参数。

**记忆类型:** `episodic`(情景)、`semantic`(语义)、`procedural`(程序)、`working`(工作)

**种子的文本类型:** `text`、`markdown`、`json`、`csv`、`claude_chat`、`gpt_chat`、`email`

更多产品