Skip to main content

An MCP server that gives AI agents a permanent, append-only causal history

Project description

History Graph Protocol (HGP)

An MCP server that gives AI agents a permanent, append-only causal history.

HGP records what an agent did and why — every operation, every causal link, and every piece of evidence behind each decision. Where memory systems (mem0, Zep, ChatGPT Memory) store what an agent knows, HGP stores what an agent did. Think of other memory systems as an agent's working memory; HGP is the agent's audit trail.


Core Concepts

Operations (Nodes)

Each operation is an immutable, typed, append-only record of an action taken by an agent. Four types:

Type Meaning
artifact A produced output (document, code, data)
hypothesis A claim, decision, or inference
merge Combining multiple prior operations
invalidation Superseding or retracting a prior operation

Operations are never deleted or mutated. The graph only grows.

Causal Graph (DAG)

Operations are connected by directed edges:

  • causal — A produced B (B depends on A)
  • invalidates — A supersedes B (B is no longer current)

Example: an analysis produces a hypothesis, which is later revised by an invalidation.

graph LR
    A["op-1\nartifact\n(analysis)"]
    B["op-2\nhypothesis\n(decision)"]
    C["op-3\ninvalidation\n(revised decision)"]

    A -->|causal| B
    C -->|invalidates| B
    A -->|causal| C

Memory Tier

Each operation carries a memory tier that reflects access recency:

Tier Meaning
short_term Recently active; included in all queries
long_term Older but still reachable; included in all queries
inactive Not accessed recently; excluded from default queries, never deleted

Tiers are updated automatically based on access patterns and can be set manually via hgp_set_memory_tier.

Evidence Trail (V3)

Operations can cite other operations as evidence, independently of the DAG edge structure. Evidence relations are stored separately and carry:

  • relationsupports, refutes, context, method, or source
  • scope — which aspect of the citing op this evidence applies to
  • inference — free-text explanation of how the evidence was used

This allows full auditability: given any decision, you can reconstruct exactly what evidence it was based on and how each piece was interpreted.


Installation

Prerequisites: Python ≥ 3.12, uv

# With uv (recommended)
uv pip install history-graph-protocol

# With pip
pip install history-graph-protocol

Note: The PyPI package name is history-graph-protocol; the installed CLI command is hgp.

Run as MCP server (stdio transport):

hgp
# or
python -m hgp.server

Installing hooks

HGP ships hook scripts for Claude Code and Gemini CLI. Run once inside your project:

hgp install-hooks            # install both Claude Code and Gemini CLI hooks
hgp install-hooks --claude   # Claude Code only
hgp install-hooks --gemini   # Gemini CLI only

Hooks are installed into <repo_root>/.claude/hooks/ and <repo_root>/.gemini/hooks/. The command must be run from inside a git repository.

Storage

HGP stores its database and content-addressable blobs in <repo_root>/.hgp/ (gitignored). The server resolves the project root from the working directory at startup — it is bound to one repository per process.

Environment Variables

Variable Default Description
HGP_PROJECT_ROOT (auto) Override project root (default: nearest .git from cwd, or ~/.hgp/ if not in a repo)
HGP_GLOBAL_MODE (unset) Set to 1 to force legacy global store at ~/.hgp/ (all projects share one DB)
HGP_HOOK_BLOCK 0 Set to 1 to block native file tool calls (Write/Edit) instead of warning

MCP Client Configuration

Claude Code / Claude Desktop (claude_desktop_config.json or .claude/mcp.json):

{
  "mcpServers": {
    "hgp": {
      "command": "python",
      "args": ["-m", "hgp.server"]
    }
  }
}

The server is started from the project directory by the MCP host, so HGP_PROJECT_ROOT is typically not needed. Set it explicitly if the working directory at startup is not the project root.


Quick Start

These are MCP tool calls — not direct Python imports. Invoke them through your MCP client (Claude Code, Claude Desktop, or any MCP-compatible host).

# 1. Record an analysis operation (artifact)
hgp_create_operation(
    op_type="artifact",
    agent_id="agent-1",
    metadata={
        "description": "Analyzed error rate spike in service logs",
        "findings": "p99 latency exceeded 2s between 03:00-04:00 UTC",
    },
)
# → returns op_id: "op-abc123"

# 2. Record a decision (hypothesis) citing the analysis as evidence
hgp_create_operation(
    op_type="hypothesis",
    agent_id="agent-1",
    metadata={"description": "Root cause is database connection pool exhaustion"},
    parent_op_ids=["op-abc123"],
    evidence_refs=[
        {
            "op_id": "op-abc123",
            "relation": "supports",
            "scope": "latency correlation",
            "inference": "Latency spike aligns with connection pool saturation metrics",
        }
    ],
)
# → returns op_id: "op-def456"

# 3. Audit: what evidence did the decision cite?
hgp_get_evidence(op_id="op-def456")
# → lists all evidence records cited by op-def456

# 4. Audit: what decisions cited the original analysis?
hgp_get_citing_ops(op_id="op-abc123")
# → lists all ops that cited op-abc123 as evidence

Tool Index

Tool Description
hgp_create_operation Record a new operation; optionally attach payload, link parents, cite evidence
hgp_query_operations Filter operations by type, agent, status, or memory tier
hgp_query_subgraph Traverse ancestors or descendants from a root operation
hgp_acquire_lease Acquire an optimistic lock on a subgraph before multi-step writes
hgp_validate_lease Ping a lease to confirm it is still active (extends TTL by default)
hgp_release_lease Release a lease explicitly after writing
hgp_set_memory_tier Manually promote or demote an operation's memory tier
hgp_get_artifact Retrieve binary payload from CAS by its object_hash
hgp_anchor_git Link an operation to a Git commit SHA
hgp_reconcile Run crash-recovery reconciler (use after unexpected shutdown)
hgp_get_evidence List all operations a given op cited as evidence
hgp_get_citing_ops Reverse lookup — list all ops that cited a given op as evidence
hgp_write_file Write (create or overwrite) a file and record it as an artifact
hgp_append_file Append content to a file and record as artifact
hgp_edit_file Replace a unique string in a file and record as artifact
hgp_delete_file Delete a file and record an invalidation operation
hgp_move_file Move/rename a file; records invalidation of old path + new artifact
hgp_file_history Return all HGP operations recorded for a given file path

→ Full API reference: docs/tools-reference.md → Usage patterns and examples: docs/usage-patterns.md

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

history_graph_protocol-0.2.0.tar.gz (305.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

history_graph_protocol-0.2.0-py3-none-any.whl (37.6 kB view details)

Uploaded Python 3

File details

Details for the file history_graph_protocol-0.2.0.tar.gz.

File metadata

  • Download URL: history_graph_protocol-0.2.0.tar.gz
  • Upload date:
  • Size: 305.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for history_graph_protocol-0.2.0.tar.gz
Algorithm Hash digest
SHA256 4499dead143d66d27149b0be2cc79ea291ef62230553dc4951cd784a6c728af8
MD5 4e4c42512610f1d83f81cd387661ad00
BLAKE2b-256 5db3952462a9a824a23c2cd52956ad015cc0d5904d1f5fff30643ee6dad736de

See more details on using hashes here.

File details

Details for the file history_graph_protocol-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: history_graph_protocol-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 37.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for history_graph_protocol-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 acc0bba0f7b923e11d1ae897e2ff05ba8b167df812c670c15d57d83b75b0f173
MD5 add30cfe97fa03b25cb022daa5858248
BLAKE2b-256 1e1dadfa679aa8382c995a1446628da481085af46b66c928483f0247b0d7d049

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page