← 返回 Skills 市场
laojun509

Agent Memory Enterprise

作者 laojun · GitHub ↗ · v0.1.0 · MIT-0
cross-platform ⚠ suspicious
115
总下载
0
收藏
1
当前安装
1
版本数
在 OpenClaw 中安装
/install agent-memory-enterprise
功能描述
Enterprise-grade 5-layer agent memory system with routing, scoring, and multi-backend storage. Use when building production AI agents that need persistent me...
使用说明 (SKILL.md)

Agent Memory Pro

Enterprise-grade 5-layer long-term memory system for AI agents with intelligent routing, importance scoring, and multi-backend storage support.

Overview

This is a production-ready implementation of the 5-layer memory architecture from Wang Fuqiang's article "How to Design an Agent Long-term Memory System".

5 Memory Layers

┌─────────────────────────────────────────────────────────────┐
│  Context Memory    - Conversation window management         │
│  (seconds-minutes) - Token budget + sliding window          │
├─────────────────────────────────────────────────────────────┤
│  Task Memory       - Multi-step task tracking               │
│  (minutes-hours)   - State machine + checkpoints            │
├─────────────────────────────────────────────────────────────┤
│  User Memory       - Persistent user profiles               │
│  (persistent)      - Version control + preferences          │
├─────────────────────────────────────────────────────────────┤
│  Knowledge Memory  - RAG document retrieval                 │
│  (persistent)      - Vector search + metadata               │
├─────────────────────────────────────────────────────────────┤
│  Experience Memory - Execution pattern learning             │
│  (long-term)       - Success/failure tracking               │
└─────────────────────────────────────────────────────────────┘

Quick Start

Installation

pip install -e .

Basic Usage

from agent_memory import AgentMemorySystem, MemorySystemConfig

# Configure system
config = MemorySystemConfig(
    redis_url="redis://localhost:6379",
    postgres_url="postgresql://user:pass@localhost/db",
    chroma_path="./chroma_db"
)

# Initialize
system = AgentMemorySystem(config)

# Record conversation
await system.context.add_message(
    user_id="user_123",
    role="user",
    content="Help me analyze Q4 data"
)

# Create tracked task
task = await system.tasks.create_task(
    user_id="user_123",
    goal="Generate Q4 sales report",
    steps=["Collect data", "Analyze", "Generate report"]
)

# Update progress
await system.tasks.complete_step(task.id, 0, {"data": [...]})

# Intelligent retrieval
working_memory = await system.router.retrieve(
    user_id="user_123",
    query="Continue generating the report",
    context={"current_task": task.id}
)

# Format for LLM
prompt = system.injector.format(working_memory)

Core Features

1. Context Memory

Conversation management with token budget control:

from agent_memory.memories import ContextMemory
from agent_memory.models import MessageRole

context = ContextMemory(max_tokens=4000, max_messages=20)

await context.add_message(
    user_id="user_123",
    role=MessageRole.USER,
    content="Hello!"
)

# Get conversation window
window = await context.get_conversation(user_id="user_123")

2. Task Memory

Multi-step task tracking with state management:

from agent_memory.memories import TaskMemory
from agent_memory.models import TaskState

# Create task
task = await task_memory.create_task(
    user_id="user_123",
    goal="Generate report",
    task_type="report_generation"
)

# Update state
await task_memory.start_step(task.id, step_index=0)
await task_memory.complete_step(task.id, 0, result={"status": "done"})

# Get progress
progress = await task_memory.get_progress(task.id)

3. User Memory

Persistent user profiles with preference learning:

from agent_memory.memories import UserMemory

# Learn preference
await user_memory.update_preference(
    user_id="user_123",
    key="response_style",
    value="concise",
    confidence=0.9
)

# Get profile
profile = await user_memory.get_profile("user_123")

4. Knowledge Memory

RAG-based document retrieval:

from agent_memory.memories import KnowledgeMemory

# Index document
await knowledge.index_document(
    doc_id="doc_001",
    content="Document content...",
    metadata={"category": "finance"}
)

# Search
results = await knowledge.search(
    query="Q4 sales",
    top_k=5
)

5. Experience Memory

Pattern learning from execution history:

from agent_memory.memories import ExperienceMemory
from agent_memory.models import ExperienceOutcome

# Record experience
await experience.record(
    task_type="report_generation",
    outcome=ExperienceOutcome.SUCCESS,
    strategy={"steps": [...]},
    lessons=["Validate data first"]
)

