Skip to content

内存管理工具

taskflow_memory 提供内存缓存和临时数据存储能力


📋 可用工具

工具名功能安全性
taskflow_memory_get获取缓存值✅ Low
taskflow_memory_set设置缓存值✅ Medium
taskflow_memory_delete删除缓存✅ Medium
taskflow_memory_clear清空缓存✅ High

🔧 工具详解

get

获取缓存值。

参数:

json
{
  "key": "string"          // 缓存键(必填)
}

示例:

Claude: 获取缓存中的用户信息

调用:

json
{
  "name": "taskflow_memory_get",
  "arguments": {
    "key": "user:123"
  }
}

返回:

json
{
  "success": true,
  "value": {"id": 123, "name": "Alice"},
  "expired": false
}

set

设置缓存值。

参数:

json
{
  "key": "string",         // 缓存键(必填)
  "value": {},             // 缓存值(必填)
  "ttl": 3600              // 过期时间(秒,可选)
}

示例:

Claude: 缓存用户信息,1 小时后过期

调用:

json
{
  "name": "taskflow_memory_set",
  "arguments": {
    "key": "user:123",
    "value": {"id": 123, "name": "Alice"},
    "ttl": 3600
  }
}

🔒 安全机制

1. 内存限制

限制项默认值
最大内存256 MB
最大键数10000
单个值大小1 MB

2. 自动清理

过期键会自动清理:

typescript
// 定期清理
setInterval(() => {
  memory.cleanupExpired();
}, 60000);

3. 敏感数据保护

以下键会被拒绝:

javascript
// ❌ 被拒绝的键
session:*
token:*
password:*
auth:*

💡 使用技巧

技巧一:会话缓存

Claude: 缓存当前会话状态

Claude 会使用内存工具存储会话数据。

技巧二:临时存储

Claude: 临时存储这个中间结果

Claude 会设置较短的 TTL。

技巧三:批量操作

Claude: 清空所有临时缓存

Claude 会调用 clear 工具。


🔗 相关链接


内存管理有问题随时问我

Released under the MIT License.