ARTICLE · INTELLIGENCE

战地情报 · 详情页

来自尧图项目组的一线实战观察与深度解析

User Information

User Information User Information【免费下载链接】mastraMastra is the modern TypeScript framework for AI-powered applications and agents.项目地址: https://gitcode.com/GitHub_Trending/ma/mastraFirst Name:Last Name:Location:Occupation:Interests:Goals:Events:Facts:Projects:### 自定义工作记忆模板 模板引导 Agent 跟踪与更新哪些信息。虽然不提供模板时系统会使用默认模板但通常你会为特定用例定义自定义模板详见 [22-custom-working-memory-templates.md](https://link.gitcode.com/i/e384a3d1914ee1892a4890e69e33de0f) typescript options: { semanticRecall: { topK: 3, messageRange: { before: 2, after: 1 }, }, workingMemory: { enabled: true, template: # User Profile ## Personal Info - Name: - Location: - Timezone: ## Preferences - Communication Style: [e.g., Formal, Casual] - Interests: - Favorite Topics: ## Session State - Current Topic: - Open Questions: - [Question 1] - [Question 2] , }, }模板是一份定义工作记忆结构的 Markdown 文档包含个人信息、偏好、会话状态等不同类型的章节。它的作用有三引导 Agent 该跟踪哪些信息、如何组织为跨会话的工作记忆提供一致的结构让 Agent 更容易定位和更新特定信息片段。在源码的 getWorkingMemoryTemplate() 中模板支持两种格式Markdown字符串模板或JSON当配置了schema时会把 Zod/JSON Schema 转换为 JSON Schema draft-07 交给模型。设计模板时应基于 Agent 的具体需求以及它需要记住的关于用户或任务的信息类型。综合实战构建完整的记忆增强 Agent现在把三大特性整合到一个 Agent 中详见 25-combining-memory-features.md// src/mastra/agents/memory-agent.ts import { Agent } from mastra/core/agent import { Memory } from mastra/memory import { LibSQLStore, LibSQLVector } from mastra/libsql // 创建综合记忆配置 const memory new Memory({ storage: new LibSQLStore({ id: learning-memory-storage, url: file:../../memory.db, // 相对 .mastra/output 目录的路径 }), vector: new LibSQLVector({ url: file:../../vector.db, // 相对 .mastra/output 目录的路径 }), embedder: openai/text-embedding-3-small, options: { // 会话历史配置 lastMessages: 20, // 上下文包含最近 20 条消息 // 语义召回配置 semanticRecall: { topK: 3, // 召回 3 条最相似消息 messageRange: { before: 2, // 每条命中前附带 2 条 after: 1, // 每条命中后附带 1 条 }, }, // 工作记忆配置 workingMemory: { enabled: true, template: # User Profile ## Personal Info - Name: - Location: - Timezone: - Occupation: ## Preferences - Communication Style: - Topics of Interest: - Learning Goals: ## Project Information - Current Projects: - [Project 1]: - Deadline: - Status: - [Project 2]: - Deadline: - Status: ## Session State - Current Topic: - Open Questions: - Action Items: , }, }, })【免费下载链接】mastraMastra is the modern TypeScript framework for AI-powered applications and agents.项目地址: https://gitcode.com/GitHub_Trending/ma/mastra创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
RELATED READING

延伸阅读

更多一线实战笔记与深度复盘,助您持续精进