Run everything on the local model; no cloud tier

GLM-4.7-Flash can reach core over SSH, check, diagnose and upgrade, so
operator messages, alert triage, health findings and the weekly upgrade all
route to the one local profile. The Anthropic profile and its cloud-first
routing go, and with them the API key and metered billing the first draft
needed. The local profile's context_tokens rises to 131072, the window Ollama
loads GLM with, so long runs are not trimmed early.

Profiles and routing stay in configuration: a second model can still be
added, with hand-over when the first is unreachable or fails the run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
paulandClaude Opus 5.5 committed 2026-09-26 01:59:28 +12:00
1 parent 61dca2c3ca
commit 9aa1abf0e2
7 files changed
+89 -93

No files matched your search

+12 -11
View File
@@ -10,8 +10,8 @@ SSH, and talks to the operator over Matrix (chat.semprini.me).
It is the *unattended driver* for the canonical **stack-support agent**, which lives in the
separate **semprini-core** repo. This project does not reimplement that logic: it notices
events, runs the stack-support agent in-process with **pydantic-ai** on a cloud or local
model, and relays the agent's typed result.
events, runs the stack-support agent in-process with **pydantic-ai** on the workstation's
local model (GLM-4.7-Flash on Ollama), and relays the agent's typed result.
Until 2026-09-26 it ran on the core host itself and drove Claude Code headless;
`docs/architecture.md` records why that changed.
@@ -40,14 +40,15 @@ Until 2026-09-26 it ran on the core host itself and drove Claude Code headless;
- **Hosts** (`hosts.py`, `config.json` → `hosts`): `core` (ssh, one multiplexed
connection), `local` (WSL bash) and `windows` (`powershell.exe` through WSL interop).
The daemon's probes, its git bookkeeping and the agent's tools all run through them.
- **Models** (`agent.py`, `config.json` → `models`, `routing`, `limits`): named profiles
(`anthropic:…` with an API key, `ollama:…` on Windows at `{windows_host}`, any
OpenAI-compatible `base_url`, or anything pydantic-ai infers). Each kind of task tries its
chain in order: an unreachable model hands over at once (`FallbackModel`); a run that
fails as a run (budget spent, no usable result) restarts on the next profile, told what
the failed attempt ran. None usable → `AgentUnavailable`: the task stays queued, the
operator is told once, retries back off from 60s to 15 min. `model local|cloud|auto` in
Matrix pins a room. `--try-model` checks a profile calls tools and *uses their results*.
- **Models** (`agent.py`, `config.json` → `models`, `routing`, `limits`): one profile,
`local` (GLM-4.7-Flash on the Windows host's Ollama, at `{windows_host}`), routed for every
kind of task. The operator decided (2026-09-26) that the local model does all of it,
upgrades included, with no cloud tier. The mechanism stays general: a profile can be
`anthropic:…` with an API key, any OpenAI-compatible `base_url`, or anything pydantic-ai
infers, and a routing list with a second profile hands over when the first is unreachable
(`FallbackModel`) or fails the run. No usable model → `AgentUnavailable`: the task stays
queued, the operator is told once per kind, and that kind backs off from 60s to 15 min.
`--try-model` checks a profile calls tools and *uses their results*.
- **The agent**: tools `shell`, `read_file`, `write_file`, `edit_file` (all on a named
host) and `fetch_url`; result type `Envelope` (status, summary, details, question,
options). Conversations are pydantic-ai message histories in `<state dir>/sessions/`, so a
@@ -81,7 +82,7 @@ Until 2026-09-26 it ran on the core host itself and drove Claude Code headless;
boot time and a pending reboot. Monitors confirmed DOWN over `down_confirmations`
cycles, blips, host anomalies and reboots become **one** health task. Three cycles that
cannot reach core raise 🚨. Scope = Kuma's active monitors, re-read every cycle.
- **Daily report** at `digest_hour_utc` (runs by model, cloud spend); **weekly upgrade**
- **Daily report** at `digest_hour_utc`; **weekly upgrade**
at `upgrade_weekday` / `upgrade_hour_utc` (all images on the core host; a pending reboot
is escalated for approval).
- **One agent run at a time.** The queue is persisted in the state file with priority
+30 -39
View File
@@ -9,9 +9,9 @@ stack on AWS Lightsail (`Semprini-Core`) healthy and current:
It is the *unattended driver* for the canonical stack-support agent in the **semprini-core**
repo (`agents/stack-support.agent.md`). The daemon notices events and hands the judgement
calls to that agent, which it runs in-process with [pydantic-ai](https://ai.pydantic.dev) on a
cloud model (Claude) or a local one (Ollama on the workstation's RTX 4090), chosen per kind of
task. Design and decisions: [`docs/architecture.md`](docs/architecture.md).
calls to that agent, which it runs in-process with [pydantic-ai](https://ai.pydantic.dev) on the
workstation's own model: GLM-4.7-Flash on Ollama, on the RTX 4090. Any model pydantic-ai
supports can be configured instead. Design and decisions: [`docs/architecture.md`](docs/architecture.md).
## Talking to it
@@ -24,7 +24,7 @@ Two rooms on chat.semprini.me:
Messages are read with a long-poll `/sync`: the homeserver answers as soon as something is
posted, so there is no polling delay. Every reply ends with a small line saying which model
answered, how long it took and, for a cloud model, what it cost.
answered and how long it took.
A message that is exactly one of these is handled at once, even mid-run:
@@ -35,8 +35,7 @@ A message that is exactly one of these is handled at once, even mid-run:
| `hold 45m <why>` | Stand down for a while: `hold` alone is 30 minutes, 8 hours is the most. Your messages still run and alerts still collect; health checks, triage, upgrades and the service desk wait, and it says so when the hold starts and when it runs out |
| `resume` | End a hold now, this machine's and the core host's |
| `new` | Forget this room's conversation |
| `model` | The model profiles and which kinds of task try which, in order |
| `model local` / `model cloud` | Your messages in this room try that profile first; `model auto` goes back to the default |
| `model` | The model it runs on. With more than one configured, `model <name>` puts that one first for your messages in this room, and `model auto` goes back to the default |
| `upgrade` | Run the weekly upgrade now |
| `help` | The list |
@@ -52,7 +51,7 @@ A message that is exactly one of these is handled at once, even mid-run:
| — Disk ≥ 85%, memory < 400 MB, kernel OOM kill, restart loop, stale Kuma | Investigate and fix; 12h cooldown per finding |
| — Core host rebooted | Verify every stack came back |
| — Core host unreachable for 3 checks | 🚨 in Stack Maintenance (delivered once Matrix, which lives there, is back) |
| Daily, 21:00 UTC | 📋 report: monitors, downtime, alerts, agent runs by model, cloud spend, commits, pending reboot or decision |
| Daily, 21:00 UTC | 📋 report: monitors, downtime, alerts, agent runs, commits, pending reboot or decision |
| Weekly, Sat 22:00 UTC | Upgrade every image and host package on core: test, pin, commit, push, roll back on failure. Majors and reboots are escalated |
| Every minute | Service desk: semprini-core's `service-desk.py`, run on the core host over SSH, fulfils the open requests in [Semprini/service-desk](https://git.semprini.me/Semprini/service-desk). What needs you is posted here: 🙋 an approval (`/approve` or `/reject` on the issue), ⛔ a failure (`/retry` once fixed), 📨 an "Ask core" request, ✅ a finished one. Waits out a hold |
| Hourly | Self-update from this repo |
@@ -72,11 +71,11 @@ image on the core host.
│ (operator > alerts > health > upgrade) │ │ service-desk.py
│ agent.py (pydantic-ai): shell · read/write/edit │ │ ~/semprini-core: the agent
│ file · fetch_url, on a named host │ │ edits, commits and pushes here
└───────┬───────────────────────────┬───────────────┘ └──────────────────────────────
│ cloud │ local
▼ ▼
Anthropic API Ollama on Windows (RTX 4090)
(claude-sonnet-5) (GLM-4.7-Flash) powershell.exe → Hyper-V (read-only)
└───────┬──────────────────────────┬────────────────┘ └──────────────────────────────
│ model │ powershell.exe
▼ ▼
Ollama on Windows (RTX 4090) Hyper-V: the home cluster VMs (inspect only)
GLM-4.7-Flash
```
The agent's result is a typed envelope the daemon relays:
@@ -87,37 +86,31 @@ The agent's result is a typed envelope the daemon relays:
## Models
`config.json` → `models` names profiles; `routing` gives each kind of task the profiles to try,
best first:
One local model does everything: your messages, alert triage, health findings and the weekly
upgrade. In `config.json`:
```json
"models": {
"cloud": {"model": "anthropic:claude-sonnet-5", "api_key": "…"},
"local": {"model": "ollama:hf.co/bartowski/zai-org_GLM-4.7-Flash-GGUF:Q5_K_S",
"base_url": "http://{windows_host}:11434/v1", "context_tokens": 32768}
"base_url": "http://{windows_host}:11434/v1", "context_tokens": 131072}
},
"routing": {"operator": ["cloud", "local"], "alerts": ["local", "cloud"],
"health": ["cloud", "local"], "upgrade": ["cloud"]}
"routing": {"operator": ["local"], "alerts": ["local"], "health": ["local"], "upgrade": ["local"]}
```
- **An unreachable model** (Ollama stopped, an API outage, a revoked key) hands the run to
the next profile at once. When none is left, the task stays queued and the maintainer
reports itself degraded.
- **A run that fails as a run** (the model loops until its budget is spent, or cannot produce
the result) starts again on the next profile, told which commands the failed attempt ran.
- A profile is `provider:model`. `anthropic:` and `ollama:` are built in; `openai:` with a
- A profile is `provider:model`. `ollama:` and `anthropic:` are built in; `openai:` with a
`base_url` is any OpenAI-compatible server (llama.cpp's `llama-server`, vLLM, LM Studio);
anything else pydantic-ai knows (`openai:gpt-…`, `google-gla:…`, `openrouter:…`) works with
its key in `api_key` or the provider's environment variable. `settings` passes model
settings through, e.g. `{"anthropic_effort": "high"}`.
- `limits` caps each run: `request_limit`, `tool_calls_limit`, and `cost_usd` per kind of task
for metered (Anthropic) runs.
**Cloud billing.** pydantic-ai calls the Anthropic API with an API key, billed per token. The
`claude setup-token` subscription token of the Claude Code era does not work here. Claude
Sonnet 5 is $2 / $10 per million input / output tokens; the system prompt, tool list and
conversation are prompt-cached, so repeated steps cost much less. The footer on each reply
and the daily report show the spend.
its key in `api_key` (`--set-api-key <profile>`) or the provider's environment variable.
`settings` passes model settings through. `context_tokens` is the window the model is run
with; older tool output is shortened as a conversation nears it.
- `routing` lists the profiles each kind of task tries, best first. With a second profile in a
list, an unreachable model hands the run to the next at once, and a run that fails as a run
(it loops until its budget is spent, or cannot produce the result) starts again on the next,
told which commands the failed attempt ran.
- `limits` caps each run: `request_limit`, `tool_calls_limit`, and `cost_usd` per kind of task,
which only a priced (cloud) model is held to.
- A cloud model is billed per token and needs an API key; a Claude subscription token (from
`claude setup-token`) is for Claude Code only and does not work here.
**Choosing a local model.** A local model is only useful if it calls tools and *uses what they
return*. `--try-model <profile>` checks both with one request, and checks Ollama's context
@@ -157,7 +150,6 @@ git clone https://git.semprini.me/paul/semprini-maintainer.git ~/semprini-mainta
cd ~/semprini-maintainer
cp config.example.json config.json # then copy matrix.* and gitea.token from the host's config.json
./install.sh # uv, .venv, SSH check, --check, systemd unit, takes over from the host
.venv/bin/python maintainer.py --set-api-key cloud # checks it with one request, saves it
.venv/bin/python maintainer.py --try-model local # tool use and context window
```
@@ -225,10 +217,9 @@ and disable the broader one.
### When no model can run
A revoked or missing API key, Ollama stopped, a provider outage: the agent never started. That
is a *maintainer* outage, not a stack verdict (`AgentUnavailable`). It is tracked per kind of
task, because each kind has its own models: with no cloud key, the cloud-only weekly upgrade
waits while your messages and alerts go to the local model.
Ollama stopped or unreachable, or (for a cloud profile) a revoked key or a provider outage: the
agent never started. That is a *maintainer* outage, not a stack verdict (`AgentUnavailable`). It
is tracked per kind of task, because each kind can be routed to its own models.
- The task stays in the persisted queue; nothing is lost.
- One `⛔ maintainer degraded` message per kind names the likely cause and the fix, then it
+3 -3
View File
@@ -5,9 +5,9 @@ maintainer.py decides *when* the agent runs and relays what it says; this
module decides *how*: which model, which tools, what it is told, and how a
conversation is kept between runs.
Models are named profiles in config.json -> models (a cloud one and a local
one, or several of each), and config.json -> routing gives each kind of task
an ordered chain of profiles:
Models are named profiles in config.json -> models (by default one: the local
model), and config.json -> routing gives each kind of task an ordered chain
of profiles. With more than one:
* an API failure (Ollama not running, a 5xx, a revoked key) moves to the
next profile at once, for the rest of the run (FallbackModel)
+5 -6
View File
@@ -20,14 +20,13 @@
"runbook_file": "docs/stack-support-runbook.md",
"models": {
"cloud": {"model": "anthropic:claude-sonnet-5", "api_key": ""},
"local": {"model": "ollama:hf.co/bartowski/zai-org_GLM-4.7-Flash-GGUF:Q5_K_S", "base_url": "http://{windows_host}:11434/v1", "context_tokens": 32768}
"local": {"model": "ollama:hf.co/bartowski/zai-org_GLM-4.7-Flash-GGUF:Q5_K_S", "base_url": "http://{windows_host}:11434/v1", "context_tokens": 131072}
},
"routing": {
"operator": ["cloud", "local"],
"alerts": ["local", "cloud"],
"health": ["cloud", "local"],
"upgrade": ["cloud"]
"operator": ["local"],
"alerts": ["local"],
"health": ["local"],
"upgrade": ["local"]
},
"limits": {
"request_limit": 150,
+22 -20
View File
@@ -8,7 +8,7 @@ Revised 2026-09-15 for the move to AWS Lightsail: the daemon ran on the stack ho
to Matrix events instead of polling, and kept the repo equal to what runs.
Revised 2026-09-26: the daemon moved to the operator's workstation, and from Claude Code to
pydantic-ai with configurable cloud and local models. Decisions that changed say so below.
pydantic-ai on the workstation's local model. Decisions that changed say so below.
## Purpose
@@ -34,7 +34,7 @@ relays its results.
| Post-mortem | Kuma DOWN→UP between checks | Agent finds the cause in logs; changes nothing healthy | Report in Stack Maintenance |
| Host checks | 5-min timer on core: disk ≥ 85%, memory < 400 MB, OOM kill, restart loop, Kuma stale, reboot | Agent investigates (12h cooldown per finding) | Report in Stack Maintenance |
| Core unreachable | 3 health checks in a row cannot reach core over SSH | No agent: nothing it could do from here | 🚨, delivered once Matrix is back |
| Daily report | 21:00 UTC | No agent: monitors, downtime, alerts, runs by model, cloud spend, commits, pending reboot or decision | 📋 in Stack Maintenance |
| Daily report | 21:00 UTC | No agent: monitors, downtime, alerts, agent runs, commits, pending reboot or decision | 📋 in Stack Maintenance |
| Weekly upgrade | Sat 22:00 UTC (Sun 08:00 AEST) | Agent upgrades every image and host packages on core; pins, commits, pushes; escalates majors and reboots | Report + decisions |
| Service desk | Every minute | `service-desk.py poll` on core, over SSH | 🙋 / ⛔ / 📨 / ✅ |
| Self-update | Hourly | Fast-forward this checkout, `uv sync` if needed, `--check`, re-exec | 🔄 notice |
@@ -63,20 +63,24 @@ relays its results.
semprini-core's rule ("on the host, commit what you apply") unchanged. Files are written in
place, never renamed over, because core's configs are bind-mounted single files.
- **Runner = pydantic-ai in the daemon's process** (2026-09-26; reverses Claude Code
headless, `claude -p`). What it gains: any model, cloud or local, per kind of task, with
fallback; a typed result instead of a JSON block fished out of prose; cancellation that
headless, `claude -p`). What it gains: any model pydantic-ai supports, local or cloud, with
fallback between them when more than one is configured; a typed result instead of a JSON
block fished out of prose; cancellation that
stops the command in flight; one Python process instead of a CLI per run. What it gives
up: Claude Code's large tool set, automatic `CLAUDE.md` loading, compaction and web search.
The agent now has five tools (`shell`, `read_file`, `write_file`, `edit_file` on a named
host, and `fetch_url`); the instructions tell it to grep the runbook and `CLAUDE.md` on core
for what it needs, and old tool output is shortened when a conversation nears a model's
window.
- **Models are profiles, routed per kind of task.** Defaults: operator messages and health
findings try the cloud first, alert triage tries the local model first, the weekly upgrade
is cloud only. Triage is the most frequent run and mostly reading, so it is the one worth
keeping local; the upgrade is the most consequential. An unreachable model hands over at
once (`FallbackModel`); a run that fails as a run restarts on the next profile, told what
the failed attempt ran. Each reply says which model answered.
- **One local model does everything** (2026-09-26, the operator's decision). Operator
messages, alert triage, health findings and the weekly upgrade all run on GLM-4.7-Flash:
the operator judged it able to reach core over SSH, check, diagnose and upgrade, and saw
no reason for a second tier. It replaced a first design, the same day, that sent operator
messages, health findings and the upgrade to Claude through the API. So there is no
metered billing and no API key to hold. The mechanism is kept general in configuration:
models are profiles, and `routing` lists the profiles each kind of task tries; a second
profile in a list takes over when the first is unreachable (`FallbackModel`) or fails the
run, told what the failed attempt ran. Each reply says which model answered.
- **Local model = GLM-4.7-Flash on Ollama, on Windows** (tested 2026-09-26). The one test
that matters is whether a model uses what a tool returns: `--try-model` gives it a value it
cannot guess. GLM-4.7-Flash and qwen3.5:35b passed; qwen3-coder called the tool and then
@@ -84,11 +88,9 @@ relays its results.
Ollama runs on the Windows host, not in WSL: its models, its GPU driver and its app are
there. The app's *Expose Ollama to the network* setting lets WSL reach it (through WSL's
gateway to Windows); it also opens it to the home LAN, and Ollama has no authentication.
- **Credential = an API key per cloud profile** (2026-09-26; reverses the `claude
setup-token` subscription token). pydantic-ai calls the Anthropic API, which is billed per
token; the subscription token is for Claude Code only. Mitigations: the instructions, tool
list and conversation are prompt-cached; `limits.cost_usd` caps each run by kind; the
footer and the daily report show the spend; the most frequent work is routed local.
- **No model credential** (2026-09-26; retires the `claude setup-token` subscription token,
which is for Claude Code only). A cloud profile added later would need an API key, billed
per token; `limits.cost_usd` caps each run on a priced model.
- **Event-driven via long-poll `/sync`, not a Synapse application service.** The
homeserver holds a `/sync` request open and answers the moment an event lands, so
messages are handled within about a second. An appservice would push over HTTP instead,
@@ -150,12 +152,12 @@ access — and a smaller local model is likely to resist such text less well tha
- **When core dies, the warning cannot get out.** The daemon now notices, but Matrix lives on
core, so the 🚨 waits in the outbox. A second channel that does not depend on core (ntfy,
or mail through SES directly) would close it.
- **A local model acts on production.** Alert triage runs local first by default. It can
change things (demote log lines, restart containers); a weaker model may judge worse.
Watch the footers, and move `alerts` to cloud first if its work disappoints.
- **One local model runs production alone.** GLM-4.7-Flash does every task, upgrades
included, with no stronger model behind it. Its commits are in Gitea and its replies say
what it did; a second profile in `routing` is the lever if its judgement disappoints.
- **Ollama down means no agent.** With one profile there is nothing to hand over to: tasks
wait, and the operator is told once per kind of task.
- **Gitea lives on the host it describes.** vol-backup copies its volume to S3 nightly, and
workstation clones exist. A push mirror to GitHub would make a rebuild independent of S3.
- **Cloud runs are metered.** A runaway run is capped by `limits`; a runaway *schedule* (an
alert storm past the cooldowns) is not, beyond the one-run-at-a-time queue.
- **Health checks pause during an agent run.** A 30-minute upgrade delays the next Kuma
check by up to that long; alerts and operator messages still queue and are acknowledged.
+1 -1
View File
@@ -111,7 +111,7 @@ cat <<EOF
Logs: journalctl -u $UNIT -f
Status: systemctl status $UNIT (or send 'status' in Matrix)
Stop: sudo systemctl stop $UNIT
Models: $PY $DIR/maintainer.py --try-model local (and cloud)
Model: $PY $DIR/maintainer.py --try-model local
WSL stops when nothing runs in it. Keep it up with a Windows scheduled task
that starts at logon (PowerShell or cmd, one line):
+16 -13
View File
@@ -28,7 +28,8 @@ Event-driven where something announces itself:
All agent work runs one task at a time through the canonical stack-support
agent (semprini-core/agents/stack-support.agent.md), run in-process with
pydantic-ai (agent.py) on a cloud or local model chosen per kind of task.
pydantic-ai (agent.py), on the workstation's local model (GLM-4.7-Flash on
Ollama) unless config.json names others.
Operator messages go to the front of the queue.
The daemon runs on the operator's workstation, not on the stack it keeps:
@@ -105,24 +106,26 @@ DEFAULTS = {
"extra_dirs": [f"{CORE_HOME}/semprini-blog", f"{CORE_HOME}/conk"],
"agent_file": "agents/stack-support.agent.md",
"runbook_file": "docs/stack-support-runbook.md",
# Model profiles (agent.py). An api_key is saved with --set-api-key and
# re-read before every run, so a new key applies without a restart.
# Model profiles (agent.py). One local model does everything; another
# profile (a cloud one, say) is only worth adding for a reason. An api_key
# is saved with --set-api-key and re-read before every run.
# {windows_host} is the Windows side of WSL's NAT network, where Ollama
# listens. Replaced whole by config.json, not merged.
"models": {
"cloud": {"model": "anthropic:claude-sonnet-5", "api_key": ""},
# GLM-4.7-Flash (30B MoE, 19 GB) fits the 4090 with room for its cache,
# and uses tool results faithfully (--try-model); qwen3-coder did not.
# Ollama loads it with a 128k window.
"local": {"model": "ollama:hf.co/bartowski/zai-org_GLM-4.7-Flash-GGUF:Q5_K_S",
"base_url": "http://{windows_host}:11434/v1"},
"base_url": "http://{windows_host}:11434/v1",
"context_tokens": 131072},
},
# Which profiles each kind of task tries, best first. Later ones take over
# when the first is unreachable or fails the run. Replaced whole.
# Which profiles each kind of task tries, best first; a later one takes
# over when the first is unreachable or fails the run. Replaced whole.
"routing": {
"operator": ["cloud", "local"],
"alerts": ["local", "cloud"],
"health": ["cloud", "local"],
"upgrade": ["cloud"],
"operator": ["local"],
"alerts": ["local"],
"health": ["local"],
"upgrade": ["local"],
},
# Per run. cost_usd caps metered (Anthropic) runs by kind; local runs are free.
"limits": {
@@ -971,7 +974,7 @@ Write to me in plain language and I act on it. A follow-up within a few hours co
- `hold 45m <why>` — stand down for a while (`hold` alone is 30 min, 8h is the most). Your messages still run and alerts still collect; health checks, triage and upgrades wait
- `resume` — end a hold now
- `new` — forget this room's conversation
- `model` — which models answer what; `model local` or `model cloud` picks one for your messages in this room, `model auto` goes back to the default
- `model` — the model I run on; with more than one configured, `model <name>` picks one for your messages in this room and `model auto` goes back to the default
- `upgrade` — run the weekly upgrade now
- `help` — this message"""
@@ -2352,7 +2355,7 @@ def main():
ap.add_argument("--offline", action="store_true",
help="with --check: skip the SSH and model reachability warnings")
ap.add_argument("--set-api-key", metavar="PROFILE",
help="check and store an API key for a model profile, e.g. cloud")
help="check and store an API key for a model profile that needs one")
ap.add_argument("--try-model", metavar="PROFILE",
help="one request with one tool call to a model profile, then exit")
ap.add_argument("--hold", metavar="DURATION",