How OpenHuman's `memory-git` Feature Uses Git for Wiki Backups, Checkpoints, and Diffs

The memory-git feature in OpenHuman leverages the git2 crate to version-control the agent's knowledge graph, enabling automatic Git commits for checkpoints, exportable Markdown wikis for backups, and computable diffs between memory states.

OpenHuman stores an AI agent's long-term knowledge in its Memory domain, and the optional memory-git feature adds Git-based versioning for durability and auditability. When enabled via the memory-git Cargo flag, this system transforms volatile memory states into durable commits, providing three core capabilities through direct integration with the git2 library.

Three Core Capabilities of the memory-git Feature

The memory-git implementation divides its functionality into three distinct operational modes: wiki export for human-readable backups, automatic checkpointing for state preservation, and differential analysis for audit trails.

Wiki Backups via Markdown Export

The wiki backup system converts the entire memory graph into a Git-compatible repository of Markdown files. Located in src/openhuman/memory/wiki, the wiki::export implementation handles serialization and remote synchronization.

This module creates a set of Markdown files representing the knowledge base and uses the git2 crate to initialize a repository, stage files with repo_add_all(), and commit changes. The resulting repository can be pushed to a remote URL configured in src/openhuman/config/schema/memory.rs under git.wiki.remote_url, providing a durable, human-readable backup that supports external editing.

Configurable Checkpoints

At configurable intervals—either on each conversational turn or via a timer—the current memory state is snapshotted into a Git commit. The checkpoint logic lives in src/openhuman/memory/checkpoint.rs, specifically within the Checkpoint::save function.

This function serializes the memory graph using the shared serialization logic in src/openhuman/memory/serialization.rs, writes the output to the repository's working tree at .openhuman/memory.git, and creates an immutable commit via git2::Repository::commit. This creates a complete history of the knowledge base that supports rollback to any prior point.

Diff Generation and Audit Trails

When memory changes occur, OpenHuman computes a textual diff between snapshots and records it as a Git patch. The DiffEngine struct in src/openhuman/memory/diff.rs orchestrates this process.

The engine loads two commit trees using the git2 API, invokes git2::Tree::diff to produce a git2::Diff object, and extracts the resulting patch. This diff can be inspected, applied, or reverted, enabling fine-grained audit trails of how the agent's knowledge evolved over time.

Implementation Architecture

Under the hood, the memory-git feature relies on a layered architecture that abstracts Git operations while maintaining zero-cost abstractions for builds that disable the feature.

Repository Initialization and Driver Layer

When the memory-git feature is compiled, the git2 dependency links against libgit2. The memory subsystem creates or opens a Git repository at .openhuman/memory.git in the user's workspace, managed by src/openhuman/memory/driver/git.rs.

This driver file contains wrapper functions that encapsulate common Git workflows:

  • repo_init() – Creates a new repository if none exists
  • repo_add_all() – Stages every file under the memory directory
  • repo_commit(message) – Writes a commit with a timestamped message
  • repo_diff(old_rev, new_rev) – Returns a textual diff between revisions

Memory Serialization Pipeline

Before Git can version the memory graph, it must be serialized to disk. The src/openhuman/memory/serialization.rs module handles conversion of the internal graph structure into JSON and Markdown formats. This serialization layer is reused by both the wiki exporter and the checkpoint writer, ensuring consistent on-disk representation across backup and checkpointing workflows.

Feature Gates and Fallback Behavior

All code paths that touch Git are guarded by #[cfg(feature = "memory-git")] conditional compilation flags. When the feature is disabled, the system falls back to the in-process Tinymemory engine without Git interaction, as implemented in src/openhuman/memory/binding.rs. This design ensures that binary size is minimized for deployments that do not require version-controlled memory.

Configuration and System Integration

The memory-git feature exposes runtime configuration through the core schema in src/openhuman/config/schema/memory.rs. Key settings include git.enabled, git.auto_checkpoint_interval, and git.wiki.remote_url, which control activation, checkpoint frequency, and remote backup destinations respectively.

