model/context: configurable default model + model-derived context window

This commit is contained in:
damocles 2026-05-20 15:12:37 +02:00 committed by Mara
parent 67f948028c
commit 9064cd3c57
3 changed files with 117 additions and 43 deletions

View file

@ -15,6 +15,45 @@
# only opts in from its own `agent.nix`.
imports = [ ./weston-vnc.nix ];
options.hyperhive.model = lib.mkOption {
type = lib.types.str;
default = "haiku";
example = "sonnet";
description = ''
Default claude model for this agent. Sets the `HIVE_DEFAULT_MODEL`
environment variable consumed by the harness at boot; if no
persisted model choice exists in the agent's state dir the harness
falls back to this value. The operator can still switch the model at
runtime via the per-agent web UI that choice is persisted to the
state dir and takes precedence over this default until the agent is
purged.
Valid values are the short model names that `claude --model` accepts:
`"haiku"`, `"sonnet"`, `"opus"` (or any future identifier). The
harness derives sensible watermarks from the model family:
haiku 200 000 token window; sonnet / opus 1 000 000 token window.
Override the derived window via `hyperhive.contextWindowTokens`.
'';
};
options.hyperhive.contextWindowTokens = lib.mkOption {
type = lib.types.int;
default = 0;
example = 1000000;
description = ''
Context-window size in tokens for this agent's model. `0` (the
default) means "auto-derive from the model name": haiku 200 000,
sonnet / opus 1 000 000. Set an explicit value here when you are
using a model the harness does not recognise, or when Anthropic
changes the window for an existing model family.
Sets the `HIVE_CONTEXT_WINDOW_TOKENS` environment variable; the
harness reads it at runtime and uses it to compute the default
compaction and auto-reset watermarks (75% and 50% of the window
respectively).
'';
};
options.hyperhive.allowedBashPatterns = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [ ];
@ -208,6 +247,16 @@
environment.etc."hyperhive/claude-plugins-auto-update.json".text =
builtins.toJSON config.hyperhive.claudePluginsAutoUpdate;
# Model + context-window env vars consumed by the harness at boot.
# HIVE_DEFAULT_MODEL seeds the initial model selection when no persisted
# model choice exists in the state dir. HIVE_CONTEXT_WINDOW_TOKENS
# overrides the auto-derived window size (only set when the NixOS option
# is non-zero so an unset env var lets the harness use its own heuristic).
environment.variables.HIVE_DEFAULT_MODEL = config.hyperhive.model;
environment.variables = lib.mkIf (config.hyperhive.contextWindowTokens != 0) {
HIVE_CONTEXT_WINDOW_TOKENS = toString config.hyperhive.contextWindowTokens;
};
boot.isNspawnContainer = true;
# Every agent gets flakes + the modern `nix` CLI out of the box.