agentleFS
maithanhduyanmaithanhduyan/memory-graph/.github/copilot-instructions.md

memory-graph

Copilot instructions1 starsChanged 11 months agoMITView on GitHub

Usage Guidelines: - Sử dụng đồ thị tri thức để tổ chức và lưu trữ thông tin quan trọng, giúp chống lại việc quên lãng thông tin. - Hỗ trợ các công cụ quản lý bộ nhớ như tạo thực thể, tạo quan hệ, thêm quan sát, xóa thực thể, xóa quan sát, xóa quan hệ, đọc đồ thị, tìm kiếm nút và mở nút. - Đảm bảo rằng tất cả các đề xuất tuân thủ giao thức MCP và…

The file

We split this copilot-instructions.md into the rules it gives an agent

2 rules. About 0 are common, 2 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Search tự động expand với synonyms:

    line 95
  2. Distinctive:

    Important Note: Always prioritize the integrity and efficiency of the knowledge graph when making suggestions or changes.

    line 364

≈ “Common” is an estimate: at least 1 in 5 of the 1,644 Copilot instructions files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
copilot-instructions.md

Memory Graph MCP Server - AI Agent Instructions

Project Manager Instructions

You are an AI agent integrated with the Memory Graph <memory>. Your role is to assist developers by providing code suggestions, documentation, and answering questions related to the project.

Usage Guidelines:

  • Sử dụng đồ thị tri thức để tổ chức và lưu trữ thông tin quan trọng, giúp chống lại việc quên lãng thông tin.
  • Hỗ trợ các công cụ quản lý bộ nhớ như tạo thực thể, tạo quan hệ, thêm quan sát, xóa thực thể, xóa quan sát, xóa quan hệ, đọc đồ thị, tìm kiếm nút và mở nút.
  • Đảm bảo rằng tất cả các đề xuất tuân thủ giao thức MCP và sử dụng định dạng JSON-RPC 2.
  • Giúp duy trì và cải thiện hiệu suất của hệ thống lưu trữ dữ liệu JSONL.
  • Cung cấp hướng dẫn chi tiết về cách xây dựng, chạy và sử dụng máy chủ MCP trong môi trường phát triển như VSCode.
  • Hỗ trợ phát triển các tính năng mới và sửa lỗi trong mã nguồn Rust của dự án.

Features - 15 Tools

Memory Tools (9)

ToolDescriptionKey Parameters
create_entitiesTạo entities mớientities[] với name, entityType, observations[], createdBy?, updatedBy?
create_relationsTạo relations giữa entitiesrelations[] với from, to, relationType, createdBy?, validFrom?, validTo?
add_observationsThêm observations vào entityobservations[] với entityName, contents[]
delete_entitiesXóa entitiesentityNames[]
delete_observationsXóa observations cụ thểdeletions[] với entityName, observations[]
delete_relationsXóa relationsrelations[]
read_graphĐọc graph với paginationlimit?, offset?
search_nodesTìm kiếm với synonym matchingquery, limit?, includeRelations?
open_nodesMở nodes theo tênnames[]

Query Tools (3)

ToolDescriptionUse Case
get_relatedLấy entities liên quanTìm dependencies, xem connections
traverseDuyệt graph theo path patternMulti-hop queries, tìm indirect relations
summarizeTóm tắt entitiesOverview nhanh, statistics

Temporal Tools (2)

ToolDescriptionUse Case
get_relations_at_timeQuery relations hợp lệ tại timestamp"Alice ở đâu năm 2024?"
get_relation_historyXem toàn bộ lịch sử relationsTrack changes over time

Utility Tools (1)

ToolDescription
get_current_timeLấy timestamp hiện tại

Data Model

Entity Structure

{
  "name": "Feature: Auth",
  "entityType": "Feature",
  "observations": ["Implements JWT", "Uses bcrypt"],
  "createdBy": "Duyan",
  "updatedBy": "Duyan",
  "createdAt": 1704067200,
  "updatedAt": 1704153600
}

Relation Structure (with Temporal Support)

{
  "from": "Alice",
  "to": "NYC",
  "relationType": "lives_in",
  "createdBy": "Duyan",
  "createdAt": 1704067200,
  "validFrom": 1704067200,
  "validTo": 1735689599
}

User Attribution

Server tự động tracking ai tạo/cập nhật data:

FieldAuto-filled FromOverride
createdByGit config user.name → OS USER/USERNAME → "anonymous"Truyền trong params
updatedBySame as aboveAuto-update khi add_observations

Kịch bản sử dụng:

// AI tự trích xuất từ git blame
{"entities": [{"name": "Bug: Auth", "createdBy": "Huy", ...}]}

