feat(ai-memory): central agent memory server on m3-hermes

Server: services.ai-memory (upstream NixOS module, llm-agents build) on
m3-hermes, bound to the Netbird range, LLM consolidation via z.ai GLM,
one global cross-project profile, auto-improve proposals gated behind
approval. Traefik on m3-atlas publishes it as memory.m3ta.dev.

Clients: per-host aim_ keys (user "sascha", labels kratos / hermes /
az-lt-nix) as agenix secrets. m3-kratos enables m3ta-home's
coding.aiMemory with the AZ checkouts routed to the "az" workspace.

Hermes: lifecycle hooks, MCP bridge and skills wired declaratively, a
home-workspace marker ("home"/"assistant"), and Honcho replaced by the
built-in notes so ai-memory is the single shared memory.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
m3tam3reandClaude Fable 5.1 committed 2026-10-25 13:01:05 +01:00
1 parent 35a0a45977
commit f142cc0721
15 files changed
+274 -12

No files matched your search

+73 -2
View File
@@ -13,12 +13,45 @@
# Same interpreter env the upstream merge script uses, so no extra
# closure cost — the derivation is shared.
yamlPython = pkgs.python3.withPackages (ps: [ps.pyyaml]);
# ── ai-memory client (server: ./ai-memory.nix, same host) ─────────────
# Hooks and the MCP bridge read the bearer from [auth].bearer_token_file
# in the data dir's config.toml, so neither config.yaml nor the process
# environment ever carries the token.
aiMemory = "${config.services.ai-memory.package}/bin/ai-memory";
aiMemoryUrl = "http://127.0.0.1:${toString (config.m3ta.ports.get "ai-memory")}";
aiMemoryDataDir = "/var/lib/hermes/.local/share/ai-memory";
aiMemoryHook = event: [
{
command = "${aiMemory} --data-dir ${aiMemoryDataDir} hook --event ${event} --agent hermes --server-url ${aiMemoryUrl}";
timeout = 20;
}
];
in {
virtualisation.docker.enable = true;
systemd.tmpfiles.rules = [
"d /var/lib/hermes/.config 0755 hermes hermes -"
"d /var/lib/hermes/.config/tea 0755 hermes hermes -"
"d /var/lib/hermes/.local 0755 hermes hermes -"
"d /var/lib/hermes/.local/share 0755 hermes hermes -"
"d ${aiMemoryDataDir} 0700 hermes hermes -"
"L+ ${aiMemoryDataDir}/config.toml - - - - ${pkgs.writeText "ai-memory-hermes-config.toml" ''
server_url = "${aiMemoryUrl}"
[auth]
bearer_token_file = "${config.age.secrets."ai-memory-hermes-token".path}"
''}"
# Scope marker: Hermes reports its process directory as cwd, so every
# assistant session lands in one project of the `home` workspace
# (coding checkouts below $HOME with their own marker still win).
"L+ /var/lib/hermes/.ai-memory.toml - - - - ${pkgs.writeText "ai-memory-hermes-marker.toml" ''
workspace = "home"
project = "assistant"
[capture]
ignore_paths = ["/run/agenix/**", "**/.env*", "/var/lib/hermes/.hermes/auth*", "/var/lib/hermes/.ssh/**"]
''}"
"L+ /var/lib/hermes/.config/tea/yml - - - - ${pkgs.writeText "tea-yml" ''
logins:
- name: m3ta
@@ -39,7 +72,6 @@ in {
# without runtime pip/uv mutation.
extraDependencyGroups = [
"matrix"
"honcho"
"exa"
"edge-tts"
"voice"
@@ -91,6 +123,11 @@ in {
API_SERVER_PORT = toString (config.m3ta.ports.get "hermes-api");
};
mcpServers.ai-memory = {
command = aiMemory;
args = ["mcp-bridge" "--no-session-id" "--server-url" "${aiMemoryUrl}/mcp" "--data-dir" aiMemoryDataDir];
};
# ── Container mode (podman) ──────────────────────────────────────────
container = {
enable = false;
@@ -217,9 +254,23 @@ in {
silence_duration = 3.0;
};
# ── ai-memory hooks ────────────────────────────────────────────────
# From `ai-memory install-hooks --agent hermes` (3.2.2). ai-memory is
# the one shared memory for every agent; Honcho was dropped in favour
# of it (2026-10-25), only Hermes' small built-in notes remain.
hooks_auto_accept = true;
hooks = {
pre_tool_call = aiMemoryHook "pre-tool-use";
post_tool_call = aiMemoryHook "post-tool-use";
on_session_start = aiMemoryHook "session-start";
pre_llm_call = aiMemoryHook "user-prompt-submit";
on_session_end = aiMemoryHook "stop";
on_session_finalize = aiMemoryHook "session-end";
};
# ── Memory ─────────────────────────────────────────────────────────
memory = {
provider = "honcho";
provider = "builtin";
memory_enabled = true;
user_profile_enabled = true;
memory_char_limit = 2200;
@@ -287,6 +338,26 @@ in {
];
};
# ── ai-memory skills ──────────────────────────────────────────────────
# Hermes ignores MCP server instructions; the routing rules reach the
# model through these skills in ~/.hermes/skills, refreshed on each boot
# so they track the installed ai-memory version.
systemd.services.hermes-ai-memory-skills = {
description = "Install ai-memory skills for Hermes";
before = ["hermes-agent.service"];
wantedBy = ["hermes-agent.service"];
environment = {
HOME = "/var/lib/hermes";
HERMES_HOME = hermesHome;
};
serviceConfig = {
Type = "oneshot";
User = "hermes";
Group = "hermes";
ExecStart = "${aiMemory} --data-dir ${aiMemoryDataDir} install-skills --scope global --agent hermes";
};
};
# ── Activation hardening ─────────────────────────────────────────────
# Upstream (hermes-agent v2026.9.24) deep-merges the Nix settings into
# the runtime-writable config.yaml via a bare `yaml.safe_load()` with no