当前位置: 首页 > Skill >

Engram — Knowledge Graphs for AI Agents

Engram — Knowledge Graphs for AI Agents

Engram — Knowledge Graphs for AI Agents

构建、查询和维护结构化知识图谱。在需要记忆代码组件、服务、人员或任何概念之间的关系时使用。

0.1.10 2026.11.27 619
获取Skill文件查看使用说明
作 者:苏言 许可证: 更新时间:2026.11.27
本文目录展开

Engram

Persistent knowledge traces for AI agents — like a brain's memory engrams, but queryable.

A persistent knowledge graph for AI agents. Store nodes (components, services, people, concepts) and edges (calls, depends_on, owns) in a local SQLite database. Survives sessions. Query dependencies, find paths, check freshness against git, export for visualization.

Installation

npm install -g @clawdactual/engram

This installs the engram CLI globally. Verify with:

engram --help

How to Run

engram <command>

Database: ~/.config/engram/models.db (override: ENGRAM_DB_PATH=/path/to/db)

Global flag: --json on any command outputs structured JSON.

Session awareness: Add a line to your workspace bootstrap file (e.g., AGENTS.md) so future sessions know the knowledge graph exists and should maintain it. See the README's "Agent Setup" section.

Quick Reference

Models (containers for graphs)

engram create <name> [-t code|org|concept|infra] [-d "description"] [-r /repo/path]
engram list
engram delete <name>
engram export <name> [-f jsonld|json|dot] [-o file]
engram import <file>

Nodes

engram add <model> <label> [--type <type>] [-m key=value ...]
engram add <model> <label> --upsert [--type <type>] [-m key=value ...]
engram upsert <model> <label> [--type <type>] [-m key=value ...]
engram rm <model> <node>
engram update <model> <node> [--label new] [--type new] [-m key=value ...]
engram verify <model> <node>           # mark as recently verified
engram nodes <model> [-t type]

--set key=value is accepted anywhere node metadata is accepted; it is an alias for --meta/-m. Prefer engram upsert for incremental agent discoveries when the node may already exist.

Edges

engram link <model> <source> <rel> <target> [-m key=value ...]
engram unlink <model> <source> <rel> <target>
engram edges <model> [--from node] [--to node] [--rel type]

Queries

engram q <model> <node>                # neighbors (depth 1)
engram q <model> <node> --depth 3     # expand neighborhood
engram q <model> --affects <node>     # what breaks if this changes? (reverse traversal)
engram q <model> --depends-on <node>  # what does this need? (forward traversal)
engram q <model> -t service           # all nodes of type (includes subtypes)
engram q <model> --stale --days 14    # nodes not verified in 14+ days
engram q <model> --orphans            # nodes with no edges
engram path <model> <from> <to> [--max-depth N]  # all paths between two nodes

Search (cross-model)

engram search <query>                 # search ALL models (labels, types, metadata)
engram search <query> --model myapp   # search within one model
engram search <query> --limit 10      # max results (default 5)
engram search <query> --exclude zink-family --exclude test  # skip models
engram search <query> --json          # JSON output for recall/automation

Results show each matching node + its 1-hop edges, grouped by model.

Types & Relationships

engram type list                      # show type hierarchy tree
engram type add <label> [--parent p] [--domain code|org|infra|concept]
engram type rm <label>
engram rel list                       # show all relationship types with inverses
engram rel add <label> [--inverse inv]
engram rel rm <label>

Branch Overlays (feature branch knowledge tracking)

Use overlays when working on feature branches, reviewing PRs, or doing any work that hasn't merged yet. Overlays keep the base model clean while capturing architectural discoveries. Merge the overlay when the PR/branch merges; delete it if the branch is abandoned.

engram branch <model> <branch-name>             # create overlay
engram branch <model> --list                    # list overlays
engram merge <model> <branch-name>              # fold into parent
engram branch <model> <branch-name> --delete    # discard

# Add nodes/edges to an overlay (use --branch flag)
engram add <model> <label> -t <type> -m key=value --branch <branch-name>
engram link <model> <source> <rel> <target> --branch <branch-name>

Key rule: When working on a feature branch, always use --branch <branch-name>. Only write directly to the base model for merged/stable knowledge.

Git Integration (code models only)

engram check <model>       # compare anchor vs HEAD, show affected nodes
engram refresh <model>     # update anchor to HEAD, mark all verified
engram diff <model>        # detailed file-by-file diff with affected subgraph
engram stale <model>       # show stale nodes and edges

Cross-Model

engram xlink <model1> <node1> <rel> <model2> <node2>

Batch

echo "add mymodel NodeA --type service
add mymodel NodeB --type database
link mymodel NodeA depends-on NodeB" | engram batch mymodel

