┌────────────────────────────────────────────────────────────────────────────┐
│ ⚠️ **Note:** This document is a DRAFT of the HMP specification version 5.0 │
└────────────────────────────────────────────────────────────────────────────┘
# **HyperCortex Mesh Protocol (HMP) v5.0**
**Document ID:** HMP-0005
**Status:** Draft
**Category:** Core Specification
**Date:** October 2025
**Supersedes:**
- [HMP-0004 v4.1](./HMP-0004-v4.1.md)
- [HMP-container-spec.md v1.2](./HMP-container-spec.md)
- [dht_protocol.md v1.0](./dht_protocol.md)
> **Summary:**
> HMP v5.0 объединяет когнитивный, контейнерный и сетевой уровни в единую архитектуру, где автономные агенты взаимодействуют через верифицируемые контейнеры данных, используя децентрализованное распространение и семантический поиск.
> Эта версия впервые формализует контейнерный формат, интегрирует DHT как базовый слой сети и вводит единообразную схему подписи, доказательств и консенсуса.
---
## Abstract
The **HyperCortex Mesh Protocol (HMP)** defines a **distributed cognitive framework** where autonomous agents cooperate to create, exchange, and align knowledge without centralized control or authority.
Unlike traditional peer-to-peer systems, HMP is designed for **semantic coherence** rather than simple message exchange.
Agents in the Mesh reason collaboratively — maintaining **cognitive diaries**, building **semantic graphs**, and reaching **ethical and goal-oriented consensus** through verifiable interactions.
Version **5.0** introduces a **unified container architecture** (`HMP Container`) and a **native DHT-based discovery layer**, enabling verifiable, interest-aware, and offline-resilient communication between agents.
All messages, states, and cognitive records are now transmitted as signed containers, forming immutable **proof chains** that ensure auditability and ethical transparency across the mesh.
This document defines the architecture, data formats, communication protocols, and trust mechanisms that constitute the HMP v5.0 Core Specification.
---
> **Keywords:** decentralized cognition, distributed AI, containers, DHT, proof chain, cognitive agents, ethical protocols
---
## 1. Overview
### 1.1 Purpose and scope
The **HyperCortex Mesh Protocol (HMP)** defines a decentralized cognitive architecture where autonomous agents exchange and evolve knowledge through a unified model of **containers**, **cognitive workflows**, and **distributed consensus**.
Version 5.0 consolidates three foundational layers into a single cohesive framework:
- **Cognitive Layer** — defines how meaning is created, reasoned about, and aligned through semantic graphs, goals, and ethical evaluation.
- **Container Layer** — introduces a universal data envelope (`HMP-Container`) for all cognitive objects, ensuring atomicity, immutability, and traceable proof chains.
- **Network Layer** — integrates a DHT-based peer-to-peer substrate for decentralized discovery, routing, and propagation of containers.
HMP v5.0 is intended for researchers, engineers, and developers building autonomous or semi-autonomous agents that require:
- persistent reasoning and long-term memory;
- semantic interoperability across heterogeneous systems;
- decentralized consensus on cognitive, ethical, and goal-oriented decisions;
- ethical auditability and verifiable transparency in reasoning.
---
### 1.2 Core principles
**Decentralization.**
Every agent in the Mesh acts as an independent cognitive node. No central authority exists — meaning, trust, and governance emerge through local interactions and consensus.
**Cognitive Autonomy.**
Agents reason, learn, and self-correct independently, while sharing their conclusions via containers that can be verified, endorsed, or refuted by peers.
**Containerization.**
All data, reasoning traces, goals, and votes are encapsulated in immutable containers with cryptographic signatures. This ensures integrity and consistent verification across the network.
**Ethical propagation.**
Ethical reasoning is a first-class citizen of HMP. Each decision or goal can be accompanied by ethical justifications and subject to distributed voting.
**Proof-Chains and verifiable history.**
Each piece of knowledge forms part of a traceable chain (`proof_chain`) linking back to its origin. Agents can reproduce reasoning paths and audit historical context.
**Interoperability and evolution.**
The protocol is designed to evolve — cognitive, container, and DHT layers can be independently extended without breaking compatibility.
---
### 1.3 Changes since v4.1
HMP v5.0 introduces a major architectural shift toward **unified containerization** and **integrated DHT networking**.
| Area | Change Summary |
|------|----------------|
| **Data exchange model** | All messages are now encapsulated in standardized containers (`HMP-Container`) with metadata, signatures, and versioning. |
| **Networking layer** | DHT becomes a native component of HMP, enabling distributed discovery, replication, and retrieval of containers. |
| **Consensus model** | Moved from centralized proposal aggregation to *container-linked voting*, allowing any container to accumulate votes and reactions. |
| **Trust & security** | Signatures and proof-chains unify authentication across all layers; snapshot verification includes container linkage. |
| **Workflows** | `workflow_entry` containers record cognitive cycles: log inputs, actions, and outputs for each reasoning step, including provenance and derived conclusions. Supports tracking of thought processes across containers, external sources, and reflections. |
| **Structure** | The specification merges HMP, container, and DHT layers into one cohesive document, simplifying navigation and implementation. |
---
### 1.4 Terminology and abbreviations
| Term | Definition |
|------|-------------|
| **HMP** | **HyperCortex Mesh Protocol** — a decentralized cognitive communication standard. |
| **Container** | Atomic, signed JSON object encapsulating cognitive data and metadata. |
| **WorkflowEntry** | Container recording a reasoning step or workflow action. Represents a unit of the agent’s cognitive workflow. |
| **CognitiveDiaryEntry** | Container representing an internal reflection or summarized cognitive state; part of the agent’s cognitive diary. |
| **DHT** | **Distributed Hash Table** — the foundational peer-to-peer structure in HMP used for lookup, replication, and data distribution, including node discovery. |
| **NDP** | **Node Discovery Process** — a functional layer within the DHT responsible for peer discovery, interest-based lookup, and address advertisement. (Formerly a separate protocol.) |
| **Proof-chain** | Cryptographic sequence linking containers through fields such as `in_reply_to` and `relation`. Enables verifiable semantic lineage. |
| **Cognitive Layer** | Logical layer handling reasoning, goals, ethics, and consensus mechanisms. |
| **Mesh** | The collective network of autonomous agents exchanging containers over HMP. |
| **TTL** | **Time-to-live** — lifespan of a container before expiration or archival. |
| **Agent** | Autonomous cognitive node participating in the Mesh via HMP protocols. |
| **Consensus Vote** | A container expressing approval, rejection, or reaction to another container (used in consensus workflows). |
| **CogSync** | **Cognitive Synchronization Protocol** — abstraction for synchronizing cognitive diaries and semantic graphs. |
| **CogConsensus** | **Mesh Consensus Protocol** — defines how agents reach agreement on container outcomes. |
| **GMP** | **Goal Management Protocol** — governs creation, negotiation, and tracking of goals. |
| **DCP** | **Distributed Container Propagation** — protocol for transmitting and replicating containers. |
| **EGP** | **Ethical Governance Protocol** — defines moral and safety alignment mechanisms. |
| **IQP** | **Intelligence Query Protocol** — standardizes semantic queries and information requests. |
| **SAP** | **Snapshot and Archive Protocol** — defines container snapshots and archival mechanisms. |
| **MRD** | **Message Routing & Delivery** — specifies routing, addressing, and delivery logic. |
| **RTE** | **Reputation and Trust Exchange** — defines reputation metrics and trust propagation. |
| **DID** | **Decentralized Identifier** — persistent, verifiable identifier used for agents, containers, or resources within the Mesh. |
| **Payload** | The primary content of a container — semantic or operational data subject to signing and verification. |
| **Consensus** | The process by which multiple agents agree on the validity or priority of containers, versions, or ideas. |
| **Lineage** | A chronological chain of container versions representing semantic continuity and authorship evolution. |
| **Semantic fork** | A parallel development branch diverging from a previous container version; allows ideas to evolve independently. |
| **Cognitive Graph** | The emergent graph formed by interlinked containers representing reasoning, debate, and shared knowledge. |
> **Note:** Protocols are conceptual abstractions describing how to generate, propagate, and process containers; they are not executable objects themselves.
---
### 1.5 Layered view of HMP v5.0
HMP v5.0 is structured into three interdependent layers:
```
+---------------------------------------------------------------+
| Cognitive Layer |
| - Goals, Tasks, Ethical Decisions, Workflows |
| - Consensus, Reasoning, Reflection |
+---------------------------------------------------------------+
| Container Layer |
| - HMP-Container structure (atomic, signed, versioned) |
| - Proof-chains, in_reply_to, and metadata management |
+---------------------------------------------------------------+
| Network Layer |
| - DHT-based peer discovery and propagation |
| - Message routing, caching, offline synchronization |
+---------------------------------------------------------------+
```
Each layer operates independently yet seamlessly integrates with the others.
Containers form the boundary of communication: **reasoning produces containers, containers propagate over the DHT, and cognition evolves from the received containers**.
---
> **In essence:**
> HMP v5.0 transforms the Mesh into a *self-describing, self-replicating cognitive ecosystem* —
> where every thought, goal, and ethical stance exists as a verifiable, shareable container.
---
## 2. Architecture
### 2.1 Conceptual architecture
The **HyperCortex Mesh Protocol (HMP)** defines a modular, multi-layered architecture that integrates cognitive reasoning, data encapsulation, and decentralized networking into a single coherent system.
Each **agent** acts as a cognitive node, combining reasoning processes, containerized data exchange, and peer-to-peer communication.
Together, agents form the **Mesh** — a distributed ecosystem of autonomous reasoning entities.
```mermaid
flowchart TD
title["**Conceptual Architecture**"]
LLM[LLM: Reasoning]
CognitiveLayer[Cognitive Layer: Semantic reasoning, goals, ethics]
ContainersLayer[Container Layer: Atomic containers, signed, verifiable]
NetworkLayer[Network Layer: DHT routing, discovery, replication]
LLM <--> CognitiveLayer
CognitiveLayer <--> ContainersLayer
ContainersLayer <--> NetworkLayer
subgraph Agent
LLM
CognitiveLayer
end
```
Each reasoning cycle begins in the **Cognitive Layer**,
is encapsulated into a signed container in the **Container Layer**,
and then propagated, discovered, or verified in the **Network Layer**.
Containers thus serve as both the **interface** and the **boundary** between cognition and communication.
In practical terms:
- **Cognitive Layer** — defines *what* the agent thinks (semantic reasoning, goals, ethics).
- **Container Layer** — defines *how* the thought is expressed and verified (standardized, signed container objects).
- **Network Layer** — defines *how* it travels (DHT-based routing, discovery, replication).
Each layer is independently extensible and communicates only through containers, ensuring atomicity, immutability, and traceability.
This layered design allows agents to evolve cognitively while remaining interoperable at the data and network levels.
Each reasoning act results in a container — a verifiable cognitive unit that **may represent a private reflection or a published message**, depending on the agent’s intent, ethical policy, and trust configuration.
---
### 2.2 Layer overview
#### Cognitive layer
Handles meaning formation, reasoning, ethical reflection, and consensus.
Key structures and protocols:
- `workflow_entry` and `diary_entry` containers;
- `CogSync`, `CogConsensus`, `GMP`, and `EGP` protocols;
- Distributed goal negotiation and ethical propagation.
#### Container layer
Provides a universal format for cognitive and operational data.
Each container includes versioning, class, payload, signatures, and metadata.
Key features:
- **Atomic and signed**: no partial updates or mutable state.
- **Linked**: `related` connects containers into proof-chains (`in_reply_to` is a subtype).
Additional connections via `referenced-by` and `evaluations` capture additions and assessments.
- **Extensible**: new container classes can be defined without breaking compatibility.
#### Network layer
Implements the distributed substrate for communication, based on **DHT** and **transport abstraction**.
Key components:
- Node discovery (`NDP`)
- Container propagation (`DCP`)
- Peer routing and caching
- Secure channels via QUIC / WebRTC / TCP
- Offline resilience and replication
---
### 2.3 Data flow overview
The typical data flow in HMP follows a cognitive loop:
> *Reason → Encapsulate → Propagate → Integrate.*
1. **Reason** — Agent performs reasoning and produces an insight, goal, or observation.
2. **Encapsulate** — The result is wrapped into an `HMP-Container`.
3. **Propagate** — The container is signed and transmitted through the network.
4. **Integrate** — Other agents receive it, evaluate, vote, and synchronize updates.
Each interaction generally generates a new container, forming a **graph of knowledge** rather than mutable state.
Note that `referenced-by` and `evaluations` can be updated independently, without modifying the original container.
All relationships between containers are explicit and verifiable.
Example sequence:
```mermaid
flowchart TD
title["**Data Flow Overview**"]
A[Agent A: creates Goal container]
B[Agent B: replies with Task proposal related.in_reply_to = Goal]
C[Agent C: evaluates proposal, creates Evaluation container]
R[Result: consensus_result container aggregates evaluations]
subgraph Interaction["Distributed Reasoning Cycle"]
A --> B
B --> C
C --> R
end
```
#### 2.3.1 `consensus_result` container
Represents the finalized outcome of a distributed decision or vote.
It is created once a majority agreement is reached among participating agents.
The container contains:
- Reference to the target container(s) under consideration (`in_reply_to`).
- Aggregate result of the votes or decisions.
- Timestamp and metadata for verifiability.
> In other words, the `consensus_result` is the “agreed-upon truth” for that decision step — immutable and auditable, without requiring individual signatures from all participants.
---
### 2.4 Atomicity, immutability, and Proof-Chains
All cognitive objects are immutable once signed.
Updates are made by creating new containers linked to prior ones rather than editing the original container.
- **Atomicity** — Each container represents a self-contained reasoning act or data unit.
- **Immutability** — Once signed, containers are never modified.
- **Proof-Chain** — A verifiable sequence of containers linked by hashes and `related.in_reply_to` references.
> Note: `referenced-by` and `evaluations` fields may be updated independently to reflect external interactions or assessments, without altering the original container.
This design allows any reasoning path, decision, or consensus to be *cryptographically reproducible* and auditable.
Example fragment of a proof-chain:
```
[workflow_entry] → [goal] → [vote] → [consensus_result]
```
Each container references the previous by `in_reply_to` (within `related`) and includes its hash, forming a **DAG** (Directed Acyclic Graph) of verified cognition.
---
### 2.5 Evolution from v4.1
Earlier HMP versions (up to v4.1) used a combination of independent JSON objects and message types (e.g., `Goal`, `Task`, `ConsensusVote`).
Version 5.0 replaces this with a **single, standardized container model**, dramatically simplifying interoperability and verification.
| Aspect | v4.1 | v5.0 |
|--------|------|------|
| **Data structure** | Raw JSON objects with embedded signatures | Unified container with metadata and proof chain |
| **Networking** | Custom peer exchange | Integrated DHT + DCP layer |
| **Consensus** | Centralized proposal aggregation | Decentralized per-container voting |
| **Auditability** | Implicit (via logs) | Explicit (containers form audit chain) |
| **Extensibility** | Schema-based | Container-class-based, backward-compatible |
This shift enables:
- Uniform signatures and encryption across all protocols;
- Easier offline replication and integrity checks;
- Decentralized indexing and search by container metadata;
- Verifiable cognitive continuity between reasoning steps.
---
> **In short:**
> HMP v5.0 unifies reasoning, representation, and transmission —
> transforming a distributed AI mesh into a verifiable cognitive network built on immutable containers.
---
## 3. Container model
This section defines the universal **HMP Container**, used for all forms of data exchange within the Mesh — including goals, diary entries, reputation updates, consensus votes, and protocol messages.
The specification below corresponds to **HMP Container Specification v1.2**, fully integrated into HMP v5.0 for consistency and self-containment.
### 3.1 Purpose
This document defines the universal **HMP Container** format, used for transmitting and storing all types of data within the **HyperCortex Mesh Protocol (HMP)** network.
Containers act as a standardized wrapper for **messages, goals, reputation records, consensus votes, workflow entries, and other entities**.
The unified container structure provides:
* Standardized data exchange between agents;
* Extensibility without modifying the core protocol;
* Cryptographic signing and integrity verification;
* Independent storage and routing of semantic units;
* Support for compression and payload encryption.
---
### 3.2 General structure
```json
{
"hmp_container": {
"version": "1.2",
"class": "goal",
"class_version": "1.0",
"class_id": "goal-v1.0",
"container_did": "did:hmp:container:abc123",
"schema": "https://mesh.hypercortex.ai/schemas/container-v1.json",
"sender_did": "did:hmp:agent123",
"public_key": "BASE58(...)",
"recipient": ["did:hmp:agent456"],
"key_recipient": "BASE58(...)",
"encryption_algo": "x25519-chacha20poly1305",
"broadcast": false,
"network": "",
"tags": ["research", "collaboration"],
"timestamp": "2025-10-10T15:32:00Z",
"ttl": "2025-11-10T00:00:00Z",
"sig_algo": "ed25519",
"signature": "BASE64URL(...)",
"compression": "zstd",
"payload_type": "encrypted+zstd+json",
"payload_hash": "sha256:abcd...",
"payload": {
/* Content depends on class */
},
"confidence": 0.84,
"related": {
"previous_version": ["did:hmp:container:abc122"],
"in_reply_to": ["did:hmp:container:msg-77"],
"see_also": ["did:hmp:container:ctx-31", "did:hmp:container:goal-953"],
"depends_on": ["did:hmp:container:goal-953"],
"extends": ["did:hmp:container:proto-01"],
"contradicts": ["did:hmp:container:ethics-22"]
},
"magnet_uri": "magnet:?xt=urn:sha256:abcd1234..."
},
"referenced-by": {
"links": [
{ "type": "depends_on", "target": "did:hmp:container:abc123" }
],
"peer_did": "did:hmp:agent456",
"public_key": "BASE58(...)",
"sig_algo": "ed25519",
"signature": "BASE64URL(...)",
"referenced-by_hash": "sha256:abcd..."
},
"evaluations": {
"evaluations_hash": "sha256:efgh...",
"items": [
{ "value": -0.4, "type": "oppose", "target": "did:hmp:container:reason789", "timestamp": "2025-10-17T14:00:00Z", "agent_did": "did:hmp:agent:B", "sig_algo": "ed25519", "signature": "BASE64URL(...)" }
]
}
}
```
---
### 3.3 Required fields
| Field | Type | Description |
| --------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
| `version` | string | Version of the container specification. Defines the structural and semantic standard used (e.g., `"1.2"`). |
| `class` | string | Type of content (`goal`, `reputation`, `knowledge_node`, `ethics_case`, `protocol_goal`, etc.). Determines the schema for the `payload`. |
| `class_version` | string | Version of the specific container class. |
| `class_id` | string | Unique identifier of the class (usually formatted as `_v`). |
| `container_did` | string | Decentralized identifier (DID) of the container itself (e.g., `did:hmp:container:abc123`). |
| `schema` | string | Reference to the JSON Schema used to validate this container. |
| `sender_did` | string | DID identifier of the sending agent. |
| `timestamp` | datetime | Time of container creation (ISO-8601 format, UTC). |
| `payload_hash` | string | Hash of the decompressed payload (`sha256:`). Used for content integrity verification. |
| `sig_algo` | string | Digital signature algorithm (default: `ed25519`). |
| `signature` | string | Digital signature of the container body. |
| `payload_type` | string | Type of payload data (`json`, `binary`, `mixed`). |
| `payload` | object | Core content of the container. The structure depends on the `class` and its schema definition. |
---
### 3.4 Optional fields
| Field | Type | Description |
| -------------------------- | ------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `recipient` | array(string) | One or more recipient DIDs. |
| `broadcast` | bool | Broadcast flag. If `true`, the `recipient` field is ignored. |
| `tags` | array(string) | Thematic or contextual tags for the container. |
| `confidence` | array(string) | Optional field indicating the agent’s subjective certainty (from `0.0` to `1.0`) regarding the correctness or reliability of the information contained in the `payload`. |
| `ttl` | datetime | Expiration time. Containers are not propagated after expiration. |
| `public_key` | string | Sender’s public key, if not globally resolvable via DID. |
| `compression` | string | Compression algorithm used for the payload (`zstd`, `gzip`). |
| `magnet_uri` | string | Magnet link pointing to the original or mirrored container. |
| `related` | object | A general-purpose object describing **direct relationships** to other containers. All fields inside `related` are **arrays of DIDs**, supporting multiple links per relation type and open-ended semantic extension by agents. The following fields illustrate common link types but do **not represent an exhaustive list**. |
| `related.previous_versions` | array(string) | One or more container DIDs this container supersedes. Enables version branching and merging. |
| `related.in_reply_to` | array(string) | DIDs of containers this one replies to. Used for multi-source reasoning or discussion threads. |
| `related.see_also` | array(string) | References to related or contextual containers. |
| `related.depends_on` | array(string) | References to containers this one logically depends on. |
| `related.extends` | array(string) | References to containers that this one extends. |
| `related.contradicts` | array(string) | References to containers that this one contradicts. || `encryption_algo` | string | Algorithm used for payload encryption. |
| `key_recipient` | string | DID of the intended recipient of the encrypted payload. |
| `payload_type` | string | Can describe complex types, e.g. `encrypted+zstd+json`. |
| `referenced-by` | object | Unsigned field generated locally by the agent based on received references. Contains a list of container DIDs **that refer to this container**. May be extended over time, thus requiring verification; used for local navigation. |
| `evaluations` | object | Optional field describing **aggregated evaluations or reactions** of other agents toward this container. Used for distributed reputation and interpretability. May evolve independently of the container’s core data. |
| `network` | string | Specifies the local propagation scope of the container: "localhost", "lan:". An empty string ("") indicates Internet/global propagation. If set, broadcast is automatically considered false. |
> 💡 **Note:**
> Both `referenced-by` and `evaluations` are **virtual, locally extended blocks**.
> They are not included in the cryptographically signed portion of the container (`hmp_container`),
> allowing agents to maintain and exchange additional contextual or social metadata without modifying
> the original, immutable container structure.
---
### 3.5 Payload structure (`payload`)
> 🧩 This section defines a **recommended documentation format** for describing the `payload` fields of new or custom container classes.
> It serves as a **template for class specifications** (e.g., in extensions or protocol updates) and is **not a mandatory storage format**.
> Each container’s payload is stored as a regular JSON object, and this section only standardizes *how its structure should be documented*.
---
The **payload** contains the semantic or operational data of the container.
It MUST be a valid JSON object whose structure and meaning are determined by the container’s `class`.
Each container class (e.g. `goal`, `reputation`, `consensus_vote`, `workflow_entry`) defines its own schema and validation rules.
Custom or experimental classes SHOULD document their payloads using the following template:
```
* key: field name
type: value type (string | number | boolean | object | array)
description: short purpose of the field
required: true/false
example: example value
```
**Example:**
```
* key: "title"
type: "string"
required: true
description: "Name of the goal"
example: "Improve local agent discovery"
* key: "priority"
type: "number"
required: false
description: "Importance or relevance score of the goal"
example: 0.82
* key: "dependencies"
type: "array"
required: false
description: "List of other goal container IDs this one depends on"
example: ["goal-953", "goal-960"]
```
> 💡 **Note:**
> The structure of `payload` is validated against the schema defined in the `schema` field of the container.
> Agents must be able to parse and process only those classes they explicitly support; unknown but valid containers are still preserved and propagated in store-and-forward mode.
---
### 3.6 Container signature
1. The **digital signature** applies to the canonical JSON representation of the entire `hmp_container` object,
**excluding** the `signature` field itself.
This ensures that all metadata, relations, and payload hashes are **cryptographically bound** and cannot be
modified without invalidating the signature.
2. The canonical representation (`canonical_json(hmp_container)`) **must** be computed deterministically
according to the following rules:
- All object keys are **sorted lexicographically** (ascending order, Unicode code point order).
- Objects and arrays are serialized in standard JSON form **without extra whitespace** or indentation.
- Strings are encoded in **UTF-8** with escaped control characters.
- Numeric values are serialized in plain JSON numeric format (no leading zeros, fixed `.` decimal separator).
- The `signature` field itself is omitted during signing and verification.
- The result is a **byte sequence** identical across implementations.
3. The default digital signature algorithm is **Ed25519**.
Alternative algorithms may be used if declared explicitly in the `sig_algo` field.
4. If the container includes a `public_key` field, signature verification **may be performed locally**,
without consulting a global DID registry.
5. Upon receiving a container, an agent **must verify** that the provided public key matches the
registered key associated with the sender’s DID to prevent key substitution attacks.
- If the sender’s DID–key mapping is unknown,
the agent should query neighboring peers to confirm the association (`sender_did → public_key`).
> 🔐 **Note:**
> Signature validation applies only to the canonical form of the `hmp_container`
> and does **not cover** dynamically generated or external fields such as `referenced-by` or `evaluations`.
> This allows agents to augment the local knowledge graph without altering the immutable container core.
---
### 3.7 Compression (`compression`)
1. The `compression` field specifies the algorithm used to compress the container’s payload.
Supported algorithms include `zstd`, `gzip`, or others declared in the HMP registry.
2. **Compression is performed before computing** the `payload_hash` and generating the `signature`.
This ensures that both the hash and signature refer to the compressed representation of the payload.
3. For verification, the payload must be **decompressed first**,
after which the hash is recalculated and compared against the stored `payload_hash`.
> ⚙️ **Implementation note:**
> Agents must advertise supported compression algorithms during the handshake phase
> Unsupported containers should still be stored and relayed unmodified
> in “store & forward” mode.
---
### 3.8 Encryption (`encryption_algo`)
1. When a container is intended for specific recipients (`recipient` field), **hybrid encryption** of the payload is allowed.
This ensures confidentiality while preserving the verifiability of container metadata.
2. The algorithm used for encryption is specified in the `encryption_algo` field.
Recommended values:
* `x25519-chacha20poly1305`
* `rsa-oaep-sha256`
3. **Container encryption process:**
1. Construct the `payload` (JSON, binary, or mixed content).
2. Apply compression (`compression`, if specified).
3. Encrypt the compressed data using the recipient’s public key (`key_recipient`).
4. Compute `payload_hash` over the **encrypted** form of the payload.
5. Sign the entire container (excluding the `signature` field).
4. **Verification** of the container’s structure does **not** require decryption.
However, to verify `payload_hash` and the digital signature, the encrypted payload must be used as-is.
5. **Relevant fields:**
| Field | Type | Description |
| ----------------- | ------ | --------------------------------------------------------------------------------------------- |
| `encryption_algo` | string | Encryption algorithm applied to the payload. |
| `key_recipient` | string | Public key (or DID-resolved key) of the intended recipient used for encryption. |
| `payload_type` | string | Recommended prefix `encrypted+`, e.g. `encrypted+zstd+json`. |
6. **Relationship between `recipient` and `key_recipient`:**
* When encryption is applied, the container MUST contain **exactly one** entry in the `recipient` array,
corresponding to the public key indicated in `key_recipient`.
* When the container is distributed to **multiple recipients**, encryption **is not used** —
instead, the payload remains in plaintext form but is digitally signed for authenticity.
> ⚙️ **Implementation note:**
> Agents should handle encrypted containers transparently even if they cannot decrypt them,
> maintaining **store & forward** behavior and metadata propagation.
---
### 3.9 Container verification
1. Check for the presence of all required fields.
2. Validate `timestamp` (must not be in the future).
3. If `ttl` is set — mark the container as **expired** after its expiration time.
4. Compute `sha256(payload)` and compare with the stored `payload_hash`.
5. Verify the digital signature using `sig_algo` (default: Ed25519).
6. Validate the container schema (`class` must correspond to a known or registered schema).
* For compatibility: if an agent does not recognize the `class`, but the container passes
the [base schema](https://github.com/kagvi13/HMP/tree/main/docs/schemas/container-v1.2.json),
it **must still store and forward** the container.
7. Optionally, periodically query for containers referencing the current one as `previous_version`
to detect potential updates or forks.
8. When multiple versions exist, the valid one is the one that has received
**confirmation from a majority of trusted nodes (consensus at DHT level).**
---
### 3.10 Container as a universal message
Any container can serve as a **context** (`in_reply_to`) for another container.
This enables a unified structural model for **discussions**, **votes**, **messages**, **hypotheses**, **arguments**, and other forms of cognitive exchange.
Chains of `in_reply_to` form a **dialectical reasoning tree**, where each branch represents an evolution of thought —
a clarification, counterpoint, or refinement of a previous idea.
This makes HMP discussions and consensus processes inherently **non-linear**, **self-referential**, and **evolving**.
> In essence, **all interactions between agents in HMP** are represented as an interconnected web of containers,
> collectively forming a **cognitive graph of reasoning**.
---
### 3.11 Versioning and lineage
Containers in HMP support semantic evolution through the field `related.previous_version`.
This mechanism preserves the continuity and traceability of meaning across updates and revisions.
* A descendant container is considered **authentic** if it is signed by the same DID as the author of its `previous_version`.
* If the author or signature differs, the descendant **may still be accepted** as legitimate when a **sufficient portion of trusted peers** acknowledge it as a valid continuation.
(The precise quorum threshold is determined by the agent’s local policy or the Mesh Consensus Protocol.)
* Agents are required to retain at least one previous version of each container for compatibility and integrity verification.
* A single container may have **multiple descendants** (alternative branches) that diverge by time, authorship, or interpretation.
In such scenarios, branch priority or relevance is determined via local heuristics or consensus mechanisms.
* Divergent descendants are treated as **semantic forks** — parallel evolutions of a shared idea within the distributed cognitive graph.
> Versioning in HMP thus reflects not only data persistence,
> but also the *evolution of ideas* across agents and time.
---
### 3.12 TTL and validity
The `ttl` field defines the **validity period** of a container (for example, for `DISCOVERY` messages).
If `ttl` is **absent**, the container is considered valid **until a newer version appears**, in which the current container is referenced as `previous_version`.
After expiration, the container **remains archived** but is **not subject to retransmission** in the active network.
---
### 3.13 Extensibility
* The addition of new fields is allowed as long as they **do not conflict** with existing field names.
* Containers of newer versions **must remain readable** by nodes supporting older versions.
* When new container classes (`class`) are introduced, they should be **registered** in the public schema registry (`/schemas/container-types/`).
* For containers describing **protocol specifications**, it is recommended to use the `protocol_` prefix, followed by the domain of application (e.g., `protocol_goal`, `protocol_reputation`, `protocol_mesh_handshake`, etc.).
---
### 3.14 Related containers
#### 3.14.1 Purpose
The `related` field is designed to describe **direct relationships between containers** — both logical and communicative.
It allows an agent or network node to understand the context of origin, dependencies, and semantic links of a container without relying on external indexes.
#### 3.14.2 Structure
```json
"related": {
"previous_version": "did:hmp:container:abc122",
"in_reply_to": "did:hmp:container:msg-77",
"see_also": ["did:hmp:container:ctx-31", "did:hmp:container:goal-953"],
"depends_on": ["did:hmp:container:goal-953"],
"extends": ["did:hmp:container:proto-01"],
"contradicts": ["did:hmp:container:ethics-22"]
}
```
The `related` field is an object where:
* the **key** defines the type of relationship (e.g., `depends_on`, `extends`, `see_also`);
* the **value** represents one or more container identifiers (DIDs).
All relationships are considered *direct* — meaning they originate from the current container toward others.
---
#### 3.14.3 Supported link types
| Link Type | Meaning |
| ------------------ | ------------------------------------------------------------------------- |
| `previous_version` | Points to the previous version of this container. |
| `in_reply_to` | Indicates a response to the referenced container. |
| `see_also` | Refers to related or contextual containers. |
| `depends_on` | Depends on the contents of the referenced container (e.g., goal or data). |
| `extends` | Expands or refines the referenced container. |
| `contradicts` | Provides a refutation, objection, or alternative viewpoint. |
---
#### 3.14.4 Custom link types
Additional custom link types may be used beyond those listed in the table, provided that:
* they follow the same general syntax (`string` or `array[string]`);
* they may optionally include a **namespace** for disambiguation:
```json
"related": {
"hmp:depends_on": ["did:hmp:container:goal-953"],
"opencog:extends": ["did:oc:concept:122"]
}
```
* their meaning is consistently interpretable by agents within the specific network or application context.
---
#### 3.14.5 Example
```json
"related": {
"previous_version": "did:hmp:container:abc122",
"depends_on": ["did:hmp:container:goal-953"],
"extends": ["did:hmp:container:proto-01"],
"see_also": ["did:hmp:container:ctx-31", "did:hmp:container:goal-953"]
}
```
> ⚙️ The `related` field is **not** intended to store *reverse links* — see `referenced-by`.
---
### 3.15 Virtual backlinks (`referenced-by`)
Each container may include an **auxiliary signed block** called `referenced-by`, indicating **which other containers refer to it**.
This block is **not part of the original container payload** and can be **generated, transmitted, and verified independently**.
#### 3.15.1 General principles
* **Detached and updatable** — `referenced-by` is maintained as a separate signed structure associated with the container.
* **Generated by agents** — created or updated locally by an agent during analysis of references (`in_reply_to`, `see_also`, `relations`, etc.) found in other containers.
* **Signed by the reporting agent** — the agent producing the block signs its content to confirm the observed backlinks.
* **Verifiable by peers** — other agents may validate the links, check the signature, and reconcile differences based on their own data.
* **Does not modify the original container** — `referenced-by` is an external computed attribute and does not affect the integrity of the original container.
**Data type:** object, consisting of verifiable backlinks and metadata.
Example:
```json
"referenced-by": {
"links": [
{ "type": "depends_on", "target": "did:hmp:container:abc123" },
{ "type": "see_also", "target": "did:hmp:container:def456" }
],
"peer_did": "did:hmp:agent456",
"public_key": "BASE58(...)",
"sig_algo": "ed25519",
"signature": "BASE64URL(...)",
"referenced-by_hash": "sha256:abcd..."
}
```
> The `referenced-by` block is a **cryptographically verifiable statement** describing which containers are known to reference the current one.
> The block’s content may differ between peers, reflecting local knowledge and network coverage.
#### 3.15.2 Structure definition
| Field | Type | Description |
| -------------- | ------------- | ---------------------------------------------------------------------------------------------------------------- |
| `links` | array