掘金 人工智能 08月13日
Agent Memory - Mirix 基础概念
index_new5.html
../../../zaker_core/zaker_tpl_static/wap/tpl_guoji1.html

 

本文深入剖析了一个AI Agent的多维度记忆管理系统,该系统整合了核心记忆、情景记忆、语义记忆、程序性记忆、资源记忆以及知识库,以支持Agent与用户的深度交互。通过LLM Agent和精密的Prompt工程,系统能够生成并组织各类记忆信息,包括用户偏好、事件摘要、通用知识、操作流程、项目文件及敏感数据。文章还介绍了统一的记忆搜索接口和不同记忆类型的自动清理策略,为构建更智能、更具连贯性的AI Agent提供了技术框架和实践思路。

✨ **多层级记忆架构**:该AI Agent系统构建了包括核心记忆、情景记忆、语义记忆、程序性记忆、资源记忆和知识库在内的六大记忆模块,分别负责存储用户偏好、事件记录、通用知识、操作流程、项目文件和敏感个人信息,形成了全面而立体的记忆体系,为Agent的连贯交互打下基础。

🧠 **LLM驱动的记忆生成与管理**:所有记忆内容的生成均依赖于LLM Agent和精细的Prompt工程,确保了记忆信息的质量和相关性。系统能够处理并组织如用户姓名、偏好、事件细节、技术概念、操作步骤、文档内容以及API密钥等多种类型的数据,展现了强大的信息处理能力。

🔍 **统一的记忆搜索与高效检索**:系统提供了一个统一的搜索接口,支持多种搜索实现方式,包括基于BM25的全文搜索、基于嵌入向量的相似性搜索以及简单的字符串匹配。用户可以根据需求选择最适合的搜索方法,以高效地从海量记忆中检索所需信息。

🧹 **智能化的记忆自动清理策略**:为了维持记忆系统的效率和性能,系统采用了针对不同记忆类型的自动清理策略。例如,核心记忆会覆盖旧条目,情景记忆按相关性归档,语义记忆合并重复概念,知识库中的凭据则按过期策略删除,确保了记忆系统的动态优化和资源有效利用。

graph TB    subgraph "Input Processing"        A[User Input] --> B[Meta Agent]    end        subgraph "Memory Managers"        C[Core Memory Manager]        D[Episodic Memory Manager]        E[Semantic Memory Manager]        F[Procedural Memory Manager]        G[Resource Memory Manager]        H[Knowledge Vault Manager]    end        subgraph "User Interaction"        I[Chat Agent]    end        subgraph "Memory Base"        J[(Shared Memory Database)]    end        B --> C    B --> D    B --> E    B --> F    B --> G    B --> H        C --> J    D --> J    E --> J    F --> J    G --> J    H --> J        I --> J    J --> I

最大特色是可以支持图片生成记忆(后续专门写一篇文章分析如何实现的)。所有记忆都是通过 LLM Agent 生成,核心是 Prompt 工程,实际使用体验并不是很稳定。

记忆类型

1. Core Memory 核心记忆

代理与用户交互时应始终可见的持久性信息,核心记忆被组织在多个 block 中( human 和 persona )

<human 117/500 characters>User's name is DavidUser prefers coffee over teaUser works as a software engineerUser enjoys reading sci-fi novels</human><persona 24/5000 characters>I am a helpful assistant</persona>

2. Episodic Memory 情景记忆

捕获特定于上下文的事件和时间活动,作为用户行为的摘要或日历。

{  "event_type": "user_message",  "summary": "User reviewed quarterly sales report",  "details": "Detailed analysis of Q3 sales performance, identified key growth areas in mobile segment, discussed strategies with marketing team",  "actor": "user",  "timestamp": "2025-03-05 10:15"}

3. Semantic Memory 语义记忆

维护一般知识,概念和独立于时间的上下文抽象信息。