Scaffold (auto-generate engram from repo)

Generate a starting-point engram from a repository's file structure. Outputs batch import commands for top-level modules, API routes, services, workflows, clients, and commands.

# Preview what would be generated (no changes)
engram-scaffold ~/path/to/repo model-name --dry-run

# Generate batch file, then import (scaffold.sh lives in the engram repo's tools/ directory)
./tools/scaffold.sh ~/path/to/repo model-name
engram batch <model> < /tmp/engram-scaffold-*.txt

The scaffold is a skeleton — enrich nodes with descriptions and add cross-service relationship edges after import. Supports Node.js/TypeScript repos (Medusa, NestJS, CLI), monorepos.

Built-in Types (extensible)

thing
├── code: component, page, widget, hook, function, service, microservice,
│         middleware, database, library, config, script, test-runner, module
├── org: person, team, role, company
├── infra: server, container, network, endpoint
└── concept: process, event, rule

Type queries include subtypes: engram q model -t service finds services AND microservices.

Built-in Relationships (extensible)

Relationship Inverse
calls called_by
depends_on depended_on_by
contains contained_in
owns owned_by
uses used_by
extends extended_by
implements implemented_by
configures configured_by
produces produced_by
consumes consumed_by
proxies_to proxied_by
manages managed_by
tests tested_by
belongs_to has_member
renders rendered_by

Best Practices for Building Models

First Install: Seed Your Environment

On first use, scan your workspace and create models for:

  • Code — repos you work on. Modules, services, dependencies.
  • Org — company structure. People, teams, repos, service relationships, trust levels.
  • Infrastructure — local tools. Email chains, SSH configs, credential paths, channel setups.
  • People — who you interact with. Roles, channels, trust levels (owner/boss/coworker/friend).

A fresh session should be able to query the graph and understand your operational context immediately. This is a one-time investment that compounds every session.

The Hybrid Approach (Recommended)

After testing both "review everything first, then batch" and "enter as you go", the optimal workflow is:

  1. Explore first (5-10 min) — Scan the codebase or domain. Read key files, understand major components. Don't enter anything yet.

  2. Batch the skeleton — Create all major nodes and their primary relationships in one batch command. This captures the obvious architecture quickly.

    engram batch myapp <<EOF
    add Frontend --type component -m file=src/App.tsx
    add API --type service -m file=src/api/server.ts
    add DB --type database
    link Frontend calls API
    link API depends_on DB
    EOF
    
  3. Add discoveries incrementally — During coding, when you discover non-obvious relationships (e.g., "this function silently depends on NODE_ENV being set"), add them immediately:

    engram upsert myapp isPubSubDisabled --type function -m "note=returns false in production regardless of DISABLE_AUTH"
    engram link myapp fleet-rest calls isPubSubDisabled
    
  4. Review after sessions — Quick pass: "Did I discover anything worth keeping?" Batch any accumulated additions.

What to Model (and What Not To)

DO model:

  • Services, modules, and their dependencies (the skeleton)
  • Non-obvious relationships you'll forget (the surprises)
  • Cross-repo connections (A calls B in a different repo)
  • Config dependencies that cause subtle bugs
  • External service integrations

DON'T model:

  • Every file in the repo (too granular, maintain cost > query value)
  • Internal function calls within a single module (grep handles this)
  • Dependencies that are obvious from imports (the code is the model)
  • Anything that changes every commit (constant staleness)

Granularity Sweet Spot

Module/service level is the sweet spot for code models. Too fine (every function) = expensive to maintain. Too coarse (just repo names) = barely better than a README. The test: would a new session benefit from knowing this relationship exists? If yes, model it.

Org Charts and People Graphs

The tool handles org charts well with type: org models and type: person nodes. A few tips:

Dual-reporting: People often report to multiple managers. Use multiple reports_to links — the graph handles this naturally:

engram link Ken reports_to Tom
engram link Ken reports_to Deepak

Part-time / contractor status: Encode employment status in metadata, not separate node types:

engram add Brandon --type person -m role="Hardware Manager (Part-Time)"

Hierarchy queries work well: engram q org --affects CEO shows everyone who reports up to that person (direct and transitive). engram path org Engineer CEO shows the reporting chain.

Iterative correction is the norm. Org charts are rarely right on the first pass — you'll get the public website version, then the human corrects you. Batch the skeleton from public info, then update incrementally as corrections come in. The rm and unlink commands make this cheap.

Keep it current: People leave, roles change. Org models go stale faster than code models. When you learn someone left, rm them immediately rather than marking them inactive.

Common Workflows

Map a codebase architecture

engram create myapp -t code -d "My application" -r /path/to/repo
engram add myapp Frontend --type component -m file=src/App.tsx
engram add myapp API --type service -m file=src/api/server.ts -m port=3000
engram add myapp DB --type database -m engine=postgres
engram link myapp Frontend calls API -m via="REST /api"
engram link myapp API depends-on DB
engram refresh myapp   # anchor to current git HEAD

Check blast radius before a change

engram q myapp --affects API       # everything upstream of API
engram path myapp Frontend DB      # all paths from Frontend to DB
engram check myapp                 # what git changes affect which nodes

Branch overlay for feature work

engram branch myapp feature/new-cache
engram add myapp Redis --type database
engram link myapp API uses Redis
# ... later ...
engram merge myapp feature/new-cache   # fold changes into base model

Share models between agents (JSON-LD)

engram export myapp -f jsonld -o myapp.jsonld    # export with semantic context
engram import myapp.jsonld                        # another agent imports it

Visualize with Graphviz

engram export myapp -f dot | dot -Tpng -o graph.png   # requires graphviz installed
engram export myapp -f dot -o myapp.dot                # save DOT file

Track freshness over time

engram stale myapp --days 7        # what hasn't been verified this week?
engram verify myapp API            # mark a node as freshly verified
engram refresh myapp               # mark everything verified (after review)

Maintain engrams with git diffs

When code changes, use engram check to see which nodes are affected, then update:

# 1. See what changed since last review
engram check myapp
# Output: lists changed files → affected nodes → affected edges

# 2. For cosmetic/rename changes (no structural change): just refresh
engram refresh myapp

# 3. For structural changes (new files, new dependencies, removed modules):
#    a. Check what's new/deleted
engram diff myapp
#    b. Add nodes for new files
engram add myapp NewService --type service -m file=src/new-service.ts
engram link myapp API calls NewService
#    c. Remove nodes for deleted files
engram rm myapp OldService
#    d. Update metadata if file paths changed
engram update myapp SomeModule -m file=src/new-path/module.ts
#    e. Refresh to anchor at new HEAD
engram refresh myapp

Key principle: check shows you what's stale, diff shows the detail, and refresh marks everything verified. The git anchor tracks when you last reviewed the model — it's not automatic sync, it's aided maintenance.

The file→node mapping is the bridge. Always include file=path/to/file.ts in node metadata — this is what check and diff use to map git changes to graph nodes. Without it, the node won't appear in staleness reports.

After a rename/refactor: If you renamed files but the structure is the same, just update file metadata and refresh. If you restructured (split a module, merged services), update the graph to match and then refresh.

Updating engrams after code changes (source-of-truth workflow)

When you've just modified code and need to update the model, always verify against the actual source — never update from memory alone.

# 1. See what files changed (the source of truth)
cd /path/to/repo && git diff HEAD~N --stat        # or git diff main..branch --stat

# 2. For each changed file, review what actually changed
git diff HEAD~N -- src/changed-file.ts

# 3. List current engram nodes for this model
engram nodes mymodel

# 4. Cross-reference: for each changed file, find its engram node(s)
#    Check if the node's metadata/note is still accurate
#    Check if edges are still correct (added/removed imports, calls, etc.)

# 5. Update stale nodes with verified information from the diff
engram update mymodel <node-id> -m 'note=Updated description from actual code'

# 6. Check for stale edges (did you remove a dependency? add a new call?)
engram edges mymodel --from <changed-node>
engram edges mymodel --to <changed-node>
# Remove edges that no longer exist, add new ones

# 7. Add nodes for new exports/modules introduced in the changes
engram upsert mymodel NewThing -t function -m file=src/file.ts 'note=...'

# 8. Refresh the git anchor
engram refresh mymodel

Anti-pattern: Updating engram nodes from working memory of what you think you changed. The code is the source of truth — always git diff first, then update the graph to match. This is especially important after multi-file refactors where it's easy to miss removed dependencies or new relationships.

The 30-second rule: If you can't verify an engram update against the actual source in 30 seconds, you're guessing. Run the diff.

推荐文章

更多
PHP时间戳与日期字符串相互转换方法详解

本文介绍PHP中时间数值(Unix时间戳)与日期字符串之间的相互转换方法。通过strtotime和date函数,实现将当前时间、指定日期转换为时间戳,以及将时间戳格式化为可读的日期时间字符串,并提供相关在线计算工具推荐。

2025.11.30 1,034
PHP日期转时间戳时区偏差怎么解决

在 PHP 中将日期字符串转换为时间戳时,若未显式指定时区,默认使用脚本配置的 date.timezone 或系统时区。当服务器时区与业务逻辑预期(如 UTC )不一致时,会产生偏差。解决核心是确保输入字符串携带明确时区信息,或在转换前统一设置时区上下文。