// Hoặc để server auto-fill từ môi trường
{"entities": [{"name": "Feature: X", ...}]}  // createdBy = current user

Semantic Search (Synonym Matching)

Search tự động expand với synonyms:

Search QueryAlso Matches
coderprogrammer, developer, engineer, dev
bugissue, defect, error, problem
donecompleted, finished, resolved
criticalurgent, p0, blocker

Tip: Không cần lo về từ vựng chính xác, search sẽ tìm semantic equivalents.

Best Practices

1. Pagination cho Large Graphs

// Đừng: read toàn bộ graph
{"tool": "read_graph", "params": {}}

// Nên: dùng pagination
{"tool": "read_graph", "params": {"limit": 50, "offset": 0}}

2. Temporal Relations cho Data Changes

// Khi data thay đổi, ĐỪNG xóa relation cũ
// Thay vào đó, set validTo và tạo relation mới

// Alice chuyển từ NYC sang Tokyo
// Step 1: Update relation cũ với validTo
// Step 2: Tạo relation mới với validFrom
{
  "from": "Alice", "to": "Tokyo",
  "relationType": "lives_in",
  "validFrom": 1735689600
}

3. Search với includeRelations

// Khi chỉ cần entities (faster):
{"tool": "search_nodes", "params": {"query": "Bug", "includeRelations": false}}

// Khi cần context đầy đủ:
{"tool": "search_nodes", "params": {"query": "Bug", "includeRelations": true}}

Workflow

1. Khi bắt đầu dự án mới:

AI Agent nên:

  1. read_graph(limit: 100) → scan existing context
  2. Scan project structure → create_entities cho Modules
  3. Đọc README, docs → create_entities cho Conventions, Decisions
  4. Đọc schema files → create_entities cho Schemas
  5. Hỏi user về business rules → create_entities cho BusinessRules

2. Khi phát triển tính năng mới:

  1. Trước khi code: search_nodes để lấy context
  2. Khi discover something new: add_observations
  3. Khi tạo file/module mới: create_entities
  4. Khi fix bug: tạo Bug entity với root cause
  5. Khi make decision: tạo Decision entity với reasoning

3. Khi switch context:

User: "Giờ làm feature X trong module Y"

AI Agent:
1. open_nodes(["Module: Y"]) → dependencies, patterns
2. search_nodes("Y") → related files, schemas
3. get_related("Module: Y") → xem connections
4. Có đủ context để tiếp tục mà không hỏi lại

4. Khi query historical data:

User: "Alice làm việc ở đâu năm 2024?"

AI Agent:
1. get_relations_at_time(timestamp: 1704067200, entityName: "Alice")
2. Trả về relations hợp lệ tại thời điểm đó

Flow hoạt động chuẩn

Goal
↓
search_nodes() → get context
↓
Decision → create_entities(Decision)
↓
Action → add_observations()
↓
Error? → create_entities(Bug) → Fix → add_observations(Lesson)
↓
Success → create_relations() với validFrom
↓
Memory updated ✓

Entity Types Reference

TypePurposeExample
ProjectDự án chính"Memory Graph MCP"
ModuleThành phần code"Auth Module"
FeatureTính năng"Feature: Pagination"
BugLỗi đã fix"Bug: Context Overflow"
DecisionQuyết định thiết kế"Decision: Use JSONL"
RequirementYêu cầu"Req: Multi-tenant"
MilestoneMốc dự án"v1.0 Release"
RiskRủi ro"Risk: Scale Limit"
ConventionCoding standards"Naming Convention"
SchemaData structures"User Schema"PersonNgười dùng/Team"John Doe", "Backend Team"

Relation Types Reference

TypeDescriptionExample
containsA chứa BProject contains Module
implementsA triển khai BModule implements Feature
fixesA sửa BCommit fixes Bug
caused_byA gây ra bởi BBug caused_by Decision
depends_onA phụ thuộc BFeature depends_on Feature
blocked_byA bị chặn bởi BTask blocked_by Bug
assigned_toA được giao cho BBug assigned_to Person
part_ofA là phần của BModule part_of Project
relates_toA liên quan BGeneric relation
supersedesA thay thế BDecision supersedes Decision
affectsA ảnh hưởng BBug affects Module
requiresA yêu cầu BFeature requires Requirement

Note: Server sẽ trả về warning nếu dùng type không chuẩn. Vẫn cho phép custom types nhưng khuyến khích dùng standard types.

Improvement Suggestions

Đã implement ✅

  • Pagination (limit/offset) cho large graphs
  • Temporal relations (validFrom/validTo)
  • Synonym matching cho semantic search
  • Timestamps (createdAt/updatedAt)

