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:
1 parent
35a0a45977
commit
f142cc0721
15 files changed
+274
-12
No files matched your search
@@ -0,0 +1,52 @@
|
||||
{
|
||||
config,
|
||||
pkgs,
|
||||
...
|
||||
}: let
|
||||
# Netbird mesh VPN range — the server is only reachable from mesh peers.
|
||||
# m3-atlas Traefik proxies memory.m3ta.dev to this port over Netbird.
|
||||
netbirdRange = "100.64.0.0/16";
|
||||
port = config.m3ta.ports.get "ai-memory";
|
||||
in {
|
||||
# ── ai-memory server ──────────────────────────────────────────────────
|
||||
# Shared agent memory for all hosts (private + work), see
|
||||
# https://aimemory.sh. Clients: m3ta-home `coding.aiMemory`.
|
||||
#
|
||||
# Flow: Agent → memory.m3ta.dev (TLS via m3-atlas Traefik) → Netbird → :${toString port}
|
||||
# Hermes on this host talks to 127.0.0.1 directly.
|
||||
services.ai-memory = {
|
||||
enable = true;
|
||||
# Same build as the clients (m3ta-home uses llm-agents.ai-memory),
|
||||
# prebuilt via the numtide cache instead of compiling the flake.
|
||||
package = pkgs.llm-agents.ai-memory;
|
||||
bind = "0.0.0.0";
|
||||
inherit port;
|
||||
enableWeb = true;
|
||||
# Root bearer, token pepper, recovery token, cookie/proxy settings and
|
||||
# the LLM provider key. Never put any of these into `settings`.
|
||||
ageSecret = "ai-memory-server-env";
|
||||
settings = {
|
||||
allowed_hosts = ["memory.m3ta.dev" "localhost" "127.0.0.1" "::1"];
|
||||
# One operator, several workspaces (private, az, home): keep one
|
||||
# cross-project profile for all of them. With database users the
|
||||
# profile is off unless enabled explicitly.
|
||||
profile = {
|
||||
enabled = true;
|
||||
share = "global";
|
||||
};
|
||||
# Shared server: auto-improvement proposals wait for approval.
|
||||
auto_improve.require_approval = true;
|
||||
};
|
||||
};
|
||||
|
||||
networking.firewall = {
|
||||
extraCommands = ''
|
||||
# Allow ai-memory only from Netbird mesh VPN
|
||||
ip46tables -A nixos-fw -p tcp --dport ${toString port} -s ${netbirdRange} -j nixos-fw-accept
|
||||
'';
|
||||
|
||||
extraStopCommands = ''
|
||||
ip46tables -D nixos-fw -p tcp --dport ${toString port} -s ${netbirdRange} -j nixos-fw-accept 2>/dev/null || true
|
||||
'';
|
||||
};
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
./hermes-agent.nix
|
||||
./herdr-sandbox.nix
|
||||
./hermes-dashboard.nix
|
||||
./ai-memory.nix
|
||||
./netbird.nix
|
||||
];
|
||||
}
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user