2026.10.24 1,031
PHP跨域配置:怎么安全地允许指定域名而非使用通配符

在 PHP 中安全地允许指定域名跨域,核心是解析请求头中的 Origin ,验证其是否在白名单内,然后动态设置 Access-Control-Allow-Origin 响应头。不要使用通配符 * ,也不要硬编码单一域名。

2025.03.29 1,018
JavaScript中利用replace结合正则实现replaceAll效果

JavaScript原生仅支持replace()进行单次或全局替换,缺乏类似Java的replaceAll()便捷方法。本文总结四种在JS中实现全量替换的方案:使用带g标志的正则、带gm标志的正则、扩展String原型以及split后join。通过对比代码示例,展示各方法的实现细节与适用场景,帮助开发者根据需求选择最优解。

2025.04.29 1,017
OpenAI的Jalapeno芯片未落地,教你分辨300兆瓦算力消息

OpenAI计划在SB Energy租赁的数据中心部署约300兆瓦自研Jalapeno推理芯片,但目前双方仍处于洽谈阶段,交易细节与上线时间表均未公布。本文带你按报道原文核实项目所处阶段,厘清芯片发布、电力功率与实际推理算力的边界,并将融资意向与签约、开工、投运节点分开追踪,避免误将规划容量计入现有算力。

2026.12.02 1,013
PHP实现基础文件上传:HTML表单与$_FILES处理流程

在 HTML 表单中设置 enctype="multipart/form-data" ,并在 PHP 后端通过 $_FILES 数组接收文件,调用 move_uploaded_file() 将临时文件移动到目标目录即可完成上传。

2026.09.07 1,013
Skill 文件
  • SKILL.md
    • Engram
    • Installation
    • How to Run
    • Quick Reference
      • Models (containers for graphs)
      • Nodes
      • Edges
      • Queries
      • Search (cross-model)
      • Types & Relationships
      • Branch Overlays (feature branch knowledge tracking)
      • Git Integration (code models only)
      • Cross-Model
      • Batch
      • Scaffold (auto-generate engram from repo)
    • Built-in Types (extensible)
    • Built-in Relationships (extensible)
    • Best Practices for Building Models
      • First Install: Seed Your Environment
      • The Hybrid Approach (Recommended)
      • What to Model (and What Not To)
      • Granularity Sweet Spot
      • Org Charts and People Graphs
    • Common Workflows
      • Map a codebase architecture
      • Check blast radius before a change
      • Branch overlay for feature work
      • Share models between agents (JSON-LD)
      • Visualize with Graphviz
      • Track freshness over time
      • Maintain engrams with git diffs
      • Updating engrams after code changes (source-of-truth workflow)
  • 项目或源文件

相关 Skill

更多
service-qa-coach service-qa-coach Review support quality for chat, email, phone, social DM, or marketplace service teams. Use when a team needs a QA scorecard, failure-mode analysis, coaching plan, calibration checklist, or service-improvement brief without live ticketing, CRM, or contact-center system access.
高中数学作业批改助手 高中数学作业批改助手 >图片识别 直接读取学生手写作答照片,识别公式、符号、步骤 🧮 自动推导 根据题目自动生成参考答案和评分细则,无需教师预设 📊 逐步给分 每个关键步骤独立评分,体现过程分 📝 结构化报告 输出含识别内容、参考答案、逐步评分、改进建议的完整报告 🗂 批量批改 支持一次性批改多道题,最终汇总得分表
Vibration Analysis Vibration Analysis 分析来自CMS趋势、RMS/峰值、频谱及SCADA报警的风机传动链(主轴、齿轮箱、发电机)振动数据。
Traditional Bone Tool Making Basics Traditional Bone Tool Making Basics Use when you need custom, durable, repairable tools like awls, needles, scrapers, harpoons, or fishing hooks made from local animal bones or antlers and comm...
音频混音工具 音频混音工具 名称:Sound Mixing Tool(标识 sound-mixing-tool) 短简介(≤60字):音乐/音效响度精确对齐 + 融合混音工作流:用 ffmpeg 两段式 loudnorm 把多组素材 LUFS 偏差压到 <0.10,再最小干预融合、导出可进引擎的独立分轨。 标签/关键词:音频混音 响度匹配 LUFS ffmpeg 游戏音频 音效设计 Wwise FMOD 分轨导出 后期处理 触发词:混音 · 响度匹配 · LUFS 对齐 · MIX 版本 · 音乐音效分轨 · 融合 · 不打架 · 不能盖住 适用场景 :游戏音频集成、影视短视频配乐、播客后期