Agent Tool Interface

The system exposes checkpointing directly to AI agents through the memory_git_checkpoint tool. Defined in src/openhuman/tools/impl/memory/git_checkpoint.rs, this tool allows an LLM to request explicit snapshots of the current memory state during conversation turns.

Remote Synchronization and Security

The composio sync service in src/openhuman/memory/sync/composio/ can be configured to push memory commits to remote Git servers, enabling multi-device synchronization. For security-critical deployments, Git commits can be signed with GPG keys if provided, and all commit metadata is logged by the core audit subsystem in src/openhuman/security/audit.rs, guaranteeing non-repudiation of knowledge edits.

Practical Code Examples

The following examples demonstrate how to interact with the memory-git system programmatically.

Creating a manual checkpoint after a conversational turn:

use openhuman::memory::checkpoint::Checkpoint;

let mem = core.memory();                // Get the memory instance
let ckpt = Checkpoint::new(&mem);
ckpt.save("Turn 42 checkpoint")?;      // Writes a Git commit

Exporting the entire memory graph as a Markdown wiki and pushing to a remote:

use openhuman::memory::wiki::export_wiki;

let repo_path = "/home/user/.openhuman/memory.git";
export_wiki(repo_path, "https://git.example.com/user/memory.wiki.git")?;

Computing a diff between the current and previous checkpoint:

use openhuman::memory::diff::DiffEngine;

let diff = DiffEngine::new(&mem)?;
let patch = diff.between("HEAD~1", "HEAD")?;
println!("{}", patch);                 // Human‑readable patch

Summary

  • The memory-git feature enables Git-based versioning of OpenHuman's memory graph through the git2 crate, activated via the memory-git Cargo feature flag.
  • Wiki backups are generated in src/openhuman/memory/wiki as Markdown files that can be pushed to remote repositories for human-readable, editable archives.
  • Checkpoints in src/openhuman/memory/checkpoint.rs create immutable Git commits at configurable intervals, allowing full rollback capabilities via Checkpoint::save.
  • Diffs produced by src/openhuman/memory/diff.rs provide textual patches between memory states for auditing and change tracking.
  • The architecture uses #[cfg(feature = "memory-git")] guards to fall back to the Tinymemory engine when the feature is disabled, ensuring minimal binary overhead.
  • Configuration is managed through src/openhuman/config/schema/memory.rs with settings for auto-checkpoint intervals and remote URLs.
  • The system supports agent-triggered checkpoints via memory_git_checkpoint and integrates with security auditing in src/openhuman/security/audit.rs.

Frequently Asked Questions

How do I enable the memory-git feature in OpenHuman?

Enable the feature by compiling OpenHuman with the memory-git Cargo flag. In your build command or Cargo.toml, include --features memory-git. When enabled, the system links the git2 crate and initializes a repository at .openhuman/memory.git; when disabled, it falls back to the in-process Tinymemory engine without Git dependencies.

What file formats does the wiki backup use?

The wiki backup serializes the memory graph into Markdown files using the serialization logic in src/openhuman/memory/serialization.rs. This produces a human-readable directory structure that can be browsed, edited in standard text editors, and synchronized to remote Git repositories as a Git-compatible wiki.

Can AI agents trigger checkpoints manually?

Yes. The memory_git_checkpoint tool in src/openhuman/tools/impl/memory/git_checkpoint.rs exposes checkpoint functionality to the agent runtime. An LLM can invoke this tool during conversation to request an immediate snapshot of the current memory state, which executes Checkpoint::save and creates a Git commit with a custom message.

How does OpenHuman secure the Git repository for sensitive data?

OpenHuman supports GPG signing of commits when users provide a GPG key in the configuration. Additionally, the core audit subsystem in src/openhuman/security/audit.rs logs all commit metadata, ensuring non-repudiation and providing an immutable record of when knowledge was modified and by which process or agent tool.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →