|
|
1 ヶ月 前 | |
|---|---|---|
| .. | ||
| README.md | 1 ヶ月 前 | |
| __init__.py | 1 ヶ月 前 | |
| models.py | 1 ヶ月 前 | |
| protocols.py | 1 ヶ月 前 | |
| skill_loader.py | 1 ヶ月 前 | |
| stores.py | 1 ヶ月 前 | |
记忆系统管理 Agent 的长期记忆和技能:
数据模型 (models.py)
Experience - 经验记录(从执行中提取的知识)Skill - 技能定义(领域知识和最佳实践)存储接口 (protocols.py, stores.py)
MemoryStore - 经验和技能存储接口StateStore - 状态存储接口MemoryMemoryStore - 内存实现MemoryStateStore - 内存实现技能加载 (skill_loader.py)
from agent.memory import (
MemoryMemoryStore,
Experience,
Skill,
load_skills_from_dir
)
# 创建存储
memory_store = MemoryMemoryStore()
# 添加经验
exp = Experience.create(
scope="coding",
context="Python type hints",
pattern="Use Optional[T] for nullable types",
outcome="success"
)
await memory_store.add_experience(exp)
# 加载技能
skills = load_skills_from_dir("./config/skills")
for skill in skills:
await memory_store.add_skill(skill)
# 检索记忆
experiences = await memory_store.search_experiences(
scope="coding",
context="type hints",
limit=5
)
技能文件使用 Markdown + YAML frontmatter:
---
name: browser-automation
description: Browser automation best practices
category: web-automation
scope: agent:*
---
## When to use
- Scraping dynamic web pages
- Testing web applications
## Guidelines
- Always check if element exists before clicking
- Use explicit waits instead of sleep()
models.py - Experience 和 Skill 数据模型protocols.py - MemoryStore 和 StateStore 接口stores.py - 内存存储实现skill_loader.py - 技能加载器__init__.py - 模块导出