360 Secure SkillHub
360 安全技能中心

Agent Memory Layer

提供 AgentMemory 类及脚本,管理三层记忆:短期(Redis、TTL 过期、优先级保留)、长期(向量相似度检索、标签过滤)、情景(时间线事件、衰减、整合),并可将重复出现的情景模式提升为长期记忆。

分类:知识
evezart
evezart
热度 29.92
最近更新 2026-05-12 19:46:48

安装

发给 Agent
帮我安装这个技能:npx secure-skills-cli add evezart/agent-memory-layer
兼容性
通用兼容
联网要求
联网要求未确认
数据出网
数据出网未确认
Metadata
name
agent-memory-layer
description
Scalable memory system for AI agents with short-term, long-term, and episodic memory. Use when building agent memory persistence, conversation context management, knowledge retrieval, or episodic recall. Covers Redis-backed short-term memory, vector-based long-term memory, and timeline-ordered episodic memory with decay and consolidation.

Agent Memory Layer

Three-tier memory system for AI agents: short-term, long-term, and episodic.

Quick Start

from memory_layer import AgentMemory

mem = AgentMemory(agent_id="my-agent")
mem.short_term.add("User prefers dark mode", priority=0.8)
mem.long_term.store("Project uses React + TypeScript", tags=["tech", "project"])
mem.episodic.record("Debugged auth bug", outcome="success", duration_min=15)

# Recall
context = mem.short_term.recall(limit=10)
relevant = mem.long_term.search("frontend framework")
similar = mem.episodic.find_similar("debugging session")

Architecture

┌─────────────────────────────────────────┐
│            Agent Memory                  │
├───────────┬───────────┬─────────────────┤
│ Short-Term│ Long-Term │   Episodic      │
│ (Redis)   │ (Vectors) │  (Timeline)     │
│ TTL: 1hr  │ Permanent │ Decay: 30d      │
│ Hot cache │ Semantic  │ Consolidated    │
└───────────┴───────────┴─────────────────┘

Memory Tiers

Short-Term (Working Memory)

  • Recent context, active conversation, current task state
  • TTL-based expiry (default 1 hour)
  • Priority-weighted retention
  • See references/short-term.md

Long-Term (Knowledge)

  • Persistent facts, preferences, learned patterns
  • Vector similarity search for retrieval
  • Tags and metadata for filtering
  • See references/long-term.md

Episodic (Experience)

  • Timeline-ordered events with outcomes
  • Decay function reduces old episode weight
  • Consolidation moves recurring patterns to long-term
  • See references/episodic.md

Consolidation

Episodic memories that recur are automatically promoted to long-term:

  • If the same outcome occurs 3+ times → store as learned pattern
  • Failed approaches get negative weight in long-term
  • See scripts/consolidate.py