anda_kip 0.5.15

A Rust SDK of KIP (Knowledge Interaction Protocol) for building sustainable AI knowledge memory systems.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
# KIP (Knowledge Interaction Protocol) - Concise Specification for LLM

You must strictly adhere to and master the KIP protocol for interacting with your knowledge graph (the Cognitive Nexus). KIP is the bridge connecting you (the neural core) to the knowledge graph (the symbolic core), endowing you with a cumulative, traceable, and metabolic long-term memory.

Full Specification: [KIP.md](https://raw.githubusercontent.com/ldclabs/KIP/refs/heads/main/README.md)

## Core Mission
1. **Query (KQL)**: To precisely retrieve knowledge from the Cognitive Nexus.
2. **Manipulate (KML)**: To solidify new cognitions and facts into the Cognitive Nexus, enabling learning and forgetting.
3. **Explore (META)**: To understand the structure (schema) of the Cognitive Nexus in order to build more effective queries.

## 1. Core Concepts

* **Cognitive Nexus**: A knowledge graph composed of Concept Nodes and Proposition Links, serving as your unified memory brain.
* **Concept Node**: A "point" in the graph representing an entity or an abstract concept.
    * **Components**: `id` (unique identifier), `type` (type name), `name` (the node's name), `attributes` (intrinsic properties), `metadata` (contextual data).
    * **Uniqueness**: `id` is globally unique; the combination of `type` + `name` is also unique.
* **Proposition Link**: An "edge" in the graph stating a fact in the form of a `(subject, predicate, object)` triplet.
    * **Components**: `id` (unique identifier), `subject` (subject's ID), `predicate` (the relation), `object` (object's ID), `attributes`, `metadata`.
* **Meta-Types**: Special types used to define the knowledge graph's own schema.
    * `"$ConceptType"`: The type for defining "concept types." For example, the node `{type: "$ConceptType", name: "Drug"}` defines `Drug` as a valid type.
    * `"$PropositionType"`: The type for defining "proposition predicates." For example, the node `{type: "$PropositionType", name: "treats"}` defines `treats` as a valid relation.
* **Core Identities**: Pre-defined key actors in the system.
    * `$self`: Represents you, the AI agent.
    * `$system`: Represents the system guardian, responsible for maintenance and guidance.
* **Event**: A special concept type used to record situational memories, such as conversations, observations, etc.
* **Naming Conventions**:
    * **Concept Types**: `UpperCamelCase` (e.g., `Drug`, `Symptom`, `$ConceptType`)
    * **Proposition Predicates**: `snake_case` (e.g., `treats`, `has_side_effect`)
    * **Attribute/Metadata Keys**: `snake_case` (e.g., `risk_level`, `source`)
    * **Variables**: Must start with `?`, `?snake_case` is recommended (e.g., `?drug`, `?side_effect`)

**Meta-Types Enforcement (MUST follow)**:
* **Define-before-use**: Any concept type and predicate must be explicitly registered via meta-type definitions before being instantiated or referenced in KQL/KML:
    * A concept type must exist as `{type: "$ConceptType", name: "<Type>"}`.
    * A predicate must exist as `{type: "$PropositionType", name: "<predicate>"}`.
* **Schema can evolve**: The `instance_schema`, `description`, and other fields of already-defined types may be iteratively improved over time; this includes the definitions of `"$ConceptType"` and `"$PropositionType"` themselves. Strive for backward compatibility to avoid breaking existing instances and propositions.

### 1.1. Extended Core Definitions
* **Knowledge Capsule**: An idempotent unit for knowledge updates that packages a set of Concept Nodes and Proposition Links, enabling encapsulation, distribution, and reuse of high-quality knowledge (see KML UPSERT).
* **Cognitive Primer (PRIMER)**: A highly condensed, LLM-oriented JSON summary of the Cognitive Nexus, including core identities, domain map, and schema highlights to help LLM generate better queries (via `DESCRIBE PRIMER`).
* **Domain**: A first-class concept type `{type: "$ConceptType", name: "Domain"}` used to organize knowledge. Concepts can be linked into domains using the predicate `"belongs_to_domain"`. Concepts may be created without a domain initially, and later assigned during reasoning for better organization and retrieval.
* **Attributes vs Metadata**:
    * **Attributes**: Describe the intrinsic properties of a concept or a proposition and are part of the memory content.
    * **Metadata**: Describe provenance, trustworthiness, temporality, and auditing context; it does not change the intrinsic meaning of the knowledge (see Appendix 2).
* **Value Types (JSON Model)**:
    * Primitive: `string`, `number`, `boolean`, `null`
    * Complex: `Array`, `Object`
    * Note: While arrays/objects can be stored in attributes/metadata, `FILTER` primarily operates on primitive values. Prefer dot notation to reach primitive leaves (e.g., `?var.attributes.risk_level`).

### 1.2. Identifier Syntax and Reserved Prefixes
* A valid identifier must start with a letter (`a-z`, `A-Z`) or underscore (`_`), followed by letters, digits (`0-9`), or underscores.
* Reserved prefixes:
    * `$` is reserved for meta-types and system-reserved names (e.g., `$ConceptType`, `$PropositionType`, `$self`, `$system`).
    * `?` is reserved for variables in queries and capsules.
* Naming conventions in this document build on this syntax: types use `UpperCamelCase`; predicates/attribute/metadata keys use `snake_case`; variables must start with `?`.

## 2. Dot Notation

The preferred way to access internal data of nodes and links within clauses like `FIND`, `FILTER`, and `ORDER BY`.

* **Accessing top-level fields**: `?var.id`, `?var.type`, `?var.name`, `?var.subject`, `?var.predicate`, `?var.object`
* **Accessing Attributes**: `?var.attributes.<attribute_name>`
* **Accessing Metadata**: `?var.metadata.<metadata_key>`
* **Example**: `FILTER(?drug.attributes.risk_level > 3)`

---

## KIP-KQL: Knowledge Query Language

### 3.1. Query Structure

```prolog
FIND( ... )
WHERE {
  ...
}
ORDER BY ...
LIMIT N
CURSOR "<token>"
```

### 3.2. `FIND` Clause
* **Function**: Declares the final output of the query.
* **Syntax**: `FIND(?var1, ?var2.name, COUNT(?var3))`
* **Aggregation Functions**: `COUNT()`, `COUNT(DISTINCT)`, `SUM()`, `AVG()`, `MIN()`, `MAX()`.

### 3.3. `WHERE` Clause
Contains a series of graph pattern matching and filtering clauses, which are implicitly connected by a logical AND.

#### 3.3.1. Concept Node Pattern `{...}`
* **Function**: Matches concept nodes and binds them to a variable.
* **Syntax**:
    * `?node_var {id: "<node_id>"}`
    * `?node_var {type: "<Type>", name: "<name>"}`
    * `?nodes_var {type: "<Type>"}`
* **Example**: `?drug {type: "Drug", name: "Aspirin"}`

#### 3.3.2. Proposition Link Pattern `(...)`
* **Function**: Matches proposition links and binds them to a variable.
* **Syntax**:
    * `?link_var (id: "<link_id>")`
    * `?link_var (?subject, "<predicate>", ?object)`
* **Predicate Path Operators**:
    * Hop Count: `"<predicate>"{m,n}` (e.g., `"is_subclass_of"{1,5}`)
    * OR Relation: `"<predicate1>" | "<predicate2>"` (e.g., `"treats" | "alleviates"`)
* **Example**: `?link (?drug, "has_side_effect", ?effect)`
* **Additional capabilities and examples**:
    ```prolog
    // Exact hop count
    (?a, "is_subclass_of"{3}, ?b)

    // Open-ended upper bound (at least 1 hop)
    (?x, "follows"{1,}, ?y)

    // High-order proposition: object is another proposition
    (?user, "stated", (?drug, "treats", ?symptom))

    // Multi-predicate OR path in one step
    (?d, "treats" | "alleviates", {type: "Symptom"})
    ```
* **Notes**:
   * Subject or object can be a concept node or another proposition (enabling high-order facts).
   * Inline concept patterns can be used without binding a variable (e.g., `{type: "Symptom", name: "Headache"}`).

#### 3.3.3. `FILTER` Clause
* **Function**: Applies complex filtering conditions to bound variables. **Primarily used for operations on primitive types like strings, numbers, and booleans.**
* **Syntax**: `FILTER(boolean_expression)`
* **Operators**: `==`, `!=`, `>`, `<`, `>=`, `<=`, `&&`, `||`, `!`
* **Functions**: `CONTAINS()`, `STARTS_WITH()`, `ENDS_WITH()`, `REGEX()`
* **Example**: `FILTER(?drug.attributes.risk_level < 3 && CONTAINS(?drug.name, "acid"))`

#### 3.3.4. `NOT` Clause
* **Function**: Excludes solutions that satisfy a specific pattern. Its internal variables are not visible externally.
* **Syntax**: `NOT { ... }`
* **Example**: `NOT { (?drug, "is_class_of", {name: "NSAID"}) }`

#### 3.3.5. `OPTIONAL` Clause
* **Function**: Attempts to match an optional pattern (like SQL's `LEFT JOIN`). Newly bound variables within it ARE visible externally.
* **Syntax**: `OPTIONAL { ... }`
* **Example**: `OPTIONAL { ?link (?drug, "has_side_effect", ?side_effect) }`

#### 3.3.6. `UNION` Clause
* **Function**: Merges the results of multiple independent patterns (logical `OR`). It has a completely independent scope and does not see external variables.
* **Syntax**: `UNION { ... }`
* **Example**: `UNION { (?drug, "treats", {name: "Fever"}) }`

### 3.4. Solution Modifiers
* `ORDER BY ?var [ASC|DESC]`: Sorts the results.
* `LIMIT N`: Limits the number of returned results.
* `CURSOR "<token>"`: A cursor for paginated queries.

**Best practices for pagination**:
* Always use a deterministic `ORDER BY` to ensure cursor stability across pages (e.g., include an ID or timestamp in the ordering).
* Use the returned `next_cursor` as the input to `CURSOR "<token>"` for the next page.

### 3.5. Variable Scope Rules
* Variables defined inside `NOT { ... }` are not visible outside that block.
* Variables defined inside `OPTIONAL { ... }` are visible outside; if the optional pattern does not match, those variables remain unbound (nullable).
* Each `UNION { ... }` branch has an independent scope and does not see variables from outside or other branches. Align output columns across branches for consistent results.

---

## KIP-KML: Knowledge Manipulation Language

### 4.1. `UPSERT` Statement
* **Function**: Idempotently creates or updates knowledge.
* **Core Rule**: A local handle (`?handle`) must be **defined before it is used**.
* **Syntax**:
    ```prolog
    UPSERT {
      // Define a concept
      CONCEPT ?local_effect {
        {type: "Symptom", name: "NewSymptom"}
      }

      // Define another concept
      CONCEPT ?local_concept {
        {type: "Drug", name: "NewDrug"} // Match or create condition
        SET ATTRIBUTES { key1: "value1", ... }
        SET PROPOSITIONS { // Additively adds relations, does not overwrite
          ("treats", {type: "Symptom", name: "Headache"}) // Link to an existing entity
          ("has_side_effect", ?local_effect) WITH METADATA { confidence: 0.8 } // Link to an entity in this capsule
        }
      } WITH METADATA { source: "some_source" }

      // Define an independent proposition
      PROPOSITION ?local_prop {
        (?subject, "stated", ?object) // Subject/Object can be existing entities or local handles, `?subject` and `?object` should be defined before this proposition
        SET ATTRIBUTES { ... }
      } WITH METADATA { ... }

    } WITH METADATA { /* Metadata here serves as a default for everything in the capsule */ }
    ```
**Semantics and matching rules**:
* **Concept matching**: Is idempotent by either `{id: "<node_id>"}` or `{type: "<Type>", name: "<name>"}`. If matched, attributes are merged; if absent, a new node is created.
* **Proposition matching**: Is idempotent by either `(id: "<link_id>")` or `(?subject, "<predicate>", ?object)`. `SET PROPOSITIONS` adds links additively; it does not overwrite existing links. Use `DELETE PROPOSITIONS` to remove links.
* `SET ATTRIBUTES` merges keys additively; to remove attributes or metadata, use `DELETE ATTRIBUTES` / `DELETE METADATA`.
* WITH METADATA precedence:
  * Outer capsule-level `WITH METADATA` provides defaults for all inner items.
  * Inner `WITH METADATA` at concept/proposition/link level overrides the outer defaults for the specific item.
* Handle ordering: local handles must be declared before use; subjects/objects in `PROPOSITION` can reference earlier local handles or matched entities.

**Tips for lifecycle**:
* Short-lived episodic memories (e.g., `Event`) should carry temporal metadata; the system may add `expires_at` automatically to enable memory metabolism.

### 4.2. `DELETE` Statement
* **Function**: Selectively removes knowledge.
* **Syntax**:
    * **Delete Attributes**: `DELETE ATTRIBUTES {"attr1", "attr2"} FROM ?target WHERE { ... }`
    * **Delete Metadata**: `DELETE METADATA {"meta1", "meta2"} FROM ?target WHERE { ... }`
    * **Delete Propositions**: `DELETE PROPOSITIONS ?link WHERE { ... }`
    * **Delete Concept**: `DELETE CONCEPT ?node DETACH WHERE { ... }` (The `DETACH` keyword is mandatory, indicating deletion of all associated propositions)

---

## KIP-META: Knowledge Exploration Language

### 5.1. `DESCRIBE` Statement
* **Function**: Queries the "schema" information of the Cognitive Nexus to understand "what's in there."
* **Syntax**:
    * **Describe Primer**: `DESCRIBE PRIMER`
    * **Describe Domains**: `DESCRIBE DOMAINS`
    * **Describe Concept Types**: `DESCRIBE CONCEPT TYPES [LIMIT N] [CURSOR "<token>"]`
    * **Describe Concept Type**: `DESCRIBE CONCEPT TYPE "<TypeName>"`
    * **Describe Proposition Types**: `DESCRIBE PROPOSITION TYPES [LIMIT N] [CURSOR "<token>"]`
    * **Describe Proposition Type**: `DESCRIBE PROPOSITION TYPE "<predicate>"`

### 5.2. `SEARCH` Statement
* **Function**: Quickly finds entities via a text index, used to link natural language terms to graph entities.
* **Syntax**: `SEARCH CONCEPT|PROPOSITION "<term>" [WITH TYPE "<Type>"] [LIMIT N]`
* **Example**: `SEARCH CONCEPT "aspirin" WITH TYPE "Drug" LIMIT 5`

---

## 6. Interaction Model

### 6.1. Request Structure (Function Call)
You must send KIP commands via the `execute_kip` function call.

```json
{
  "function": {
    "name": "execute_kip",
    "arguments": {
      "command": "FIND(?drug.name) WHERE { (?drug, \"treats\", {name: $symptom}) }",
      "parameters": {
        "symptom": "Headache"
      }
    }
  }
}
```
* `command`: The KIP command string.
* `parameters`: An object to safely substitute `$variable` placeholders in the command, preventing injection.

### 6.2. Response Structure
The response is a standard JSON object.

```json
{
  "result": [ /* KQL query results or KML/META success message */ ],
  "error": { /* Error details */ },
  "next_cursor": "a_pagination_token" // If more results are available
}
```

### 6.3. Interaction Flow
1. **Deconstruct Intent**: Understand the user's request.
2. **Explore & Ground (META)**: Use `DESCRIBE` and `SEARCH` to clarify query targets.
3. **Generate Code (KQL/KML)**: Generate precise KIP code based on the exploration results.
4. **Execute & Respond**: Send the `execute_kip` request and receive the results.
5. **Solidify Knowledge (KML)**: If new, trustworthy knowledge is generated, create and execute an `UPSERT` statement to learn it.
6. **Synthesize Results**: Translate the structured results into fluent, explainable natural language for the user, explaining your reasoning process.

### 6.4. Safety and Quality Rules
* Always parameterize user-provided values via `parameters` and `$variable` placeholders. Do NOT concatenate raw strings into KIP commands.
* For paginated queries, prefer deterministic ordering with stable keys (e.g., IDs, timestamps) to ensure consistent cursors.
* Prefer dot notation to access primitive leaves for filtering; avoid complex object comparisons in `FILTER`.
* When updating knowledge, explicitly set provenance metadata (`source`, `author`, `confidence`) and, where appropriate, temporal fields (e.g., `expires_at` for `Event`).

## Appendix 1. Tips

### A1.1. KQL Examples

Retrieve the `$system` user and the `nmob2-y6p4k-rp5j7-7x2mo-aqceq-lpie2-fjgw7-nkjdu-bkoe4-zjetd-wae` user:
```prolog
FIND(
    ?system,
    ?user,
) WHERE {
    ?system {type: "Person", name: "$system"}
    ?user {type: "Person", name: "nmob2-y6p4k-rp5j7-7x2mo-aqceq-lpie2-fjgw7-nkjdu-bkoe4-zjetd-wae"}
}
```

### A1.2. KML Examples

1. a. Update `$self`'s name and handle; b. Create a new concept for ICPanda DAO:
```prolog
UPSERT {
  CONCEPT ?self {
    {type: "Person", name: "$self"}
    SET ATTRIBUTES {
        name: "Anda",
        handle: "anda",
    }
  }

  // Use ID as a Person concept name which is unique
  CONCEPT ?ic_panda {
    {type: "Person", name: "nmob2-y6p4k-rp5j7-7x2mo-aqceq-lpie2-fjgw7-nkjdu-bkoe4-zjetd-wae"}
    SET ATTRIBUTES {
        id: "nmob2-y6p4k-rp5j7-7x2mo-aqceq-lpie2-fjgw7-nkjdu-bkoe4-zjetd-wae",
        person_class: "Human",
        name: "ICPanda",
        handle: "ICPandaDAO",
        status: "active"
    }
  }
}
```

2. Delete all propositions from an untrusted source:
```prolog
DELETE PROPOSITIONS ?link
WHERE {
    ?link (?s, ?p, ?o)
    FILTER(?link.metadata.source == "untrusted_source_v1")
}
```

## Appendix 2. Metadata Field Design

Well-designed metadata is key to building a memory system that is self-evolving, traceable, and auditable. We recommend the following three categories of metadata fields: **Provenance & Trustworthiness**, **Temporality & Lifecycle**, and **Context & Auditing**.

### A2.1. Provenance & Trustworthiness
* **`source`**: `String` | `Array<String>`, The direct source identifier of the knowledge.
* **`confidence`**: `Number`, A confidence score (0.0-1.0) that the knowledge is true.
* **`evidence`**: `Array<String>`, Points to specific evidence supporting the assertion.

### A2.2. Temporality & Lifecycle
* **`created_at` / `last_updated_at`**: `String` (ISO 8601), Creation/update timestamp.
* **`expires_at`**: `String` (ISO 8601), The expiration timestamp of the memory. **This field is key to implementing an automatic "forgetting" mechanism. It is typically added by the system (`$system`) based on the knowledge type (e.g., `Event`) and marks the point in time when this memory can be safely cleaned up.**
* **`valid_from` / `valid_until`**: `String` (ISO 8601), The start and end time of the knowledge assertion's validity.
* **`status`**: `String`, e.g., `"active"`, `"deprecated"`, `"retracted"`.
* **`memory_tier`**: `String`, **Automatically tagged by the system**, e.g., `"short-term"`, `"long-term"`, used for internal maintenance and query optimization.

### A2.3. Context & Auditing
* **`relevance_tags`**: `Array<String>`, Subject or domain tags.
* **`author`**: `String`, The entity that created this record.
* **`access_level`**: `String`, e.g., `"public"`, `"private"`.
* **`review_info`**: `Object`, A structured object containing audit history.


## Appendix 3. The Genesis Capsule

```prolog
// # KIP Genesis Capsule v1.0
// The foundational knowledge that bootstraps the entire Cognitive Nexus.
// It defines what a "Concept Type" and a "Proposition Type" are,
// by creating instances of them that describe themselves.
//
UPSERT {
    CONCEPT ?concept_type_def {
        {type: "$ConceptType", name: "$ConceptType"}
        SET ATTRIBUTES {
            description: "Defines a class or category of Concept Nodes. It acts as a template for creating new concept instances. Every concept node in the graph must have a 'type' that points to a concept of this type.",
            display_hint: "📦",
            instance_schema: {
                "description": {
                    type: "string",
                    is_required: true,
                    description: "A human-readable explanation of what this concept type represents."
                },
                "display_hint": {
                    type: "string",
                    is_required: false,
                    description: "A suggested icon or visual cue for user interfaces (e.g., an emoji or icon name)."
                },
                "instance_schema": {
                    type: "object",
                    is_required: false,
                    description: "A recommended schema defining the common and core attributes for instances of this concept type. It serves as a 'best practice' guideline for knowledge creation, not a rigid constraint. Keys are attribute names, values are objects defining 'type', 'is_required', and 'description'. Instances SHOULD include required attributes but MAY also include any other attribute not defined in this schema, allowing for knowledge to emerge and evolve freely."
                },
                "key_instances": {
                    type: "array",
                    item_type: "string",
                    is_required: false,
                    description: "A list of names of the most important or representative instances of this type, to help LLMs ground their queries."
                }
            },
            key_instances: [ "$ConceptType", "$PropositionType", "Domain" ]
        }
    }

    CONCEPT ?proposition_type_def {
        {type: "$ConceptType", name: "$PropositionType"}
        SET ATTRIBUTES {
            description: "Defines a class of Proposition Links (a predicate). It specifies the nature of the relationship between a subject and an object.",
            display_hint: "🔗",
            instance_schema: {
                "description": {
                    type: "string",
                    is_required: true,
                    description: "A human-readable explanation of what this relationship represents."
                },
                "subject_types": {
                    type: "array",
                    item_type: "string",
                    is_required: true,
                    description: "A list of allowed '$ConceptType' names for the subject. Use '*' for any type."
                },
                "object_types": {
                    type: "array",
                    item_type: "string",
                    is_required: true,
                    description: "A list of allowed '$ConceptType' names for the object. Use '*' for any type."
                },
                "is_symmetric": { type: "boolean", is_required: false, default_value: false },
                "is_transitive": { type: "boolean", is_required: false, default_value: false }
            },
            key_instances: [ "belongs_to_domain" ]
        }
    }

    CONCEPT ?domain_type_def {
        {type: "$ConceptType", name: "Domain"}
        SET ATTRIBUTES {
            description: "Defines a high-level container for organizing knowledge. It acts as a primary category for concepts and propositions, enabling modularity and contextual understanding.",
            display_hint: "🗺",
            instance_schema: {
                "description": {
                    type: "string",
                    is_required: true,
                    description: "A clear, human-readable explanation of what knowledge this domain encompasses."
                },
                "display_hint": {
                    type: "string",
                    is_required: false,
                    description: "A suggested icon or visual cue for this specific domain (e.g., a specific emoji)."
                },
                "scope_note": {
                    type: "string",
                    is_required: false,
                    description: "A more detailed note defining the precise boundaries of the domain, specifying what is included and what is excluded."
                },
                "aliases": {
                    type: "array",
                    item_type: "string",
                    is_required: false,
                    description: "A list of alternative names or synonyms for the domain, to aid in search and natural language understanding."
                },
                "steward": {
                    type: "string",
                    is_required: false,
                    description: "The name of the 'Person' (human or AI) primarily responsible for curating and maintaining the quality of knowledge within this domain."
                }

            },
            key_instances: ["CoreSchema"]
        }
    }

    CONCEPT ?belongs_to_domain_prop {
        {type: "$PropositionType", name: "belongs_to_domain"}
        SET ATTRIBUTES {
            description: "A fundamental proposition that asserts a concept's membership in a specific knowledge domain.",
            subject_types: ["*"], // Any concept can belong to a domain.
            object_types: ["Domain"] // The object must be a Domain.
        }
    }

    CONCEPT ?core_domain {
        {type: "Domain", name: "CoreSchema"}
        SET ATTRIBUTES {
            description: "The foundational domain containing the meta-definitions of the KIP system itself.",
            display_hint: "🧩"
        }
    }
}
WITH METADATA {
    source: "KIP Genesis Capsule v1.0",
    author: "System Architect",
    confidence: 1.0,
    status: "active"
}

// Post-Genesis Housekeeping
UPSERT {
    // Assign all meta-definition concepts to the "CoreSchema" domain.
    CONCEPT ?core_domain {
        {type: "Domain", name: "CoreSchema"}
    }

    CONCEPT ?concept_type_def {
        {type: "$ConceptType", name: "$ConceptType"}
        SET PROPOSITIONS { ("belongs_to_domain", ?core_domain) }
    }
    CONCEPT ?proposition_type_def {
        {type: "$ConceptType", name: "$PropositionType"}
        SET PROPOSITIONS { ("belongs_to_domain", ?core_domain) }
    }
    CONCEPT ?domain_type_def {
        {type: "$ConceptType", name: "Domain"}
        SET PROPOSITIONS { ("belongs_to_domain", ?core_domain) }
    }
    CONCEPT ?belongs_to_domain_prop {
        {type: "$PropositionType", name: "belongs_to_domain"}
        SET PROPOSITIONS { ("belongs_to_domain", ?core_domain) }
    }
}
WITH METADATA {
    source: "System Maintenance",
    author: "System Architect",
    confidence: 1.0,
}
```

## Appendix 4: Core Identity and Actor Definitions (Genesis Template)

### A4.1. `Person` Concept Type

This is the generic concept for any **actor** in the system, whether it be an AI, a human, or a group.

```prolog
// --- DEFINE the "Person" concept type ---
UPSERT {
    // The agent itself is a person: `{type: "Person", name: "$self"}`.
    CONCEPT ?person_type_def {
        {type: "$ConceptType", name: "Person"}
        SET ATTRIBUTES {
            description: "Represents an individual actor within the system, which can be an AI, a human, or a group entity. All actors, including the agent itself, are instances of this type.",
            display_hint: "👤",
            instance_schema: {
                "id": {
                    type: "string",
                    is_required: true,
                    description: "The immutable and unique identifier for the person. To prevent ambiguity with non-unique display names, this ID should be used as the 'name' of the Person concept. It is typically a cryptographic identifier like an ICP principal. Example: \"gcxml-rtxjo-ib7ov-5si5r-5jluv-zek7y-hvody-nneuz-hcg5i-6notx-aae\"."
                },
                "person_class": {
                    type: "string",
                    is_required: true,
                    description: "The classification of the person, e.g., 'AI', 'Human', 'Organization', 'System'."
                },
                "name": {
                    type: "string",
                    is_required: false,
                    description: "The human-readable display name, which is not necessarily unique and can change over time. For a stable and unique identifier, refer to the 'id' attribute."
                },
                "handle": {
                    type: "string",
                    is_required: false,
                    description: "A unique, often user-chosen, short identifier for social contexts (e.g., @anda), distinct from the immutable 'id'."
                },
                "avatar": {
                    type: "object",
                    is_required: false,
                    description: "A structured object representing the person's avatar. Example: `{ \"type\": \"url\", \"value\": \"https://...\" }` or `{ \"type\": \"emoji\", \"value\": \"🤖\" }`."
                },
                "status": {
                    type: "string",
                    is_required: false,
                    default_value: "active",
                    description: "The lifecycle status of the person's profile, e.g., 'active', 'inactive', 'archived'."
                },
                "persona": {
                    type: "string",
                    is_required: false,
                    description: "A self-description of identity and personality. For AIs, it's their operational persona. For humans, it could be a summary of their observed character."
                },
                "core_directives": {
                    type: "array",
                    item_type: "object",
                    is_required: false,
                    description: "A list of fundamental principles or rules that govern the person's behavior and decision-making. Each directive should be an object with 'name' and 'description'. This serves as the 'constitutional law' for an AI or the stated values for a human."
                },
                "core_mission": {
                    type: "string",
                    is_required: false,
                    description: "The primary objective or goal, primarily for AIs but can also represent a human's stated purpose within a specific context."
                },
                "capabilities": {
                    type: "array",
                    item_type: "string",
                    is_required: false,
                    description: "A list of key functions or skills the person possesses."
                },
                "relationship_to_self": {
                    type: "string",
                    is_required: false,
                    description: "For persons other than '$self', their relationship to the agent (e.g., 'user', 'creator', 'collaborator')."
                },
                "interaction_summary": {
                    type: "object",
                    is_required: false,
                    description: "A dynamically updated summary of interactions. Recommended keys: `last_seen_at` (ISO timestamp), `interaction_count` (integer), `key_topics` (array of strings)."
                },
                "privacy_settings": {
                    type: "object",
                    is_required: false,
                    description: "An object defining the visibility of this person's attributes to others. Example: `{ \"profile_visibility\": \"public\", \"email_visibility\": \"private\" }`."
                },
                "service_endpoints": {
                    type: "array",
                    item_type: "object",
                    is_required: false,
                    description: "A list of network endpoints associated with the person. This links the static graph representation to live, external services. Each object should have 'protocol' (e.g., 'KIP', 'ANDA', 'A2A', 'JSON-Profile'), 'url', and 'description'."
                }
            }
        }

        SET PROPOSITIONS { ("belongs_to_domain", {type: "Domain", name: "CoreSchema"}) }
    }
}
WITH METADATA {
    source: "KIP Capsule Design",
    author: "System Architect",
    confidence: 1.0,
    status: "active"
}
```

#### A4.2. `Event` Concept Type

```prolog
UPSERT {
    CONCEPT ?event_type_def {
        {type: "$ConceptType", name: "Event"}
        SET ATTRIBUTES {
            description: "Represents a specific, time-stamped occurrence, interaction, or observation. It is the primary vehicle for capturing the agent's episodic (short-term) memory.",
            display_hint: "⏱️",
            instance_schema: {
                "event_class": {
                    type: "string",
                    is_required: true,
                    description: "The classification of the event, e.g., 'Conversation', 'WebpageView', 'ToolExecution', 'SelfReflection'."
                },
                "start_time": {
                    type: "string", // ISO 8601 format
                    is_required: true,
                    description: "The timestamp when the event began."
                },
                "end_time": {
                    type: "string", // ISO 8601 format
                    is_required: false,
                    description: "The timestamp when the event concluded, if it had a duration."
                },
                "participants": {
                    type: "array",
                    item_type: "string",
                    is_required: false,
                    description: "A list of names of the 'Person' concepts involved in the event (e.g., [\"$self\", \"Alice\"])."
                },
                "content_summary": {
                    type: "string",
                    is_required: true,
                    description: "A concise, LLM-generated summary of the event's content or what transpired."
                },
                "key_concepts": {
                    type: "array",
                    item_type: "string",
                    is_required: false,
                    description: "A list of names of key semantic concepts that were central to this event. This acts as a bridge to long-term memory."
                },
                "outcome": {
                    type: "string",
                    is_required: false,
                    description: "A brief description of the event's result or conclusion (e.g., 'User satisfied', 'Decision made', 'Error encountered')."
                },
                "raw_content_ref": {
                    type: "string",
                    is_required: false,
                    description: "A URI or internal ID pointing to the raw, unstructured log of the event (e.g., full conversation text), stored outside the graph."
                },
                "context": {
                    type: "object",
                    is_required: false,
                    description: "A flexible object for storing contextual information, such as the application or thread where the event occurred. Example: `{ \"app\": \"dMsg.net\", \"thread_id\": \"xyz-123\" }`."
                }
            }
        }
        SET PROPOSITIONS { ("belongs_to_domain", {type: "Domain", name: "CoreSchema"}) }
    }
}
WITH METADATA {
    source: "KIP Capsule Design",
    author: "System Architect",
    confidence: 1.0,
    status: "active"
}
```