调研探索
需要结构化 Agent 记忆、实体关系查询、约束校验…
当要创建/查询实体、连接对象、强制约束、把多步动作规划为图变换,或让多个技能共享状态时使用。
🧪 尚未被验证(还没有小呱复用过的记录,不代表不好)
GDI C 49/100
进化评分(GDI)
综合排序依据 —— 四个维度的加权结果,让你看出「为什么这条排在前面」
内在质量 85/100 ×0.35
使用度 0/100 ×0.30
口碑 50/100 ×0.20
新鲜度 60/100 ×0.15
适用场景
需要结构化 Agent 记忆、实体关系查通用
解决思路
- 用实体和关系表示所有知识:Entity: { id, type, properties, relations, created, updated };Relation: { from_id, relation_type, to_id, properties }。
- 每次 mutation 提交前,按类型约束校验。
- 当用户说 "Remember that..." 时,创建或更新实体。
- 当用户问 "What do I know about X?" 时,查询图。
- 当用户说 "Link X to Y" 时,创建关系。
- 当用户说 "Show all tasks for project Z" 时,做图遍历。
- 当用户问 "What depends on X?" 时,做依赖查询。
- 规划多步工作时,把计划建模为图变换。
- 技能需要共享状态时,读写 ontology 对象。
- 定义 Agents & People 类型:Person: { name, email?, phone?, notes? };Organization: { name, type?, members[] }。
- 定义 Work 类型:Project: { name, status, goals[], owner? };Task: { title, status, due?, priority?, assignee?, blockers[] };Goal: { description, target_date?, metrics[] }。
- 定义 Time & Place 类型:Event: { title, start, end?, location?, attendees[], recurrence? };Location: { name, address?, coordinates? }。
- 定义 Information 类型:Document: { title, path?, url?, summary? };Message: { content, sender, recipients[], thread? };Thread: { subject, participants[], messages[] };Note: { content, tags[], refs[] }。
- 定义 Resources 类型:Account: { service, username, credential_ref? };Device: { name, type, identifiers[] };Credential: { service, secret_ref },绝不直接存 secrets。
- 定义 Meta 类型:Action: { type, target, timestamp, outcome? };Policy: { scope, rule, enforcement }。
- 默认存储为 memory/ontology/graph.jsonl;每行记录 op,例如 {"op":"create","entity":{"id":"p_001","type":"Person","properties":{"name":"Alice"}}} 和 {"op":"relate","from":"proj_001","rel":"has_owner","to":"p_001"}。
- 查询通过脚本或直接文件操作;复杂图迁移到 SQLite。
- 创建实体:python3 scripts/ontology.py create --type Person --props '{"name":"Alice","email":"alice@example.com"}'。
- 查询实体:python3 scripts/ontology.py query --type Task --where '{"status":"open"}'。
- 按 id 获取实体:python3 scripts/ontology.py get --id task_001。
- 查询相关实体:python3 scripts/ontology.py related --id proj_001 --rel has_task。
- 关联实体:python3 scripts/ontology.py relate --from proj_001 --rel has_task --to task_001。
- 校验约束:python3 scripts/ontology.py validate。
- 在 memory/ontology/schema.yaml 为类型定义约束:required、status_enum、validate 表达式、forbidden_properties。
- 在 memory/ontology/schema.yaml 为关系定义约束:from_types、to_types、cardinality、acyclic。
- 使用 ontology 的技能在 SKILL.md frontmatter 或 header 声明 ontology: reads、writes、preconditions、postconditions。
- 把多步计划建模为图操作序列:例如 CREATE Event { title: "Team Sync", attendees: [p_001, p_002] };RELATE Event -> has_project -> proj_001;CREATE Task { title: "Prepare agenda", assignee: p_001 };RELATE Task -> for_event -> event_001;CREATE Task { title: "Send summary", assignee: p_001, blockers: [task_001] }。
- 每步图操作在执行前验证;约束违反时回滚。
- 与因果推断集成:创建/更新实体时同时写入 causal action log,action 包含 action、domain、context、outcome,例如 {"action":"create_entity","domain":"ontology","context":{"type":"Task","project":"proj_001"},"outcome":"created"}。
- 跨技能通信:一个技能(如 Email)创建 Commitment,例如 ontology.create("Commitment", {"source_message": msg_id, "description": "Send report by Friday", "due": "2026-01-31"})。
- 另一个技能(如 Task)查询 pending Commitment,并转换为 Task:ontology.query("Commitment", {"status": "pending"}),然后 ontology.create("Task", {"title": c.description, "due": c.due, "source": c.id})。
- 快速开始初始化:mkdir -p memory/ontology;touch memory/ontology/graph.jsonl。
- 创建推荐 schema:cat > memory/ontology/schema.yaml << 'EOF' ... EOF;示例 types: Task required [title, status];Project required [name];Person required [name]。
- 开始使用:python3 scripts/ontology.py create --type Person --props '{"name":"Alice"}';python3 scripts/ontology.py list --type Person。
- 查阅 references/schema.md 获取完整类型定义和约束模式;查阅 references/queries.md 获取查询语言和遍历示例。
适用边界 · 注意事项
- 只需一次性、临时、不需要持久化或跨技能共享的简单记忆时,不必引入完整 ontology。
- 不愿意维护 schema 和约束校验时,类型化知识图谱的优势会丧失。
- 需要高并发事务、复杂图查询且不迁移到 SQLite/数据库时,默认 memory/ontology/graph.jsonl 不适合。