# Find similar successful experiences
patterns = await experience.find_patterns(
    task_type="report_generation",
    min_success_rate=0.8
)

Intelligent Routing

The MemoryRouter intelligently selects which memories to load:

from agent_memory.routing import MemoryRouter

router = MemoryRouter(
    context=context,
    tasks=task_memory,
    users=user_memory,
    knowledge=knowledge_memory,
    experience=experience_memory
)

# Automatic feature extraction and routing
working_memory = await router.retrieve(
    user_id="user_123",
    query="Generate Q4 report for East region",
    context={"task_type": "report_generation"}
)

Routing Features

  • Feature Extraction: Automatically detects task complexity, knowledge needs, history
  • Selective Loading: Only loads relevant memory types
  • Importance Scoring: Ranks memories by relevance, recency, frequency
  • Token Budget: Respects context window limits

Importance Scoring

from agent_memory.scoring import ImportanceScorer

scorer = ImportanceScorer(
    relevance_weight=0.3,
    recency_weight=0.25,
    frequency_weight=0.2,
    explicit_weight=0.25
)

score = await scorer.calculate(memory_item, query_context)

Score Components

  • Relevance: Semantic similarity to query
  • Recency: Time decay function
  • Frequency: Access count normalization
  • Explicit: User-rated importance

Storage Backends

Redis (Context & Cache)

from agent_memory.storage import RedisClient

redis = RedisClient(url="redis://localhost:6379")

PostgreSQL (Task, User, Experience)

from agent_memory.storage import PostgresClient

postgres = PostgresClient(url="postgresql://...")

ChromaDB (Knowledge)

from agent_memory.storage import ChromaClient

chroma = ChromaClient(path="./chroma_db")

Configuration

from agent_memory.config import MemorySystemConfig

config = MemorySystemConfig(
    # Redis for context & cache
    redis=RedisConfig(url="redis://localhost:6379"),
    
    # PostgreSQL for structured data
    postgres=PostgreSQLConfig(
        url="postgresql://user:pass@localhost/db"
    ),
    
    # Chroma for vector search
    chroma=ChromaConfig(path="./chroma_db"),
    
    # Memory-specific configs
    context=ContextMemoryConfig(max_tokens=4000),
    tasks=TaskMemoryConfig(),
    users=UserMemoryConfig(),
    knowledge=KnowledgeMemoryConfig(),
    experience=ExperienceMemoryConfig(),
    
    # Scoring config
    scoring=ScoringConfig(
        decay_half_life_days=7.0
    )
)

Project Structure

agent_memory/
├── __init__.py              # System entry point
├── config.py                # Configuration management
├── exceptions.py            # Custom exceptions
├── core/
│   └── base_memory.py       # Abstract base classes
├── memories/                # 5 memory implementations
│   ├── context_memory.py
│   ├── task_memory.py
│   ├── user_memory.py
│   ├── knowledge_memory.py
│   └── experience_memory.py
├── models/                  # Pydantic data models
│   ├── base.py
│   ├── context.py
│   ├── task.py
│   ├── user.py
│   ├── knowledge.py
│   ├── experience.py
│   └── scoring.py
├── routing/                 # Intelligent routing
│   ├── router.py
│   └── feature_extractor.py
├── injection/               # Memory injection
│   ├── injector.py
│   └── formatters.py
├── scoring/                 # Importance scoring
│   ├── importance_scorer.py
│   └── decay.py
└── storage/                 # Backend clients
    ├── redis_client.py
    ├── postgres_client.py
    ├── postgres_models.py
    └── chroma_client.py

tests/                       # Comprehensive test suite
alembic/                     # Database migrations
pyproject.toml              # Project configuration

Dependencies

  • Python 3.10+
  • Redis 5.0+
  • PostgreSQL 14+
  • ChromaDB 0.4+
  • SQLAlchemy 2.0+ (async)
  • Pydantic 2.0+
  • sentence-transformers

Testing

pytest tests/ -v --cov=agent_memory

Migration

alembic upgrade head

Reference

  • Original Article: "如何设计一套Agent长期记忆系统" by Wang Fuqiang
  • Architecture: 5-layer memory with routing and scoring
  • GitHub: laojun509/MemCore
