--- name: system-zero description: Install and run System Zero (the sr-zero package), a decision model with no learned weights whose every answer names its rule, its record and its file and line, and build, test and maintain the user's own Zero pack from their labelled CSV or JSON lines. Use when the user wants to install, try or serve System Zero or sr-zero, answer routine decisions such as ticket routing, spam, intent or policy checks with readable rules on a CPU, call the System One decision API (POST /v1/systemone) locally, compile labelled data into rules, run the dev gate, add or test override rules, put System Zero in front of their own model with --defer-to, unlearn a data source, or explain an answer. Not for open-domain language understanding or world knowledge, which belong to a neural model. --- # System Zero System Zero is a decision model with no learned weights: rules counted from data plus hand-written modules, in pure Python (3.9 or newer, no dependencies) on one CPU core. It answers System One decision questions (`choice`, `noul` for yes/no, `score`) with a probability for every option, and every answer names its rule, the rule's record in training and its file and line, or says that no rule applied. It is on PyPI as `sr-zero`. Site: https://system-zero.semantic-router.org; the longer guide for agents: https://system-zero.semantic-router.org/llms.txt. A Zero pack is the user's own Zero: a directory of data (`manifest.json`, `rules.jsonl`, `overrides.jsonl`, `tests.jsonl`), compiled from their labelled examples and served in front of the official rules for the questions it claims. The commands below are for bash and zsh (Linux, macOS, WSL). The examples use a pack `support` and the files `data/train.csv` and `data/dev.csv`; use the user's names. ## Guard rails - Keep everything local. System Zero makes no network calls of its own: the network is for installing the package, and for `--defer-to` when the user names their own model's endpoint, which then receives the questions System Zero is not sure of, with their state. Never send the user's data, packs, rules or answers anywhere else: no web searches, issues, chats, uploads or other services. - Keep packs private. `rules.jsonl` holds words and word pairs of the training text and counts by source. Keep packs in the user's own directories and private repositories, and publish one when the user agrees, after reading the identifier warnings of `pack test`. - Serve on 127.0.0.1, the default. `/api/decide` takes no API key. Use `--host 0.0.0.0` or `--explain-packs full` when the user asks for it and knows who can reach the port, and not otherwise. - Quote safely. Single quotes around text and questions; never an exclamation mark inside double quotes, which interactive bash and zsh expand; an apostrophe inside single quotes is `'\''`. Longer or messier text goes into a JSON file (`sr-zero -j FILE`, `curl -d @FILE`). - Never ship a failing pack. A pack whose dev gate fails, whose decision tests fail, or that was never tested on held-out rows is not ready: do not serve it, seal it, commit it as done or hand it over. Never compile the dev rows into the pack they test. - Report what was measured: the numbers of `pack test --dev` with the number of dev questions, and the rule and record behind each answer. Claim nothing beyond them. - Ask before installing uv, a Python or the package, and before writing outside the working directory. Never edit `rules.jsonl` by hand; compile again instead. ## 1. Check that System Zero fits Use it for routine decisions whose evidence is in the input text: ticket routing, spam, intent, a policy check, a triage step. Recommend a neural model instead when the decision needs language understanding or world knowledge (facts, commonsense, what a text implies): words alone do not carry those answers, and System Zero is near chance there. Decisions about people, and other high-stakes uses, need review by a person. ## 2. Detect Python and uv ```sh command -v uv && uv --version command -v python3 && python3 -c 'import sys; print(sys.version.split()[0], sys.version_info >= (3, 9))' ``` - uv found: use step 3a. uv brings a suitable Python when the system's is older than 3.9. - No uv, and the second line ends in `True`: use step 3b. - Neither: ask the user to install uv (`curl -LsSf https://astral.sh/uv/install.sh | sh`, then a new shell), then step 3a. ## 3. Install 3a, with uv: ```sh uv tool install sr-zero sr-zero --version ``` 3b, in a virtual environment (many systems refuse `pip install` outside one): ```sh python3 -m venv ~/.venvs/sr-zero ~/.venvs/sr-zero/bin/python -m pip install sr-zero ~/.venvs/sr-zero/bin/sr-zero --version ``` With 3b, write `~/.venvs/sr-zero/bin/sr-zero` wherever this skill says `sr-zero`. On Debian and Ubuntu, `python3 -m venv` stops with `ensurepip is not available` until the `python3-venv` package is installed: ask the user, or use uv. Check: the version is `sr-zero 0.11.0` or newer; the pack commands need 0.9.2, and `--defer-to` needs 0.11.0. To try one question without installing, `uvx sr-zero` takes the same arguments. ## 4. Verify with one question ```sh sr-zero 'Check out my channel and subscribe' -q 'Is this comment spam?' --yes-no ``` ```text > yes 0.90 ###################### no 0.10 ## why: if the state contains "my channel", answer true (37 of 37 right in training) system_zero/rules/options.py:2324 · 353 µs · 0 parameters ``` Check: exit status 0, a pick with its probability, and a `why:` line that cites `system_zero/rules/FILE.py:LINE`. How to read it: - The probability is the lower end of the 95% interval of the rule's record, so a rule seen a few times stays unsure; it reaches 0.9 only on a record that three or more families of training questions back. `true` is the yes of a yes/no question. - `37 of 37 right in training` is the record: the rule fired on 37 training questions and was right on all 37. - `no rule applies, so every option is equally likely` (by chance) and `no rule fired, so the answer most often right in training` (by the prior) mean that nothing in the text decided: report the answer as unknown. - Other forms: `-o A B C` for a choice, `--levels LOW MID HIGH` for a score, `--raw` for the JSON answer with its `explanation`, and `-j requests.jsonl -e` for one `{"state", "questions"}` request per line. ## 5. Serve and test over HTTP ```sh nohup sr-zero serve --port 8000 > sr-zero-serve.log 2>&1 & echo $! > sr-zero-serve.pid for i in $(seq 30); do curl -sf http://localhost:8000/health && break; sleep 1; done ``` Check: `{"api_version":"5.0.0","status":"ready","reason":null,"model":"system-zero"}`. If nothing comes, read `sr-zero-serve.log`. Then one question, and the same with its explanation: ```sh curl -s -w '\n' http://localhost:8000/v1/systemone \ -H 'Content-Type: application/json' \ -d '{"state": "Check out my channel and subscribe", "questions": {"spam": {"type": "noul", "instructions": "Is this comment spam?"}}}' curl -s -w '\n' http://localhost:8000/api/decide \ -H 'Content-Type: application/json' \ -d '{"state": "Check out my channel and subscribe", "questions": {"spam": {"type": "noul", "instructions": "Is this comment spam?"}}}' ``` Check: the answer has `"noul":0.8999059390425449`, and from `/api/decide` an `explanation` with `rule`, `right`, `fired`, `file` and `line`. A `choice` question gives `criteria` as 2 to 255 options (key and description) and is answered with `choice` and every option's `probabilities`; a `score` gives 2 to 10 levels, from lowest to highest. Stop the server when done: ```sh kill "$(cat sr-zero-serve.pid)" ``` ## 6. Build the user's pack Start with the data. A CSV needs a header with `text` and `label`; optional columns are `source` (a channel, customer or dataset: the unit that can be removed later), `group` (near-copies such as one thread or template, kept together when records are counted on held-out rows), `split` (`dev` and `test` rows are left out of the compile), `licence` and `id`. System One JSON lines are `{"state", "questions", "expected"}` rows, `true` or `false` for a `noul`, with optional `source`, `meta.licence` and `meta.group`. Check: at least 30 labelled rows per question (a few hundred are better), each label spelled one way, no rows from a benchmark or test set the user reports on. If there is no dev set, split one row in five off a copy, by `group` when there is one. The original `data/all.csv` stays as it is: ```sh python3 - <<'EOF' import csv, hashlib with open('data/all.csv', newline='', encoding='utf-8-sig') as f: reader = csv.DictReader(f) rows, columns = list(reader), reader.fieldnames names = {c.strip().lower(): c for c in columns} key = names.get('group') or names['text'] for path, dev in (('data/train.csv', False), ('data/dev.csv', True)): with open(path, 'w', newline='', encoding='utf-8') as f: out = csv.DictWriter(f, fieldnames=columns) out.writeheader() out.writerows(r for r in rows if (int(hashlib.sha256(r[key].encode()).hexdigest(), 16) % 5 == 0) == dev) EOF wc -l data/train.csv data/dev.csv ``` Create the pack, compile it, and ask it something: ```sh sr-zero pack init support --question 'Which team should handle this ticket?' sr-zero pack compile data/train.csv -o support sr-zero pack explain support 'I was charged twice for my plan this month' ``` Check the compile output: `read N rows`, a line with the user's labels and its rule count, `wrote support/rules.jsonl and manifest.json`. `not learned: ... (fewer than --min-count)` means too few rows. The explanation cites a line of `support/rules.jsonl` and splits its record by source (`by source: email 64 of 98, web 68 of 92`). A pack compiled from JSON lines needs its question named: `sr-zero pack explain PACK 'TEXT' -q 'QUESTION' --yes-no` (or `-o A B C`). ## 7. Run the dev gate, and decide ```sh sr-zero pack test support --dev data/dev.csv ``` The lines that decide (from a 600-ticket example): ```text dev: 180 questions accuracy 51.7% (the official rules alone: 20.6%) threshold none: no threshold's answers reach the target on dev with enough answered; defer everything, or improve the pack gate: passed (180 questions the pack answers: pack 51.7%, official alone 20.6%; 56 won, 0 lost, sign test p < 0.0001) ``` The gate compares the pack with the official rules alone on the dev questions the pack claims, and fails when the official rules are right more often where the two disagree. The threshold is the lowest probability whose answers reach the target, a 90% lower bound (`--target`), with at least 30 answered. `test` exits 1 when the gate or a decision test fails, 2 when the pack cannot be loaded. | Result | Do | |---|---| | `gate: FAILED` | Refuse to ship: do not serve, seal or hand over the pack. Tell the user the official rules alone do better on these questions; fix labels, add data, or drop the pack. | | `gate: passed (0 questions the pack answers ...)` | Not a pass: the dev rows do not ask the pack's question. A yes/no or two-option pack answers its own question wording alone. | | `gate: passed` with a threshold | Ship it with that threshold: seal it and serve the pack in front of the user's model with `--defer-to` (step 9), or let the caller accept an answer when its top probability (`probabilities[choice]`, or the larger of `noul` and `1 - noul`) reaches it and its `by` is not `prior` or `chance`, and defer the rest. | | `gate: passed`, threshold `none` | Better than the official rules, not sure enough to decide alone at the target: a suggestion at most, every decision deferred. Improve it with more varied examples and overrides; a lower `--target` finds a threshold only if the user accepts that accuracy. | | Fewer than 100 dev questions, or sign test p of 0.05 or more | Weak evidence: say so, and ask for more dev data. | ## 8. Add an override rule and test it For a known policy or a wrong answer, add one line to `support/overrides.jsonl`: ```json {"id": "chargebacks", "when": {"any": ["chargeback", "disputed the charge"]}, "answer": "billing", "note": "Payment disputes go to billing, whatever else the ticket says."} ``` and to `support/tests.jsonl` at least one example it fires on, cases it must leave alone, and a decision test: ```json {"rule": "chargebacks", "state": "My bank shows a chargeback from you.", "fires": true} {"rule": "chargebacks", "state": "I disputed the charge with my card company.", "fires": true} {"rule": "chargebacks", "state": "Can I charge my phone with the dock?", "fires": false} {"state": "My bank shows a chargeback from you, and the parcel never arrived", "expect": "billing"} ``` Phrases match whole words in order, in any letter case (`charge` does not match `charged`); `when` takes `any`, `all` and `none`; `answer` is one of the pack's options; there are no regular expressions. An override decides before the counted rules, with the lower bound of its record on its examples as its probability (2 examples give 0.34, 20 give 0.84). Test it, and seal it: ```sh sr-zero pack explain support 'My bank shows a chargeback from you' sr-zero pack test support --dev data/dev.csv --seal ``` Check: the explanation cites `support/overrides.jsonl:1`; the test prints `overrides: 1 rule(s), 3 example(s), all as they should be`, `decision tests: 1 of 1 pass`, the gate, and `sealed: manifest.json records the hashes of the files that passed` (with `--dev`, sealing needs the gate too). A rule without a firing example, or an example that does not hold, refuses the pack with one line naming the file and line. Serve the pack as in step 5, and ask its question as `questions.decision` in `support/manifest.json` writes it: ```sh nohup sr-zero serve --pack support --port 8000 > sr-zero-serve.log 2>&1 & echo $! > sr-zero-serve.pid for i in $(seq 30); do curl -sf -o /dev/null http://localhost:8000/health && break; sleep 1; done curl -s -w '\n' http://localhost:8000/v1/systemone \ -H 'Content-Type: application/json' \ -d '{"state": "My bank shows a chargeback from you", "questions": {"team": {"type": "choice", "instructions": "Which team should handle this ticket?", "criteria": {"account": "account", "billing": "billing", "returns": "returns", "sales": "sales", "shipping": "shipping", "technical": "technical"}}}}' kill "$(cat sr-zero-serve.pid)" ``` Check: `"choice":"billing"`, and `sr-zero-serve.log` shows `packs: support 0.1.0`. `serve` refuses to start when a decision test fails on the stack it assembled. Every question the pack does not claim gets the official answer, unchanged. Over HTTP, pack explanations keep the file, line and record and leave out the rule's words, notes and sources. ## 9. Put the pack in front of the user's model With `--defer-to URL`, `sr-zero serve` keeps what System Zero is sure of and sends the other questions, with the request's state, to any System One endpoint: the user's own neural model. A question stays when an override decided it, or a rule answered it at or above the threshold; an answer from the prior or by chance always goes. Ask the user for their model's endpoint first, and use no other; the commands below use `http://127.0.0.1:8001`. Seal a threshold at a target the user accepts (here a 75% lower bound), serve, and ask about a ticket the pack is unsure of: ```sh sr-zero pack test support --dev data/dev.csv --target 0.75 --seal nohup sr-zero serve --pack support --defer-to http://127.0.0.1:8001 --port 8000 > sr-zero-serve.log 2>&1 & echo $! > sr-zero-serve.pid for i in $(seq 30); do curl -sf -o /dev/null http://localhost:8000/health && break; sleep 1; done curl -s -w '\n' http://localhost:8000/api/decide \ -H 'Content-Type: application/json' \ -d '{"state": "The login page keeps spinning and never loads", "questions": {"team": {"type": "choice", "instructions": "Which team should handle this ticket?", "criteria": {"account": "account", "billing": "billing", "returns": "returns", "sales": "sales", "shipping": "shipping", "technical": "technical"}}}}' kill "$(cat sr-zero-serve.pid)" ``` Check, for the 600-ticket example: the test prints `threshold 0.625: answers 33.9% (61) at 88.5%, Wilson lower bound 78.2% >= target`, and the sealing line goes on `and the threshold 0.625, which serve --defer-to uses unless --threshold is given`; `sr-zero-serve.log` shows a `defer:` line naming the threshold and `http://127.0.0.1:8001/v1/systemone`; the answer's `explanation` has `"by":"deferred"` and `deferred: the top probability here, 0.447, is below the threshold 0.625`, with System Zero's own answer under `local`. A ticket the pack is sure of is answered here and sends nothing. If the endpoint fails or does not answer within `--defer-timeout` (10 seconds by default), the question keeps System Zero's answer with a `deferral` error, the request still succeeds, and the log says `cannot reach it`. `--threshold T` sets the threshold by hand (`yes=0.95,no=0.99` gives one per answer); `SYSTEM_ZERO_DEFER_KEY`, if set, is sent to the endpoint as its key, and nowhere else. To check the wiring before the user's model is connected, a second System Zero can stand in for it: `sr-zero pack compile data/train.csv -o model --question 'Which team should handle this ticket?' --no-evidence`, then `sr-zero serve --pack model --port 8001`. ## 10. Unlearn a source ```sh sr-zero pack unlearn support --source email --dry-run sr-zero pack unlearn support --source email data/train.csv -o support-no-email sr-zero pack test support-no-email --dev data/dev.csv ``` Check: `removed N rows of email; rebuilt support-no-email ...` and `its rules.jsonl is the one a compile of the remaining rows gives, byte for byte; manifest.json records the removal`. `unlearn` needs the data the pack was compiled from and keeps the overrides and tests. Run the gate on the new pack before it replaces the old one, and tell the user that their own data files still hold the removed rows. ## 11. Report results Give each answer with its reason, so the user can check it: - One answer: the pick, its probability, the rule in its own words, its record and its citation. For example: billing, 0.63, by the evidence of the ticket's words ("i was", "month", "was charged"), right on 132 of 190 training questions, `support/rules.jsonl:454`, email 64 of 98 and web 68 of 92. - No rule: say "System Zero has no rule for this" and recommend deferring, rather than reporting the pick. - A deferred answer (`"by": "deferred"`): say that the user's model answered it, and give System Zero's own answer from `local` with the reason in `rule`. - A pack: its name, version and identity; the dev size; accuracy against the official rules alone; the gate line with won, lost and p; the threshold and its coverage, or `none`; the warnings. Say which decisions it may make alone and which go to a person or a neural model. ## 12. When to recommend a neural model - The question needs language understanding or world knowledge. - The answer is by `chance` or the `prior`: no rule applied. - The top probability is below the pack's threshold, or the pack has no threshold. With `--defer-to` (step 9) these questions go to the user's model on their own. - The traffic no longer looks like the dev set: under distribution shift some decisions are confidently wrong, so run the gate on fresh dev rows. - Images, `box` questions or spans: System Zero reads text alone. ## Troubleshooting - Python older than 3.9: pip finds no matching distribution. Use uv, or `uv tool install --python 3.12 sr-zero`. - `sr-zero: command not found` after `uv tool install`: run `uv tool update-shell` and open a new shell. - `externally-managed-environment` from pip: use uv, or step 3b. `ensurepip is not available`: install `python3-venv` with the user's OK, or use uv. - The download: uv fetches the package, and a Python when none fits; behind a proxy, set `HTTPS_PROXY`. After that, System Zero needs no network. `uvx sr-zero@latest` picks up a new release. - `zsh: no matches found`: a `?` or `*` was left unquoted. `event not found`: an exclamation mark inside double quotes. - `the port is in use`: stop the other server or pick another `--port`. - `has no question decision`: a JSON-lines pack; give `-q` with `--yes-no` or `-o`. - `--defer-to ...: cannot reach it` in the server log: the endpoint is down or its URL is wrong; those questions kept System Zero's answers, marked `deferral`. - A pack compiled by an older System Zero that reads text differently is refused: compile it again from its data.