鱼皮AI导航
鱼皮AI导航
  • 主页
  • 社区
  • AI工具
  • AI知识库
  • AI提示词
  • MCP
  • Skills
  • AI学习资源
  • AI资讯
  • GitHub开源
登录/注册

agentdb-memory-patterns

实现基于持久化存储的智能体记忆管理,支持会话记忆、长期存储与模式学习,通过向量索引和分层结构高效组织上下文,结合推理引擎实现动态情境合成与优化,适用于构建具备持续学习能力的对话系统与自主代理。

数据与分析
访问 GitHub
文档Skills.MD
name
AgentDB Memory Patterns
description
Implement persistent memory patterns for AI agents using AgentDB. Includes session memory, long-term storage, pattern learning, and context management. Use when building stateful agents, chat systems, or intelligent assistants.

AgentDB Memory Patterns

What This Skill Does

Provides memory management patterns for AI agents using AgentDB's persistent storage and ReasoningBank integration. Enables agents to remember conversations, learn from interactions, and maintain context across sessions.

Performance: 150x-12,500x faster than traditional solutions with 100% backward compatibility.

Prerequisites

  • Node.js 18+
  • AgentDB v1.0.7+ (via agentic-flow or standalone)
  • Understanding of agent architectures

Quick Start with CLI

Initialize AgentDB

▼
bash
复制代码
# Initialize vector database npx agentdb@latest init ./agents.db # Or with custom dimensions npx agentdb@latest init ./agents.db --dimension 768 # Use preset configurations npx agentdb@latest init ./agents.db --preset large # In-memory database for testing npx agentdb@latest init ./memory.db --in-memory

Start MCP Server for Claude Code

▼
bash
复制代码
# Start MCP server (integrates with Claude Code) npx agentdb@latest mcp # Add to Claude Code (one-time setup) claude mcp add agentdb npx agentdb@latest mcp

Create Learning Plugin

▼
bash
复制代码
# Interactive plugin wizard npx agentdb@latest create-plugin # Use template directly npx agentdb@latest create-plugin -t decision-transformer -n my-agent # Available templates: # - decision-transformer (sequence modeling RL) # - q-learning (value-based learning) # - sarsa (on-policy TD learning) # - actor-critic (policy gradient) # - curiosity-driven (exploration-based)

Quick Start with API

▼
typescript
复制代码
import { createAgentDBAdapter } from 'agentic-flow/reasoningbank'; // Initialize with default configuration const adapter = await createAgentDBAdapter({ dbPath: '.agentdb/reasoningbank.db', enableLearning: true, // Enable learning plugins enableReasoning: true, // Enable reasoning agents quantizationType: 'scalar', // binary | scalar | product | none cacheSize: 1000, // In-memory cache }); // Store interaction memory const patternId = await adapter.insertPattern({ id: '', type: 'pattern', domain: 'conversation', pattern_data: JSON.stringify({ embedding: await computeEmbedding('What is the capital of France?'), pattern: { user: 'What is the capital of France?', assistant: 'The capital of France is Paris.', timestamp: Date.now() } }), confidence: 0.95, usage_count: 1, success_count: 1, created_at: Date.now(), last_used: Date.now(), }); // Retrieve context with reasoning const context = await adapter.retrieveWithReasoning(queryEmbedding, { domain: 'conversation', k: 10, useMMR: true, // Maximal Marginal Relevance synthesizeContext: true, // Generate rich context });

Memory Patterns

1. Session Memory

▼
typescript
复制代码
class SessionMemory { async storeMessage(role: string, content: string) { return await db.storeMemory({ sessionId: this.sessionId, role, content, timestamp: Date.now() }); } async getSessionHistory(limit = 20) { return await db.query({ filters: { sessionId: this.sessionId }, orderBy: 'timestamp', limit }); } }

2. Long-Term Memory

▼
typescript
复制代码
// Store important facts await db.storeFact({ category: 'user_preference', key: 'language', value: 'English', confidence: 1.0, source: 'explicit' }); // Retrieve facts const prefs = await db.getFacts({ category: 'user_preference' });

3. Pattern Learning

▼
typescript
复制代码
// Learn from successful interactions await db.storePattern({ trigger: 'user_asks_time', response: 'provide_formatted_time', success: true, context: { timezone: 'UTC' } }); // Apply learned patterns const pattern = await db.matchPattern(currentContext);

Advanced Patterns

Hierarchical Memory

▼
typescript
复制代码
// Organize memory in hierarchy await memory.organize({ immediate: recentMessages, // Last 10 messages shortTerm: sessionContext, // Current session longTerm: importantFacts, // Persistent facts semantic: embeddedKnowledge // Vector search });

Memory Consolidation

▼
typescript
复制代码
// Periodically consolidate memories await memory.consolidate({ strategy: 'importance', // Keep important memories maxSize: 10000, // Size limit minScore: 0.5 // Relevance threshold });

CLI Operations

Query Database

▼
bash
复制代码
# Query with vector embedding npx agentdb@latest query ./agents.db "[0.1,0.2,0.3,...]" # Top-k results npx agentdb@latest query ./agents.db "[0.1,0.2,0.3]" -k 10 # With similarity threshold npx agentdb@latest query ./agents.db "0.1 0.2 0.3" -t 0.75 # JSON output npx agentdb@latest query ./agents.db "[...]" -f json

Import/Export Data

▼
bash
复制代码
# Export vectors to file npx agentdb@latest export ./agents.db ./backup.json # Import vectors from file npx agentdb@latest import ./backup.json # Get database statistics npx agentdb@latest stats ./agents.db

Performance Benchmarks

