Files
darmanandClaude Opus 5.5 c13a0093c3 feat(mars): honcho-console phase 3 — metrics, stage models, spend
Honcho now exports Prometheus metrics (METRICS_ENABLED) for the
console's token, cost and latency views. The console prices each stage
with the models read from honcho-api's own environment, and reads
Honcho's OpenRouter key as a systemd credential for actual spend.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-02 23:54:48 +02:00

137 lines
5.1 KiB
Nix

{ config, pkgs, ... }:
# Honcho memory server: luna's memory provider (wired up in hermes-agent.nix
# prepare-dirs). API + deriver from the official image; Postgres and
# Ollama (embeddings) run natively. Everything binds loopback only.
let
honchoImage = "ghcr.io/plastic-labs/honcho@sha256:c74955d6dbea6dda42c2dd9dd13dea726fcba36ba5c0b6bae4867f7ed762896d"; # v3.2.2
honchoUid = 984;
honchoGid = 984;
# :nitro = OpenRouter's fastest-provider routing; the default picks cheap, slow hosts.
fastModel = "z-ai/glm-5.3-flash:nitro";
# Dreams maintain the peer cards, incl. her AI identity card.
smartModel = "deepseek/deepseek-v4-pro";
embedModel = "qwen3-embedding:0.6b";
# Peer auth over the socket: the container runs as the host's honcho uid,
# so there is no DB password to manage.
env = {
DB_CONNECTION_URI = "postgresql+psycopg://honcho@/honcho?host=/run/postgresql";
AUTH_USE_AUTH = "false";
CACHE_ENABLED = "false";
# Read by honcho-console (token usage, latency). The deriver serves its own
# on 0.0.0.0:9090, which the firewall keeps off the LAN.
METRICS_ENABLED = "true";
HOME = "/tmp";
LLM_OPENAI_BASE_URL = "https://openrouter.ai/api/v1";
# Lowest reasoning GLM allows ("none" is rejected): hidden reasoning can
# eat the deriver's whole output budget before any JSON is written.
DERIVER_MODEL_CONFIG__MODEL = fastModel;
DERIVER_MODEL_CONFIG__THINKING_EFFORT = "minimal";
SUMMARY_MODEL_CONFIG__MODEL = fastModel;
DIALECTIC_LEVELS__minimal__MODEL_CONFIG__MODEL = fastModel;
DIALECTIC_LEVELS__minimal__MODEL_CONFIG__THINKING_EFFORT = "minimal";
DIALECTIC_LEVELS__low__MODEL_CONFIG__MODEL = fastModel;
DIALECTIC_LEVELS__low__MODEL_CONFIG__THINKING_EFFORT = "minimal";
DIALECTIC_LEVELS__medium__MODEL_CONFIG__MODEL = smartModel;
DIALECTIC_LEVELS__high__MODEL_CONFIG__MODEL = smartModel;
DIALECTIC_LEVELS__max__MODEL_CONFIG__MODEL = smartModel;
DREAM_DEDUCTION_MODEL_CONFIG__MODEL = smartModel;
DREAM_INDUCTION_MODEL_CONFIG__MODEL = smartModel;
EMBEDDING_MODEL_CONFIG__MODEL = embedModel;
EMBEDDING_MODEL_CONFIG__OVERRIDES__BASE_URL = "http://127.0.0.1:11434/v1";
EMBEDDING_MODEL_CONFIG__OVERRIDES__API_KEY = "ollama";
# Fixed at the first migration; changing it later means a fresh DB.
EMBEDDING_VECTOR_DIMENSIONS = "1024";
EMBEDDING_MODEL_CONFIG__DIMENSIONS_MODE = "never";
};
container = {
image = honchoImage;
user = "${toString honchoUid}:${toString honchoGid}";
extraOptions = [ "--network=host" ];
volumes = [ "/run/postgresql:/run/postgresql" ];
environment = env;
environmentFiles = [ config.sops.templates."honcho.env".path ];
};
deps = [ "postgresql-setup.service" "honcho-db-setup.service" "ollama.service" ];
in
{
users.users.honcho = {
isSystemUser = true;
uid = honchoUid;
group = "honcho";
};
users.groups.honcho.gid = honchoGid;
services.postgresql = {
enable = true;
extensions = ps: [ ps.pgvector ];
ensureDatabases = [ "honcho" ];
ensureUsers = [{
name = "honcho";
ensureDBOwnership = true;
}];
};
# CREATE EXTENSION needs a superuser; Honcho's migrations only re-assert it.
systemd.services.honcho-db-setup = {
description = "Enable pgvector in the honcho database";
# ensureDatabases runs in postgresql-setup, not postgresql itself.
after = [ "postgresql-setup.service" ];
requires = [ "postgresql-setup.service" ];
serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;
User = "postgres";
};
script = ''
${config.services.postgresql.package}/bin/psql -d honcho -c 'CREATE EXTENSION IF NOT EXISTS vector'
'';
};
services.ollama = {
enable = true;
host = "127.0.0.1";
loadModels = [ embedModel ];
};
virtualisation.oci-containers.containers.honcho-api = container // {
# Image CMD binds 0.0.0.0 and skips migrations. Migrations create
# vector(1536); configure_embeddings resizes them (no-op once matching,
# refuses on populated tables).
entrypoint = "sh";
cmd = [
"-c"
"/app/.venv/bin/python scripts/provision_db.py && /app/.venv/bin/python scripts/configure_embeddings.py --yes && exec /app/.venv/bin/fastapi run --host 127.0.0.1 --port 8000 src/main.py"
];
};
virtualisation.oci-containers.containers.honcho-deriver = container // {
# Waits for the API, i.e. for the schema resize above.
entrypoint = "sh";
cmd = [
"-c"
"until /app/.venv/bin/python -c \"import urllib.request; urllib.request.urlopen('http://127.0.0.1:8000/health', timeout=2)\" 2>/dev/null; do sleep 2; done; exec /app/.venv/bin/python -m src.deriver"
];
};
systemd.services.podman-honcho-api = {
after = deps;
requires = deps;
};
systemd.services.podman-honcho-deriver = {
after = [ "podman-honcho-api.service" ];
requires = [ "podman-honcho-api.service" ];
};
# wants, not requires: Telegram must survive Honcho being down.
systemd.services.podman-hermes-agent = {
after = [ "podman-honcho-api.service" ];
wants = [ "podman-honcho-api.service" ];
};
}