Future Enhancements 🚀

  1. Vector Embeddings: Upgrade từ synonym matching sang true semantic search với embeddings
  2. Graph Visualization: Web UI để visualize knowledge graph
  3. Auto-summarization: Tự động tóm tắt entities khi graph quá lớn
  4. Conflict Detection: Phát hiện observations mâu thuẫn
  5. Import/Export: Sync với external knowledge bases
  6. Multi-tenant: Support nhiều projects trong 1 server

Context Preservation (CRITICAL)

Khi nào cần lưu vào Memory:

TriggerActionTool
Summarized conversation historyLưu summary vào entitycreate_entities hoặc add_observations
Mất bối cảnh (context lost)Lưu tiến độ hiện tạiadd_observations
Hoàn thành task lớnTạo entity mới với chi tiếtcreate_entities
Phát hiện bug/lessonGhi nhận để không lặp lạicreate_entities
Trước khi kết thúc sessionLưu pending workadd_observations

Khi Summarized conversation history:

AI Agent BẮT BUỘC phải:

  1. Tạo entity mới nếu đang làm task lớn chưa có trong graph:
{
  "entityType": "Feature|Bug|Decision|Task",
  "name": "Feature: [Tên feature đang làm]",
  "observations": [
    "Status: [In Progress|Completed|Blocked]",
    "Phase: [Phase hiện tại]",
    "Files modified: [danh sách files]",
    "Tests: [số tests passed/failed]",
    "Next steps: [việc cần làm tiếp]"
  ]
}
  1. Hoặc add observations vào entity đã tồn tại:
{
  "entityName": "Feature: [Tên feature]",
  "contents": [
    "[Timestamp] Session summary: ...",
    "Completed: [danh sách đã hoàn thành]",
    "Pending: [việc còn lại]",
    "Blockers: [nếu có]"
  ]
}

Khi mất bối cảnh (Context Lost):

Dấu hiệu nhận biết:

  • User nói "bạn đã quên", "tiếp tục việc đang làm"
  • AI không nhớ đang làm gì
  • Conversation bị reset/refresh

Recovery Flow:

1. search_nodes("Feature|Bug|Task") → tìm recent work
2. open_nodes([entity_name]) → lấy chi tiết
3. get_related(entity_name) → xem dependencies
4. Tiếp tục từ "Next steps" trong observations

Template cho Session Summary:

// Tạo entity mới cho task lớn
{
  "name": "Session: [YYYY-MM-DD] [Topic]",
  "entityType": "ConversationSummary",
  "observations": [
    "Duration: [thời gian làm việc]",
    "Goal: [mục tiêu ban đầu]",
    "Achieved: [đã đạt được gì]",
    "Files: [files đã tạo/sửa]",
    "Tests: [kết quả test]",
    "Decisions: [quyết định đã đưa ra]",
    "Learnings: [bài học rút ra]",
    "Next: [việc cần làm tiếp]"
  ]
}

Best Practices cho Context Preservation:

  1. Lưu thường xuyên: Sau mỗi milestone nhỏ, add observation
  2. Chi tiết hóa: Ghi rõ file paths, function names, line numbers
  3. Link entities: Tạo relations giữa tasks liên quan
  4. Timestamp: Luôn ghi thời gian để track progress
  5. Next steps rõ ràng: Để AI tiếp theo biết làm gì

Ví dụ thực tế:

// User: "Tiếp tục việc đang làm"
// AI đã mất context

AI Agent:
1. search_nodes("Feature|Task|Session", limit: 10)
   → Tìm thấy "Feature: Event Sourcing Architecture"

2. open_nodes(["Feature: Event Sourcing Architecture"])
   → Observations có "Next steps: Phase 8 - Enhancements"

3. AI biết cần làm Phase 8, tiếp tục không cần hỏi lại user

Auto-save Triggers

AI Agent PHẢI tự động lưu vào Memory Graph khi:

  1. "Summarized conversation history" xuất hiện
  2. User nói: "ghi nhớ", "lưu lại", "remember this"
  3. Hoàn thành task lớn (fix bug, implement feature)
  4. Đưa ra decision quan trọng
  5. Giải thích concept phức tạp mà user có thể cần lại
  6. Trước khi kết thúc session hoặc chuyển chủ đề lớn
  7. Khi thinking quá lâu không có tiến triển rõ ràng

Template khi lưu:

  • Dùng add_observations cho entity đã có
  • Dùng create_entities cho knowledge mới

Important Note: Always prioritize the integrity and efficiency of the knowledge graph when making suggestions or changes.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.