▼
bash
复制代码
# Run performance benchmarks npx agentdb@latest benchmark # Results show: # - Pattern Search: 150x faster (100µs vs 15ms) # - Batch Insert: 500x faster (2ms vs 1s) # - Large-scale Query: 12,500x faster (8ms vs 100s)

Integration with ReasoningBank

▼
typescript
复制代码
import { createAgentDBAdapter, migrateToAgentDB } from 'agentic-flow/reasoningbank'; // Migrate from legacy ReasoningBank const result = await migrateToAgentDB( '.swarm/memory.db', // Source (legacy) '.agentdb/reasoningbank.db' // Destination (AgentDB) ); console.log(`✅ Migrated ${result.patternsMigrated} patterns`); // Train learning model const adapter = await createAgentDBAdapter({ enableLearning: true, }); await adapter.train({ epochs: 50, batchSize: 32, }); // Get optimal strategy with reasoning const result = await adapter.retrieveWithReasoning(queryEmbedding, { domain: 'task-planning', synthesizeContext: true, optimizeMemory: true, });

Learning Plugins

Available Algorithms (9 Total)

  1. Decision Transformer - Sequence modeling RL (recommended)
  2. Q-Learning - Value-based learning
  3. SARSA - On-policy TD learning
  4. Actor-Critic - Policy gradient with baseline
  5. Active Learning - Query selection
  6. Adversarial Training - Robustness
  7. Curriculum Learning - Progressive difficulty
  8. Federated Learning - Distributed learning
  9. Multi-task Learning - Transfer learning

List and Manage Plugins

▼
bash
复制代码
# List available plugins npx agentdb@latest list-plugins # List plugin templates npx agentdb@latest list-templates # Get plugin info npx agentdb@latest plugin-info <name>

Reasoning Agents (4 Modules)

  1. PatternMatcher - Find similar patterns with HNSW indexing
  2. ContextSynthesizer - Generate rich context from multiple sources
  3. MemoryOptimizer - Consolidate similar patterns, prune low-quality
  4. ExperienceCurator - Quality-based experience filtering

Best Practices

  1. Enable quantization: Use scalar/binary for 4-32x memory reduction
  2. Use caching: 1000 pattern cache for <1ms retrieval
  3. Batch operations: 500x faster than individual inserts
  4. Train regularly: Update learning models with new experiences
  5. Enable reasoning: Automatic context synthesis and optimization
  6. Monitor metrics: Use stats command to track performance

Troubleshooting

Issue: Memory growing too large

▼
bash
复制代码
# Check database size npx agentdb@latest stats ./agents.db # Enable quantization # Use 'binary' (32x smaller) or 'scalar' (4x smaller)

Issue: Slow search performance

▼
bash
复制代码
# Enable HNSW indexing and caching # Results: <100µs search time

Issue: Migration from legacy ReasoningBank

▼
bash
复制代码
# Automatic migration with validation npx agentdb@latest migrate --source .swarm/memory.db

Performance Characteristics

  • Vector Search: <100µs (HNSW indexing)
  • Pattern Retrieval: <1ms (with cache)
  • Batch Insert: 2ms for 100 patterns
  • Memory Efficiency: 4-32x reduction with quantization
  • Backward Compatibility: 100% compatible with ReasoningBank API

Learn More

  • GitHub: https://github.com/ruvnet/agentic-flow/tree/main/packages/agentdb
  • Documentation: node_modules/agentic-flow/docs/AGENTDB_INTEGRATION.md
  • MCP Integration: npx agentdb@latest mcp for Claude Code
  • Website: https://agentdb.ruv.io
数据与分析

快捷安装

复制到终端去安装 Skill

npxskillsaddruvnet/claude-flow--skill"agentdb-memory-patterns"
站长:程序员鱼皮 老鱼简历 商务合作 增值电信业务经营许可证
2026 鱼皮AI导航 | 沪ICP备19026706号-6
站长:程序员鱼皮 老鱼简历 商务合作 增值电信业务经营许可证
2026 鱼皮AI导航 | 沪ICP备19026706号-6
🔥热门工具
朱雀AI检测朱雀AI检测
朱雀AI检测助手朱雀AI检测助手
LovartLovart
老鱼简历老鱼简历
WritePass官网WritePass官网
面多多面多多
CursorCursor
星月写作星月写作
朱雀AI检测助手朱雀AI检测助手
零感AI零感AI
Skills 推荐
definition-of-done-generator
自动生成项目完成标准的规范定义与配置文件,提供符合企业级工作流要求的最佳实践指导,输出可直接投入生产环境的代码和验证结果,适用于需要标准化流程审批、合规审查及跨系统集成的复杂项目管理场景。
sagemaker-endpoint-deployer
自动化部署机器学习模型至云端服务端点,支持从配置生成到生产验证的全流程,适用于模型上线、服务监控与推理优化等场景,确保部署方案符合工业级标准。
docx
支持专业级 Word 文档的全生命周期处理,包括从零创建结构化文档、精准编辑内容、管理修订痕迹与批注、提取纯文本或原始 XML 数据、转换为 PDF 或图像用于视觉分析,适用于法律、学术及企业场景下的高保真文档协作与自动化处理。
skills-search
提供对 Claude Code 技能生态的全周期管理能力,支持按功能关键词检索技能、查看详细信息、安装或卸载指定技能,并区分用户级与项目级作用域,覆盖发现、评估、部署及维护各环节。
moai-foundation-core
构建高质量、可扩展的AI开发工作流,通过领域驱动设计与模块化架构实现需求规范先行,结合自动化质量门禁、精细化上下文管理与渐进式知识呈现,在保障安全与可维护性的同时提升开发效率与协作清晰度。