[  {    "name": "PostgreSQL",    "summary": "Open-source relational database management system",    "details": "Powerful, enterprise-grade database with advanced features like JSONB support, full-text search, and vector extensions. Preferred by user for its performance and reliability.",    "source": "user_interaction"  },  {    "name": "MkDocs Material",    "summary": "Documentation framework based on MkDocs",    "details": "Static site generator that creates beautiful documentation sites from Markdown files. Features include responsive design, search functionality, and extensive customization options.",    "source": "documentation_project"  },  {    "name": "Team Standup Meeting",    "summary": "Daily team synchronization meeting",    "details": "Occurs every weekday at 9 AM, attended by development team to discuss progress, blockers, and daily goals. Usually lasts 15-20 minutes.",    "source": "recurring_activity"  }]

包含的数据内容类型:

4. Procedural Memory 程序性记忆

记录完成特定任务的流程工作流和分步说明。

[  {    "entry_type": "workflow",    "description": "Setting up new development environment",    "steps": [      "1. Install Python 3.11 or later",      "2. Set up virtual environment with 'python -m venv venv'",      "3. Activate virtual environment",      "4. Install dependencies with 'pip install -r requirements.txt'",      "5. Configure environment variables in .env file",      "6. Initialize database with 'python manage.py migrate'",      "7. Run development server with 'python manage.py runserver'"    ]  },  {    "entry_type": "guide",    "description": "Troubleshooting PostgreSQL connection issues",    "steps": [      "1. Check if PostgreSQL service is running",      "2. Verify database exists with 'psql -l'",      "3. Test connection with 'psql -U username -d database'",      "4. Check firewall settings if connecting remotely",      "5. Verify authentication configuration in pg_hba.conf"    ]  }]

5. Resource Memory 资源存储器

管理与用户交互的活动文档和项目相关文件。

[  {    "title": "API Documentation Draft",    "summary": "Initial draft of REST API documentation for the customer management system, includes endpoint specifications and example requests",    "resource_type": "markdown",    "content": "# Customer Management API\n\n## Overview\nThis API provides endpoints for managing customer data...\n\n## Endpoints\n\n### GET /api/customers\nRetrieve list of customers..."  },  {    "title": "Meeting Recording - Sprint Planning",    "summary": "Voice recording from sprint planning meeting discussing user stories and development priorities for next iteration",    "resource_type": "voice_transcript",    "content": "Transcript: 'Let's start with the user authentication story. Based on our previous discussion, we need to implement OAuth 2.0 integration...'"  }]

6. Knowledge Vault

存储结构化的个人数据敏感数据,如地址、电话号码、联系人和凭据。

[  {    "entry_type": "api_key",    "source": "openai",    "sensitivity": "high",    "secret_value": "sk-proj-xxxxxxxxxxxxxxxxxxxx",    "caption": "OpenAI API key for ChatGPT integration"  },  {    "entry_type": "bookmark",    "source": "user_provided",    "sensitivity": "low",    "secret_value": "https://docs.mirix.ai/",    "caption": "MIRIX documentation website"  },  {    "entry_type": "contact_info",    "source": "user_profile",    "sensitivity": "medium",    "secret_value": "john.doe@example.com",    "caption": "Primary email address"  }]

主要参数说明:

Sensitivity Levels 灵敏度水平

Security Features 安全功能

记忆搜索

所有类型的记忆都使用统一的搜索接口

results = search_in_memory(    query="machine learning project",    memory_type='episodic', # can be chosen from ['all', 'episodic', 'semantic', 'resource', 'procedural', 'knowledge_vault']    limit=20)

3 种搜索实现方式:

MethodDescriptionBest ForPerformance
bm25推荐 - PostgreSQL 原生全文搜索大多数查询,生产使用Excellent
embedding使用嵌入的向量相似性搜索语义相似性,概念查询Good
string_match简单字符串包含搜索精确文本匹配Fast

记忆自动清理策略

Fish AI Reader

Fish AI Reader

AI辅助创作,多种专业模板,深度分析,高质量内容生成。从观点提取到深度思考,FishAI为您提供全方位的创作支持。新版本引入自定义参数,让您的创作更加个性化和精准。

FishAI

FishAI

鱼阅,AI 时代的下一个智能信息助手,助你摆脱信息焦虑

联系邮箱 441953276@qq.com

相关标签

AI Agent 记忆管理 LLM Prompt工程 信息检索
相关文章