mcpField
O
ontology

ontology

github.com/sundial-orgAgent 工作流6703.7k 次安装34 周前更新
代码仓库

关于 ontology

ontology 是用于将知识表示为可验证图谱的类型化词汇与约束系统,适合需要在技能间共享结构化状态的 Agent。实体变更会先按类型约束验证,并支持查询、关系遍历和规划操作。

主要功能

  1. 01类型化实体与关系
  2. 02变更前校验约束
  3. 03查询和图谱遍历
  4. 04JSONL 文件存储
  5. 05多步计划建模

适用场景

  1. 01记录和查询人物、项目与任务
  2. 02关联项目、负责人和任务
  3. 03检查数据是否满足类型约束
  4. 04将多步计划表示为图操作

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/sundial-org/awesome-openclaw-skills --skill ontology

安装后在 Claude Code 中输入/ontology确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

references/
queries.md
schema.md
scripts/
ontology.py

详细介绍

本体

用于将知识表示为可验证图的类型化词汇与约束系统。

核心概念

所有内容都是一个实体,具有类型、属性以及与其他实体的关系。每次变更都会先根据类型约束进行验证,再提交。

Entity: { id, type, properties, relations, created, updated }
Relation: { from_id, relation_type, to_id, properties }

适用场景

触发条件操作
“记住……”创建/更新实体
“我对 X 了解什么?”查询图
“将 X 与 Y 关联”创建关系
“显示项目 Z 的所有任务”遍历图
“哪些内容依赖于 X?”查询依赖关系
规划多步骤工作将其建模为图转换
技能需要共享状态读写本体对象

核心类型

# 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 }  # Never store secrets directly

# Meta
Action: { type, target, timestamp, outcome? }
Policy: { scope, rule, enforcement }

存储

默认路径:memory/ontology/graph.jsonl

{"op":"create","entity":{"id":"p_001","type":"Person","properties":{"name":"Alice"}}}
{"op":"create","entity":{"id":"proj_001","type":"Project","properties":{"name":"Website Redesign","status":"active"}}}
{"op":"relate","from":"proj_001","rel":"has_owner","to":"p_001"}

通过脚本或直接操作文件进行查询。对于复杂图,可迁移到 SQLite。

工作流

创建实体
python3 scripts/ontology.py create --type Person --props '{"name":"Alice","email":"[email protected]"}'
查询
python3 scripts/ontology.py query --type Task --where '{"status":"open"}'
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  # Check all constraints

约束

在 memory/ontology/schema.yaml 中定义:

types:
  Task:
    required: [title, status]
    status_enum: [open, in_progress, blocked, done]
  
  Event:
    required: [title, start]
    validate: "end >= start if end exists"

  Credential:
    required: [service, secret_ref]
    forbidden_properties: [password, secret, token]  # Force indirection

relations:
  has_owner:
    from_types: [Project, Task]
    to_types: [Person]
    cardinality: many_to_one
  
  blocks:
    from_types: [Task]
    to_types: [Task]
    acyclic: true  # No circular dependencies

技能契约

使用本体的技能应声明:

# In SKILL.md frontmatter or header
ontology:
  reads: [Task, Project, Person]
  writes: [Task, Action]
  preconditions:
    - "Task.assignee must exist"
  postconditions:
    - "Created Task has status=open"

将规划建模为图转换

将多步骤计划建模为一系列图操作:

Plan: "Schedule team meeting and create follow-up tasks"

1. CREATE Event { title: "Team Sync", attendees: [p_001, p_002] }
2. RELATE Event -> has_project -> proj_001
3. CREATE Task { title: "Prepare agenda", assignee: p_001 }
4. RELATE Task -> for_event -> event_001
5. CREATE Task { title: "Send summary", assignee: p_001, blockers: [task_001] }

每个步骤都会在执行前进行验证。违反约束时回滚。

集成模式

与因果推断集成

将本体变更记录为因果操作:

# When creating/updating entities, also log to causal action log
action = {
    "action": "create_entity",
    "domain": "ontology", 
    "context": {"type": "Task", "project": "proj_001"},
    "outcome": "created"
}
跨技能通信
# Email skill creates commitment
commitment = ontology.create("Commitment", {
    "source_message": msg_id,
    "description": "Send report by Friday",
    "due": "2026-01-31"
})

# Task skill picks it up
tasks = ontology.query("Commitment", {"status": "pending"})
for c in tasks:
    ontology.create("Task", {
        "title": c.description,
        "due": c.due,
        "source": c.id
    })

快速开始

# Initialize ontology storage
mkdir -p memory/ontology
touch memory/ontology/graph.jsonl

# Create schema (optional but recommended)
cat > memory/ontology/schema.yaml << 'EOF'
types:
  Task:
    required: [title, status]
  Project:
    required: [name]
  Person:
    required: [name]
EOF

# Start using
python3 scripts/ontology.py create --type Person --props '{"name":"Alice"}'
python3 scripts/ontology.py list --type Person

参考资料

  • references/schema.md — 完整的类型定义和约束模式
  • references/queries.md — 查询语言和遍历示例

评论

支持 Markdown