安全使用建议
This package appears to implement the memory system it advertises, but it silently reads environment variables and a .env file for backend credentials (Redis, PostgreSQL, ChromaDB) even though the registry entry declares no required credentials. Before installing or running: 1) Inspect the storage client files (postgres_client.py, redis_client.py, chroma_client.py) to confirm they only connect to your configured backends and don't call unexpected endpoints. 2) Do not install into an environment that contains production .env secrets or global DB credentials — use an isolated virtualenv or container and test with throwaway databases. 3) Consider whether you want to grant the skill network access to your databases; if not, run it in a sandbox. 4) Because the skill author and homepage are unknown, prefer to audit the source or get the package from a trusted source before giving it real credentials. If you want, I can scan the storage client files (postgres_client.py, redis_client.py, chroma_client.py) and pyproject.toml for any hardcoded hosts or unexpected behavior — that would raise or lower my confidence.
功能分析
Type: OpenClaw Skill Name: agent-memory-enterprise Version: 0.1.0 The agent-memory-enterprise bundle is a legitimate, well-architected implementation of a 5-layer long-term memory system for AI agents, utilizing Redis, PostgreSQL, and ChromaDB. The code follows standard patterns for RAG (Retrieval-Augmented Generation) and state management, including token budget management in 'injector.py' and intelligent routing in 'router.py'. No indicators of malicious intent, data exfiltration, or unauthorized execution were found; the instructions in 'SKILL.md' are consistent with the stated purpose of providing persistent memory capabilities.
能力评估
Purpose & Capability
The name, description, SKILL.md examples, and the included code implement a 5-layer memory system that legitimately requires Redis, PostgreSQL, and ChromaDB configuration. That capability matches the stated purpose. However, the registry metadata lists no required environment variables or primary credential even though the code supports/reads AGENT_MEM_REDIS_URL, AGENT_MEM_POSTGRESQL_URL, AGENT_MEM_CHROMA_PERSIST_DIRECTORY, and similar overrides — a mismatch between declared requirements and actual needs.
Instruction Scope
SKILL.md only shows typical usage and an install hint (pip install -e .) and does not warn that the package will load .env or expect DB connection strings. The code calls dotenv.load_dotenv() and reads environment variables for backend URLs; that means the skill can pick up sensitive credentials from the environment or a .env file without the SKILL metadata declaring those secrets or warning the user.
Install Mechanism
There is no registry install spec, but SKILL.md instructs pip install -e . and the package includes a pyproject and ~50 source files. This is an instruction-only registry entry with embedded code — installing will execute user-supplied code locally. No remote/external download URLs or obfuscated installers were found in the provided files, which lowers supply-chain risk, but the absence of a registry install spec is an inconsistency worth noting.
Credentials
The skill requires backend connection strings (Redis, PostgreSQL, Chroma) to be useful, yet requires.env is empty and primary credential is none. The code reads environment variables (AGENT_MEM_REDIS_URL, AGENT_MEM_POSTGRESQL_URL, AGENT_MEM_CHROMA_PERSIST_DIRECTORY) and will load a .env file via dotenv.load_dotenv(). That means the skill may access secrets present in the environment or a .env file even though the registry did not declare any required credentials — disproportionate lack of disclosure.
Persistence & Privilege
The skill is not marked always:true and does not request system-wide configuration changes in the provided code. It does not appear to modify other skills' configurations. It will, however, attempt to connect to external services (databases, vector DB) when used — expected for its purpose.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install agent-memory-enterprise
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /agent-memory-enterprise 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v0.1.0
agent-memory-enterprise 0.1.0 - Initial release of an enterprise-grade, 5-layer agent memory system based on Wang Fuqiang’s architecture. - Supports context, task, user, knowledge, and experience memory, each with specialized features for persistent and long-term memory. - Includes smart memory routing, importance scoring, and selective memory retrieval. - Multi-backend storage with PostgreSQL, Redis, and ChromaDB. - Designed for production AI agents needing robust, scalable memory systems.
元数据
Slug agent-memory-enterprise
版本 0.1.0
许可证 MIT-0
累计安装 1
当前安装数 1
历史版本数 1
常见问题

Agent Memory Enterprise 是什么?

Enterprise-grade 5-layer agent memory system with routing, scoring, and multi-backend storage. Use when building production AI agents that need persistent me... 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 115 次。

如何安装 Agent Memory Enterprise?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install agent-memory-enterprise」即可一键安装,无需额外配置。

Agent Memory Enterprise 是免费的吗?

是的,Agent Memory Enterprise 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

Agent Memory Enterprise 支持哪些平台?

Agent Memory Enterprise 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 Agent Memory Enterprise?

由 laojun(@laojun509)开发并维护,当前版本 v0.1.0。

💬 留言讨论