A `continue` assessment re-dispatches the next step onto the queue rather than running it inline, so a multi-step request only finishes when a front end drains `Scheduler.run_queue()` -- as the CLI and gateway already do. The dashboard ran only the first step and left the child stranded in the queue, so a compound request looked finished when it was not. - `DashboardHandler._complete` runs the returned reply through `_drain_chain` and returns the last reply (intermediate steps are hidden at `result` verbosity); `/api/submit` and `/api/answer` use it. - `/api/answer` now also returns `request_id` (`SchedulerReply.run_id`) so a front end can cross-link the resumed run. - `test_submit_completes_a_multi_step_chain` drives a deterministic two-step chain and asserts both steps ran, the reply is the final step, nothing is left in the queue, and the runs are linked.
semif-agent
A self-hosted agent whose entire control flow is one decision model. You ask it to do something in plain language ("check my email", "message Sam on SimpleX", "put lunch with Dana on my calendar") and it either chooses and executes a known skill in seconds or learns a new one in minutes.
The routing, gating, scoring, assessment and fidelity decisions are all made by SemIf — a small local model that reads option logits directly from a single forward pass. An LLM is used only to generate what cannot be achieved deterministically or through classification - for example, a skill's title, description, or code body. There are no simulated successes with mocked data and fake endpoint. There is chain-of-thought infodump to give the illusion of confidence in a failed outcome. There is just a decision tree leading to reusable code snippets, plugged into a deliberately planned infrastructure of basic services. If intelligence is "on tap," then semif-agent is the catchment system.
A successful release of this could be defined by a single question: "Can I use this for most of the things I use my phone for besides scrolling?" The idea of using a single chat interface operating on minimal back-end resources to replace the diversity of features currently accomplished by a smartphone is audacious for sure. Many have tried and failed. But as technology progresses, it is always worth revisiting old problems with fresh eyes, and we are confident that the end result will be something that a substantial base of end users would enjoy.
Table of contents
- Why this exists (the reasoning)
- How it works
- Features
- Repository layout
- Installation
- Running the agent
- Skills in detail
- Testing
- Roadmap / status
Why this exists
The design premise is that language models are good at generating text and bad at being a reliable control plane. Repeatedly asking an LLM "should I interrupt this process? how urgent is this? which skill handles this?" produces slow, non-deterministic, un-loggable behavior. So control flow is pulled out of the model entirely:
- Semantic ifs, not text generation. SemIf is a local rebuild of Jev's interface pattern. One forward pass reads typed option logits directly from a model; it returns per-option probabilities conditional on exactly the option set you supplied. There is no answer sentence and no decoding loop. It is fast (~0.9 s/decision on CPU), deterministic, cheap, and — crucially — loggable. Probabilities are conditional on the option set, not absolute confidence, so the agent treats them as conditional scores and calibrates per workload.
- Local by construction. The target is a desktop machine; data stays in-network. The decision model is pinned to an exact revision, so every swap is auditable via prompt hashes.
- The decision engine is always real. There is no mock engine and no degraded mode. If SemIf cannot be loaded, the app reports it and exits non-zero rather than pretending. (Pure unit tests may use a scripted double; the runtime never does.)
- Simulated Agile patterns. A skill is a real integration into the active tool chain for end user satisfaction. It takes existing mail protocols, SimpleX, CalDAV/WebDAV, configured local CLIs, HTTP APIs and your supplied data to produce actions that best fit your query. In the absence of a an existing skill, the skill generation process is activated. Skill generation has four major phases - definition, refinement, coding, testing (unit and integration). Each step in this process has deterministic and probabilistic handling optimized to achieve the stated goal of the user in the context of the platform's core mission.
- Nothing is gated out up front. Every input is dispatched.
Inputs that are not requests fall through navigation into the closed
responsecategory — a hardcoded tree of canned replies (greeting,thanks,acknowledge,farewell,affirm, and the catchallclarify). A request no skill covers is not a canned reply: the actionability guard (navigate:actionability) sends it to skill authoring instead, soresponseis reached only when the input asks for nothing.responsenever goes through codegen and its runs are never assessed (a canned line has no side effect to succeed or fail). It never offers generated text. By design, you will never be having a "conversation" with an LLM through this platform. - Everything is a training row. Every SemIf decision is logged as a labeled
row; the
dreampass computes the prediction-vs-observation cost (cross-entropy / NLL + ECE) that later drives fine-tuning. This means that the platform should improve with use, much like SOTA agentic harnesses, but through reinforcement learning and procedurally generated context augmentations (as opposed to markdown files that grow, compress, and prune their way through a meandering and inherently context-limited self-improvement loop).
How it works
The scheduler: queue and dispatch
Implemented in semif_agent/scheduler.py and semif_agent/queue.py:
intake (typed input / messenger gateway / scripted)
├─ idle → dispatch immediately
└─ busy → FIFO queue (arrival order, no priority)
- The queue is a strict first-in-first-out list of pending requests with a
maximum depth (
queue.py). There is no urgency scoring and no preemption. - A skill run paused for input (
needs_input) keeps the current slot busy; an answer routes straight back to the pending run, bypassing the queue and navigation. - The running process always finishes before the next queued request is dispatched.
- Exactly one execution slot. (Concurrency, when it comes, is SemIf's shared-state mode for parallel decisions — not parallel process execution.)
The skill tree and navigation
Skills are leaves: categories → skills → actions. Navigation is a chain of SemIf
choices, one per level (navigate in semif_agent/skills.py), and every
choice is logged (navigate:category, navigate:leaf, navigate:response).
- Two-stage at both levels; the guards are the create doors.
- Category. The softmax offers every existing category with its
description plus a
create_categorybranch, and the winner is confirmed by the scope guard (confirm_category_fit, phasenavigate:category_scope): a name-anchored SemIf check atnavigation.category_tauasking whether that category's scope covers the request. Confirmed → descend; rejected (or acreate_categorywin) → author a new category. Descriptions are load-bearing: with bare names the model sent "book a flight to japan" tosimplex(0.49 vscreate_category0.12); with descriptions it pickscreate_category0.87. An empty tree short-circuits straight to create. - Leaf. The leaf softmax picks only among the existing skills (a create
option diluted its probability and let a crowded tree drift into create on a
weak plurality). The picked skill then goes through the intent guard
(
confirm_skill_fit, phasenavigate:intent): atnavigation.intent_tauit decides what the skill does for the request, given the steps already taken (the run ledger is part of its state).same(it performs the next action the request needs) orpart(the request needs more than one action and this skill performs one required part) → run it;different(it does no action the request asks for) → author a new leaf in that category. The guard only decides whether the skill contributes; whether more work remains isassess:outcome's call. An empty (or single-skill) category skips the softmax and goes straight to the guard. - Both guards are deliberately permissive; with real descriptions the in-scope cases score 0.9–1.0, so a borderline over-cover routes into a plausible category and the leaf guard catches it.
The skill run loop
Every skill (semif_agent/skill.py) follows the same loop:
observe baseline → act → observe outcome → assess
act(ctx, request)is the single body phase. It reads resolved values fromctx.configand performs the real action via stdlib transports, returning anActionResult(action_log, new_state, needs_input, decisions). Any SemIf sub-decisions it makes (e.g. which contact is "girlfriend", resolved over a live candidate set) are returned onActionResult.decisionsand logged as training rows with the run outcome.assessis a SemIf decision, not generation:assess:outcome— is there any additional work to satisfy the request? Three outcomes at threshold precedencefailed > done > continue:done(request satisfied),continue(this step worked but more work is needed → the scheduler routes the logical next step with a bounded run ledger),failed(the step errored → the repair path). Its state includes the skill action, the goal, the resolved inputs (secrets redacted), the bounded action log, and the steps already taken.
- The run summary is deterministic (same inputs ⇒ same string):
f"{category}.{name}: {'ok'|'failed'} — {action_log or new_state}". - Every skill's output is bounded to one speakable budget (
chain.result_chars, ~300 chars): the result string and its run-ledger entry. A long product belongs in a file I/O side effect, not the result (seeCODEGEN.md). - A skill can pause for human input two ways:
actreturnsneeds_input(act re-runs on resume, withrequest.user_inputset), or — for a contract variable the runner cannot satisfy — a pre-act pause collects config before act runs.
Authoring a new skill
When navigation chooses a create branch, the scheduler queues the draft to a
single-slot llm worker and the body write to a separate single-slot codegen
worker. It is asynchronous, so the gate stays free while either model thinks:
- Spec. The small
llmprovider (generate_skill_spec) authors a title + description and a de-identified, reusable goal (plus the generic service/transport) on its own worker. The stub is registered and hot-merged into the running tree as soon as it lands; askill_writingtrace event is emitted. The goal is the only task data codegen is ever shown. - Codegen body (
generate_skill_body): a larger OpenAI-compatible model (codegen, your configured code-capable model) writes a singleactagainstCODEGEN.md, reading every operational value fromctx.configand declaringINTEGRATION(service / transport / config_vars) plus its own flatCONTRACT(variable → description; every key must be read fromctx.config). Privacy: codegen is the primarily-cloud model, so it receives only the de-identified spec — never the user's request, question answers, or run output. - Fidelity gate (
authoring:fidelitySemIf accept/reconsider decision + staticintegration_findings): does the body contain a concrete, side-effecting operation that really performs its goal? The state carries the whole body (never a prefix) plus a deterministic operation inventory and the de-identified goal — never the raw request — and asks the positive question rather than asking the model to prove a negative. Because a decision ingests the body whole, generated artifacts are size-bounded (max_body_chars/max_test_chars, derived from the engine's context). One corrective regen with the de-identified evidence bundle (inventory + findings included), then accept with a trace rather than hard-fail. - Contract (
parse_contract): read from the body's ownCONTRACTconstant — a flat map of snake_case variable name → semantic description, for user input and SemIf only;contract.jsonis a persisted mirror. - Test (
generate_skill_tests): a shared-context call producesskill.test.py, a hermetic mechanics test (inline fixtures, a loopbackhttp.serverfor HTTP bodies, no external network). - Auto-run (
run_skill_test): executes the test as a subprocess. On failure a 2-option SemIf decision (codegen_regen) picks code/test to regenerate (the contract rides in the code), bounded bycodegen.test_max_attempts.
On success the body materializes to data/skills/<category>/<name>/, is
hot-merged, and the original request is re-queued and re-runs navigation
onto the new leaf. On failure the leaf stays a restartable stub. A whole new
category runs the same chain deterministically:
create_category → create_skill → async body → re-dispatch.
A rejected/simulated body is traced (fidelity_review) and never blocks
authoring. Codegen failures (including timeouts) surface as a graceful stub and
are retryable with restart <category> <skill>.
What each model sees
Two kinds of model calls exist, and they are injected with different things.
A SemIf decision carries only three fields — state, question, and
options (each with an id + description) — and
semif_phase1.llamacpp_backend.score reads the option logits from that one
forward pass. There is no hidden system prompt and no growing conversation:
what you see in the table below is the entire input. Probabilities are
conditional on exactly the supplied options.
A generative call (llm for titles/descriptions/goals, codegen for bodies
and tests) is a built OpenAI-style messages list. The trusted local llm
context is assembled from the request and the tree; the codegen context is
assembled only from the de-identified spec (goal + generic service/transport),
the tree, the runtime bridge catalog (describe_bridges()), and — for bodies
and tests — the contract files (CODEGEN.md, TESTGEN.md). Codegen never
receives the user's request, question answers, or run output.
SemIf decisions
| Phase | File | State injected | Options |
|---|---|---|---|
navigate:category |
skills.py:682 |
request text | every category name (+ create_category) |
navigate:leaf |
skills.py:736 |
request text + current category | every skill name + description (+ create_skill) |
navigate:response |
skills.py:634 |
request text + category | canned reply names + descriptions (catchall last) |
navigate:intent |
skills.py:811 |
Requested action: <text> + Action of the existing skill: <description> |
same / different |
assess:outcome |
skill.py:311 |
skill label + goal + resolved inputs + bounded action log + steps already taken | done / continue / failed |
config:search |
scheduler.py:1477 |
skill + variable name + its semantic description | each candidate config key (+ ask) |
config:record |
skill.py:112 |
skill + variable = value |
record / ask_again |
authoring:fidelity |
scheduler.py:1836 |
skill, goal, description, INTEGRATION JSON, static findings, operation inventory, whole body (no raw request) |
accept / reconsider |
repair:choice |
scheduler.py:658 |
skill, request, integration, truncated failure | retry / repair_skill / ask_user / no_repair |
| degeneration watchdog¹ | cli.py:128 |
[codegen <model>] + last 2000 chars of the stream |
continue / stop |
codegen_regen¹ |
cli.py:165 |
[testgen <model>] + last 1200 chars of the test error |
regen_code / regen_test / regen_contract |
¹ Trace-only: logged to runs.jsonl, never to decisions.jsonl.
Generative calls
| Call | Client | System context | User context | File |
|---|---|---|---|---|
generate_category |
llm |
authoring instruction: propose one broad category, JSON-only | request text + full tree summary | skills.py:896 |
generate_skill_spec |
llm |
authoring instruction: propose one specific skill + a de-identified goal and generic service/transport, JSON-only | request + category + existing skill names | skills.py:947 |
generate_skill_body |
codegen |
full CODEGEN.md | de-identified spec (goal + description), category, name, existing skills + tree summary, integration hint, bridge catalog, BODY_DIRECTIVES |
codegen.py:156 |
| body retry | codegen |
full CODEGEN.md | rejection reason, de-identified spec (goal + description), integration hint, bridge catalog, BODY_DIRECTIVES |
codegen.py:474 |
generate_skill_tests |
codegen |
full TESTGEN.md | skill, de-identified goal, full body code, bridge catalog; continued with the accepted contract JSON as an assistant turn + the test-gen ask | codegen.py:942 |
regenerate_skill_body |
codegen |
full CODEGEN.md | correction header, de-identified goal + description, de-identified evidence bundle (rendered verbatim), previous body, integration hint, bridge catalog, BODY_DIRECTIVES |
codegen.py:1046 |
The bridge catalog is describe_bridges() (bridges/registry.py:33): each
known bridge's name, service, description, base-URL config var, auth header +
token var, documented config vars, and endpoints. It is the single runtime
source of bridge specifics — CODEGEN.md and TESTGEN.md carry only the generic
pattern — so a bridge can be added without touching either contract file.
The evidence bundle handed to a corrective regen is de-identified: a generic failure kind, the integration, the goal, and the previous body, rendered as-is with no prose diagnosis. It carries no request text and no run output.
Data contracts and tiered config
Generated bodies own no data. At runtime the runner merges:
global config → category config → skill config → per-fire answers = ctx.config
- After the contract lands, a SemIf
choiceper variable auto-populates the skill config from the whole cascade (global → category → skill config) (config:search). - Variables still unresolved pause the run before act and are asked of the human one at a time.
- Each answer gets a SemIf
record-as-config vs ask-again-each-firechoice (config:record); recorded values persist to the skillconfig.json. - On successive firings only the unresolved variables are asked.
A finished skill folder is:
data/skills/<category>/<name>/
skill.py # runnable body
skill.test.py # hermetic mechanics test
contract.json # variable name -> semantic description
config.json # recorded values (secrets live here, gitignored)
Each body also records the CODEGEN.md revision it was written against
(contract_ref / contract_dirty on the skill_writing trace).
Repairing a failed run
A failed real run logs a SemIf repair:choice decision offering:
retry | repair_skill | ask_user | no_repair
It is surfaced as a repair_offered trace, in the REPL (repairs,
repair <id> [action]) and in the dashboard. Executing is user-confirmed
(a codegen write is slow): retry re-queues, repair_skill rewrites the body
with the observed failure (bounded by codegen.repair.max_attempts), and
ask_user posts a repair question. A run is never silently auto-repaired.
Dream: the learning signal
semif_agent/dream.py replays decisions.jsonl and computes, per row, the NLL
of the observed outcome under the predicted distribution, plus weighted
cross-entropy, accuracy and binned ECE. Human relabels (relabel, or
POST /api/relabel) are weighted 3×. This is the training signal for the v2
fine-tuning loop — it is not yet the fine-tune itself.
Features
- SemIf-only decisions — choice, scoring, navigation, assessment, fidelity, config search/record, repair choice, regeneration choice, and a codegen degeneration watchdog all route through one local decision model.
- No handle/ignore gate — every input is dispatched; non-tasks fall through
to the closed
responsecanned tree. - Real integrations by construction — bodies must perform the real action,
read data from
ctx.config, declareINTEGRATION, and report real failures. - Async skill authoring — spec → body → fidelity → contract → test → auto-run, with a SemIf regeneration ladder on test failure. Gate stays free.
- Tiered config + first-fire collection — global/category/skill config with
a
record-vs-askdecision per answer. - Runtime repair loop — retry / repair / ask / no-op, user-confirmed.
- Decision logging + dream cost — every decision is a labeled training row with prompt hashes, tokens and timing.
- Run lifecycle tracing —
runs.jsonlkeyed byrun_id, powering a Redux-DevTools-style dashboard. - Messenger command gateway (SimpleX + LXMF) — take commands and reply over DM.
- Voice gateway — a local microphone front end: wake word + speech-to-text + text-to-speech, all local (openWakeWord / faster-whisper / Piper).
- Standalone bridge services — a token-guarded localhost HTTP layer in front of third-party systems, so generated bodies never speak native protocols.
- Seeds — shipped real starter skills:
nextcloud.create_event(the authoritative worked example),nextcloud.next_event(Nextcloud CalDAV),nextcloud.create_task(Nextcloud task list),simplex.next_message/simplex.send_message/simplex.connect_link, andcalculator.calculate(two operands, one SemIf-chosen operator, spoken answer). - Fatal-on-engine-loss — the engine is always real; its absence exits the app.
- Stdlib-only core — SemIf/llama.cpp are lazy imports, so the package stays importable and testable without the heavy engine installed.
Repository layout
semif_agent/
cli.py argparse: run / dream / skills / status / relabel /
dashboard / gateway / bridge
scheduler.py no up-front gate; FIFO queue -> dispatch;
needs_input pauses; async single-slot
skill authoring worker; fidelity gate; repair loop
skill.py observe -> act -> observe -> assess; deterministic
summary; pre-act contract collection; resolved-input state
skills.py tree + registry, canned `response` tree, navigation,
create gates, intent guard, tiered config resolution
codegen.py OpenAI-compatible client; body/test generation;
parse/validate; CONTRACT + INTEGRATION extraction; test runner
provider.py shared OpenAI-compatible transport (SSE/budget/idle/watchdog);
SemIfEngineClient generates text from the in-process engine
engine.py SemIfEngine -> semif_phase1.llamacpp_backend (lazy import);
call() scores, generate() samples text
llm.py small provider; authors new title + description
(ollama / opencode / the loaded engine via `semif`)
log.py decisions.jsonl rows {state, question, options, probs, ...}
trace.py runs.jsonl lifecycle events keyed by run_id
dream.py NLL / weighted CE / accuracy / ECE cost report
decisions.py DecisionRequest / Option / DecisionResult / Request dataclasses
queue.py bounded FIFO request queue
dashboard.py stdlib HTTP + JSON API + static UI
static/ dashboard frontend (html/js/css)
simplex_ws.py neutral SimpleX daemon protocol (shared by gateway + bridge)
voice_transport.py neutral voice transport: mic capture, wake word, VAD,
speech-to-text (faster-whisper), text-to-speech (Piper)
gateway/ messenger COMMAND intake/reply (SimpleX, LXMF, voice)
bridges/ standalone third-party API bridges (SimpleX, LLM, Nextcloud)
seeds/ committed starter skills (nextcloud, simplex)
scripts/ bootstrap.sh, simplex-address.py, systemd/*.in
requirements/ staging.txt — the pinned engine deps
tests/ stdlib unit tests + tests/integration (real engine + LLM)
CODEGEN.md the contract fed to the skill-body codegen model
TESTGEN.md the contract fed to the test/contract codegen model
AGENTS.md the operational guide (read this before touching code)
config.example.json per-machine config template (seeded to config.json once)
pins.json committed pins: engine/GGUF/tokenizer/simplex-chat refs
local/ gitignored: this deployment's notes (hosts, addresses, models)
Installation
The agent runs anywhere pure-Python runs, but a working agent needs the SemIf
decision engine, a pinned GGUF, and an OpenAI-compatible endpoint for codegen.
scripts/bootstrap.sh provisions all of it inside a gitignored .runtime/ tree
in the checkout.
Prerequisites: ollama models
Two OpenAI-compatible endpoints (usually ollama), which may be on different machines:
codegen— a large, code-capable model that writes skill bodies. This is slow and ideally on a beefier host.llm— a small, fast model that authors the title + description of a newly created category/skill. Deliberately its own endpoint/model, so it can stay local even whencodegenis remote; it uses the same provider transport (provider.py) and an unreachable endpoint is graceful (the request is not re-dispatched), never fatal. Itsprovidercan be"ollama"(default),"opencode"(the hosted Console API), or"semif"— the already-loaded decision engine model generates in-process, with no endpoint and nollm.modelat all (see thellm.semifblock inconfig.json).
The decision engine is separate and runs via llama.cpp, not ollama. It is CPU
by default; to offload it to a GPU, set engine.gpu_layers in config.json and
run scripts/bootstrap.sh --gpu vulkan|rocm|cuda (a GPU build is opt-in because
it is slower on CPU).
Option A: one-command provisioning (bootstrap.sh)
On a fresh Ubuntu machine, from a checkout of this repo:
scripts/bootstrap.sh
With no config.json yet, the script seeds one from config.example.json; edit
it to set llm.model/codegen.model (and the endpoints). Flags override those
values for the run only — --llm-url, --codegen-url, --llm-model,
--codegen-model — and are never written back to config.json.
The script is idempotent (every stage no-ops on existing state) and:
- installs system prereqs + enables linger;
- generates/uses
~/.ssh/id_ed25519and clones + pins the SemIf engine; - creates
.runtime/venvand installs the pinned deps fromrequirements/staging.txt(installingsemif-phase1with--no-deps, since the llama.cpp path never imports torch); - downloads and sha256-verifies the pinned GGUF into
.runtime/models/; - pre-fetches the HF tokenizer into
.runtime/hf/; - downloads and sha256-verifies the pinned
simplex-chatbinary; - seeds
config.jsonfromconfig.example.jsononly if it does not already exist — it never rewritesconfig.json(only a human edits that file); - renders and enables systemd user units:
semif-simplex(bot daemon),semif-gateway(agent gateway),semif-simplex-forward(the bridge's own daemon),semif-bridge; - prints the bot's SimpleX contact address.
Flags (--llm-url, --codegen-url, --llm-model, --codegen-model,
--copy-data SRC) override the values read from config.json for that run only.
--voice additionally installs the optional voice-gateway stack
(requirements/voice.txt + system PortAudio) and downloads its models (the
openWakeWord models into the venv under .runtime/venv, the Piper voice into
.runtime/voice/tts, the faster-whisper model into the .runtime/hf cache).
Run scripts/bootstrap.sh -h for the full list.
It installs no ollama; it expects one for llm and pulls llm.model,
warning (never auto-pulling) if the remote codegen host is missing its model.
Pinned external refs (engine commit, GGUF url+sha256, HF tokenizer revision,
simplex-chat version/url+sha256) live in the committed pins.json, not in
config.json.
Option B: core only (stdlib)
The core is dependency-free, so unit tests run anywhere:
python3 -m pytest tests/ -q --ignore=tests/integration
For a full install on a machine you manage, follow the same steps bootstrap
performs (venv, semif-phase1 --no-deps, requirements/staging.txt, GGUF,
tokenizer cache), then create config.json from the template and adjust paths:
cp config.example.json config.json
Configuration
config.json is gitignored, per-machine, and required — the agent refuses
to start without it. scripts/bootstrap.sh seeds it from config.example.json
once; afterwards only a human edits it (nothing writes config.json). Pinned
external refs live in the committed pins.json, so config.json holds only
per-machine settings:
cp config.example.json config.json # if not already created by bootstrap
Key blocks:
| Block | What it controls |
|---|---|
engine |
per-machine engine settings: backend, context, threads, optional GGUF path override (refs come from pins.json) |
llm |
small model endpoint that authors new category/skill title + description |
codegen |
skill-body model endpoint, timeouts, sampler, approval gate, fidelity, repair, test, degeneration watchdog, token budget |
navigation |
two-stage guards: leaf intent_tau, category category_tau |
tau |
decision threshold; max_reentries requeue bound |
queue |
max_size |
skill_bodies / skill_seeds / log / trace / category_registry |
runtime paths (anchored to the checkout) |
gateway.simplex |
command gateway: ws_url, allowlist, batching |
gateway.voice |
voice gateway: wake/STT/TTS engines + models, audio devices, VAD |
bridges.simplex |
forwarding bridge: host/port/token/ws_url |
bridges.llm |
LLM bridge: host/port/token (model comes from llm) |
bridges.nextcloud |
Nextcloud bridge: host/port/token + connection (url/username/app_password/defaults) |
bridges.outlook |
Outlook bridge: host/port/token + Microsoft Graph connection (client_id/tenant/defaults) |
simplex_chat |
gateway/forward ports and bot display names (binary refs come from pins.json) |
dashboard |
bind host/port |
Bridge skills read simplex_bridge_url / llm_bridge_url /
nextcloud_bridge_url / outlook_bridge_url (+ their _token) from
ctx.config; each is derived at startup from its bridges.<name>
host/port/token, so there is no duplicate top-level key to keep in sync. A bridge
with no block (or no port) leaves the variable unresolved and the operator is
asked for it.
llm.model and codegen.model are required (no default): set each to a
model its endpoint serves. A missing model fails fast at startup with a clear
config error rather than sending a request to a model that isn't there.
Runtime artifacts (data/decisions.jsonl, data/runs.jsonl,
data/categories.json, data/skills/, data/drafts/) are gitignored too.
Codegen timeout: do not cap codegen
max_tokens. A reasoning codegen model can write for 25–45 min;codegen.timeoutdefaults to 1200 s and a per-machine config may raise it to 3600 s.
Running the agent
All subcommands go through the CLI:
python -m semif_agent.cli run # interactive REPL
python -m semif_agent.cli run --script inputs.jsonl
python -m semif_agent.cli dream # cost report
python -m semif_agent.cli skills # print the skill tree
python -m semif_agent.cli status # current process + queue
python -m semif_agent.cli relabel <id> <outcome>
python -m semif_agent.cli dashboard [--port 8765] [--host 0.0.0.0] [--replay]
python -m semif_agent.cli gateway [--platform simplex,lxmf,voice|all] [--dashboard]
python -m semif_agent.cli bridge [--name simplex]
On a provisioned host, use the venv and set HF_HOME to the checkout's cache:
REPO=<your-checkout>
HF_HOME="$REPO/.runtime/hf" "$REPO/.runtime/venv/bin/python" -m semif_agent.cli run
REPL
Type a request, or one of the meta-commands:
busy <text> mark a current process (so the queue can be demonstrated)
idle clear the current process
status current process + queue
skills skill tree
dream cost report
relabel <id> <outcome>
restart <category> <skill>
repairs list pending repair offers
repair <offer-id> [retry|repair_skill|ask_user|no_repair]
quit
Authoring questions and repair offers are printed after each turn; answer them inline.
Scripted mode
--script file.jsonl submits each {"text": ..., "source": ...} row, then
drains the queue.
Dashboard
A stdlib HTTP server serving a Redux-DevTools-style inspector: static skill tree, run flow with decisions/events and dream costs, status, and write endpoints.
GET /api/trace /api/tree /api/dream /api/status /api/questions /api/repairs
POST /api/submit /api/answer /api/questions /api/restart /api/repair /api/relabel
Live mode warms the engine; --replay reads the logs without loading SemIf
(submit degrades to a JSON error). Binds 127.0.0.1:8765 by default.
Messenger gateway (SimpleX + LXMF)
cli gateway runs one or more command transports in a single process that
shares one scheduler/skill store. --platform takes a comma-separated list or
all and defaults to simplex:
python -m semif_agent.cli gateway [--platform simplex,lxmf,voice|all] [--dashboard]
Each platform feeds authorized DM text through the normal queue/dispatch
dispatch pipeline. Results, authoring questions and repair offers go back to the
originating chat. Config lives under gateway.<platform> in config.json;
enabled defaults to false. Both transports are default-deny — put allowed
identities in gateway.<platform>.allowed_users (or set allow_all_users for
dev) — and all adapters share one process (never run two gateway processes
over one skill store). On a provisioned host semif-gateway.service runs
gateway --platform all, so it survives logout/reboot.
SimpleX. Connects to the local simplex-chat daemon over its JSON WebSocket
API (gateway.simplex.ws_url, which must match simplex_chat.port). Requires
the optional websockets package (lazy import; the gateway refuses to start
without it). allowed_users entries match a numeric contactId or a display
name. The daemon must run in bot mode (simplex-chat -p PORT --create-bot-display-name NAME), not --headless/--relay — in v7 those mean
"chat relay" and yield a relay address, not a user contact address. Add the
bot's contact link to reach it: scripts/simplex-address.py shows/creates it
(bootstrap prints it), and the gateway prints it once on connect.
LXMF (Reticulum). Runs in-process — there is no external daemon;
pip install lxmf provides the transport (optional, lazy import; the gateway
refuses to start with an install hint otherwise). The bot's reachable address is
its LXMF delivery destination hash (32 hex chars), printed once on connect; the
identity is persisted under gateway.lxmf.storage_path (default
.runtime/lxmf/router) so the address is stable across restarts. allowed_users
matches the peer's LXMF address (32 hex) or a best-effort display name.
desired_method is direct (reliable link) or opportunistic (single packet),
and an optional propagation_node enables store-and-forward. Add the printed
address as a contact in your LXMF client and DM it.
Gateway isolation is non-negotiable. The gateway takes commands and sends replies — nothing else. It never reads history, shows or creates invite links, or composes messages. That is messaging UX and lives in the bridges.
Voice gateway
gateway --platform voice turns the machine's microphone into a command front
end: an always-on wake word (openWakeWord), speech-to-text
(faster-whisper), and text-to-speech (Piper), all local — no cloud. A spoken
command is fed through the same queue/dispatch pipeline as a typed or
messaged one, and every reply is spoken back. It is a normal gateway adapter, so
needs_input questions, repair offers, and approvals are spoken and answered by
voice too.
python -m semif_agent.cli gateway --platform voice
- Requirements. The voice stack is optional and lazy-imported; install it
with
scripts/bootstrap.sh --voice(or.runtime/venv/bin/pip install -r requirements/voice.txt) plus the system PortAudio lib and ALSA mixer tools (apt install libportaudio2 alsa-utils). The gateway refuses to start with an install hint if the stack is missing. PortAudio has no volume control — usealsamixer/amixer(thensudo alsactl store) to unmute and set the mic/speaker levels. - Models.
gateway.voice.wake.modelis an openWakeWord model (defaulthey_computer, spoken phrase "Hey Computer"),stt.modela faster-whisper size (defaultbase.en), andtts.voicea Piper voice (defaulten_US-lessac-medium). Bootstrap downloads the official openWakeWord models into the venv's package dir (under.runtime/venv) and the Piper voice into.runtime/voice/tts; the faster-whisper model lands in the.runtime/hfcache. openWakeWord ships no "computer" model, so the default is a pinned community model (openWakeWord-compatible, sha256-checked inpins.json) thatscripts/voice-models.pyfetches into.runtime/voice/wake, where the detector resolves it viawake.model_dir. Setwake.modelto an official name (e.g.alexa) or a path to switch. Because the community model's scores run lower than the official models, the seededwake.thresholdis0.2(the official models score ~0.99 and use0.5). - Behavior. Half-duplex — capture is discarded while a reply is speaking, so
the agent never transcribes itself (no barge-in yet). The wake word is required
before every command and is held while the scheduler is still running the
current request, so a second command cannot start until the first reaches a
result. A short beep plays when
the wake word fires (
gateway.voice.cue), so you know you're being heard; a short multi-note "bling" (cue.submit_notes, each entry[frequency_hz, duration_ms], spaced bycue.note_gap_ms) plays once the utterance is transcribed. (Setcue.submit_notesto[]andcue.submit_frequency > 0for the older single submit beep.) After the wake word, capture waitslisten_timeout_sfor the command to begin, so a pause before speaking (e.g. while the cue beep plays) does not truncate it.max_speak_charstruncates long replies before speaking.result_only(default true for voice) speaks only the skill's result line — scheduler bookkeeping is dropped and the<skill>: ok —wrapper is stripped — so the spoken output is the answer, not the scheduler's internals; set it false to speak the full scheduler output. There is no allowlist: the mic is local, so physical access is the authorization. - Run mode. Foreground, in the user's audio session — a headless systemd user service does not share the user's audio session, so voice is not rendered as a unit.
Bridge services
cli bridge runs standalone bridges: each is a process that stands up a small,
token-guarded localhost HTTP API in front of one third-party system (and, where
the system needs one, owns its own daemon/profile). Generated skill bodies call
them like any HTTP service (base URL from a config var), so they never speak a
native protocol directly.
The first bridge is SimpleX (semif_agent/bridges/simplex.py), with its own
simplex-chat daemon separate from the gateway's. Its HTTP surface:
GET /health
GET /contacts
GET /inbox # peek buffered inbound DMs
GET /inbox/next?contact=<id> # pop oldest unread
GET /unread # daemon's persistent unread chats (read-only; 503/502)
GET /history?contact=<id>&count=<n> # recent messages for one chat (read-only; 503/502)
GET /address # show/create the contact link (503 not connected, 502 failure)
POST /send {"recipient": "<id|display_name>", "text": "..."}
/unread and /history read the daemon's own state (/_get chats / /_get chat),
so they see messages that arrived while the bridge was down — unlike the live
/inbox receive buffer. Both are read-only: v7 has no mark-read command, so
acking is a client-side read receipt, not an API call.
Skills call the forwarding bridge at the address derived from bridges.simplex
(simplex_bridge_url); the bridge catalog
is injected into every codegen prompt via describe_bridges(), so it is the
single source of bridge specifics. Adding a bridge = a class + a config block +
a CATALOG entry.
The LLM bridge (semif_agent/bridges/llm.py) is the second: a generic
POST /chat {"messages": [{"role","content"}, ...], "max_tokens"?: int} -> {"text": "..."}
in front of the agent's language model, so a body can ask for short generated
text (e.g. extract an event title + description) over HTTP instead of speaking
the OpenAI-compatible protocol itself. It does not own the model connection:
cli bridge threads the scheduler's already-configured llm client into it, so
the endpoint/model/sampler live only in the top-level llm block; bridges.llm
carries just the local listener. Skills call it at the address derived from
bridges.llm (llm_bridge_url, + optional llm_bridge_token); with no client
it returns 502, never a fabricated reply. It starts in the same
semif-bridge.service process as the other enabled bridges.
The Nextcloud bridge (semif_agent/bridges/nextcloud.py) is the third: it
wraps the account's native protocols — WebDAV files, CalDAV calendar events and
tasks, CardDAV contacts, and the OCS Notes API — behind one JSON surface, so a
body never speaks DAV/OCS directly. It has no service daemon (Nextcloud is
plain HTTPS) and is stdlib-only (urllib + xml.etree), so it starts instantly
in the same semif-bridge process. The connection (base URL, username, app
password) is configured in bridges.nextcloud and falls back to the top-level
nextcloud_url / nextcloud_username / nextcloud_app_password /
nextcloud_default_calendar the nextcloud seeds use, so the account is
configured once. Skills call it at the address derived from bridges.nextcloud
(nextcloud_bridge_url, + optional nextcloud_bridge_token). Its HTTP surface:
GET /health
GET /user # account info (OCS)
GET /capabilities # server capabilities (OCS)
GET /files?path=<dir> # list a folder (WebDAV)
GET /files/stat?path=<path>
GET /files/read?path=<path> # text, or base64 for binary
GET /files/search?query=<text>&path=<dir>
POST /files/write {"path","content","encoding"?,"overwrite"?}
POST /files/mkdir | /files/delete | /files/move | /files/copy
GET /calendars
GET /calendars/events?calendar=<name>&start=<iso>&end=<iso> # CalDAV VEVENT
POST /calendars/events | /calendars/events/update | /calendars/events/delete
GET /tasks?calendar=<name> # CalDAV VTODO
POST /tasks | /tasks/update | /tasks/complete | /tasks/delete
GET /addressbooks
GET /contacts?addressbook=<name>&query=<text> # CardDAV
POST /contacts | /contacts/update | /contacts/delete
GET /notes | /notes/get?id=<id> # Notes app (OCS)
POST /notes | /notes/update | /notes/delete
A missing connection is 503; a real Nextcloud failure (transport, HTTP error,
or a bad reply) is 502 — never a fabricated success. Calendar and addressbook
defaults resolve from bridges.nextcloud when a request names none and the
account has several.
The Outlook bridge (semif_agent/bridges/outlook.py) wraps the user's
Microsoft account (Outlook / Microsoft 365) through Microsoft Graph: mail,
calendar events, Microsoft To Do tasks, contacts, and OneDrive files. Like
Nextcloud it has no service daemon (Graph is plain HTTPS) and is stdlib-only,
so it starts instantly in the same semif-bridge process. Authorization is the
OAuth2 device code flow: register an Entra ID public-client app, put its
client_id in bridges.outlook, and run scripts/outlook-auth.py once — the
tokens are stored (0600) under the checkout's .runtime/outlook/token.json and
refreshed automatically. The bridge starts without a token; an unauthenticated
route returns 503 telling the operator to run that helper. Skills call it at the
address derived from bridges.outlook (outlook_bridge_url, + optional
outlook_bridge_token). Its HTTP surface:
GET /health
GET /user # the signed-in account
GET /mail/folders
GET /mail/messages?folder=<name|id>&count=<n>&search=<text>&unread=<bool>
GET /mail/messages/get?id=<id>
POST /mail/send {"to":[...],"cc"?,"subject"?,"body"?,"content_type"?}
POST /mail/draft {"to"?,"cc"?,"subject"?,"body"?,"content_type"?}
GET /calendars
GET /calendars/events?calendar=<name|id>&start=<iso>&end=<iso> # recurrences expand
POST /calendars/events | /calendars/events/update | /calendars/events/delete
GET /tasklists # Microsoft To Do
GET /tasks?list=<name|id>
POST /tasks | /tasks/update | /tasks/complete | /tasks/delete
GET /contacts?query=<text>&count=<n>
GET /files?path=<dir> # OneDrive
GET /files/read?path=<path> # text, or base64 for binary
POST /files/write {"path","content","encoding"?,"overwrite"?}
A missing client_id or an unauthorized bridge is 503; a real Graph failure
(transport, HTTP error, or a bad reply) is 502 — never a fabricated success.
Seven seeds/outlook/* skills ship (next_message, send_message,
next_event, create_event, create_task, list_contacts, list_files);
send_message composes the message through the LLM bridge and asks for
confirmation before it sends.
Dream report
HF_HOME=... python -m semif_agent.cli dream
Prints row counts, weighted cross-entropy, accuracy, ECE and the highest-cost rows.
Skills in detail
A skill is one specific, single-purpose action reachable by category → skill navigation. It is three things:
- a registry entry (navigable description —
name+description, authored by the smallllmprovider and recorded indata/categories.json); - a code body (a single
act); - an
INTEGRATIONdeclaration (service / transport / config_vars) and a flatCONTRACT(the operational values the runner must provide).
CODEGEN.md is the authoritative body contract and is fed verbatim to the codegen
model. It requires: perform the real action; stdlib transports only
(urllib/http.client, imaplib/smtplib/poplib, subprocess, file I/O);
no mocking; data from ctx.config (never embedded or fabricated); request
clarification via needs_input when requirements are unclear; write files only
under configured data dirs; fail fast; and declare a consistent INTEGRATION.
TESTGEN.md is the separate contract for tests. A generated test is a
hermetic mechanics check — inline fixtures, a loopback http.server for HTTP
bodies, no external network, no mock_data.json. Passing it proves the code
runs, not that the live integration works. That is what the real run and the
repair loop are for.
Seeds (seeds/) ship real starter integrations in the exact generated
folder format, plus a manifest.json. merge_seed_store loads them into every
tree at startup; recorded config is written to the runtime store, so the
committed seed never holds secrets.
nextcloud.create_event— create an event on Nextcloud CalDAV (the authoritative worked example); resolves the target calendar with a SemIf choice over the owned calendars (strong winner, else the configured default); config varsnextcloud_url,nextcloud_username,nextcloud_app_password,nextcloud_default_calendar, plus the LLM bridge (llm_bridge_url,llm_bridge_token).nextcloud.next_event— next upcoming event from Nextcloud CalDAV (recurring events expanded server-side); config varsnextcloud_url,nextcloud_username,nextcloud_app_password,nextcloud_default_calendar.nextcloud.create_task— add a task to a Nextcloud task list through the Nextcloud bridge (GET /tasklists,POST /tasks); config varsnextcloud_bridge_url,nextcloud_bridge_token,llm_bridge_url,llm_bridge_token.simplex.next_message— read the next unread message via the forwarding bridge; config varssimplex_bridge_url,simplex_bridge_token,simplex_default_contact.simplex.send_message— send a message to a contact resolved over the bridge's contact list (a SemIf choice, defaulting to the configured contact); config varssimplex_bridge_url,simplex_bridge_token,simplex_default_contact, plus the LLM bridge (llm_bridge_url,llm_bridge_token) to write the text when the request states none.simplex.connect_link— show/create the forwarding bot's contact link.calculator.calculate— evaluate a bounded arithmetic request (two operands, one operator) and speak the answer in words; the operator is a SemIf choice over addition, subtraction, multiplication, division, exponents, squares, cubes, square roots, cube roots, fractions, and percentages, and SemIf picks the operands when the request writes more numbers than the operation needs (pure local compute, no config).
Testing
# anywhere, fast, stdlib only
python3 -m pytest tests/ -q --ignore=tests/integration
# where real SemIf + a real ollama are available (run from the checkout root)
./.runtime/venv/bin/python -m pytest tests/integration -q -s
Unit tests use the ScriptedEngine double (tests/conftest.py) to drive
scheduling mechanics without a GGUF; data-structure tests cover queue ordering,
dream cost and contract serialization. tests/test_voice_gateway.py drives the
voice loop with injected fake engines (no hardware, network, or heavy packages).
Integration tests exercise the real engine + LLM end to end.
Fixtures are not the runtime. Skill tests use real local endpoints (a loopback server, never a mock); a real run is the only proof an integration works.
Roadmap / status
Done. Core loop, FIFO queue, skill tree, real SemIf assessment, decision
logging, dream cost pass, REPL + JSONL CLI; live create_category /
create_skill with the async authoring pipeline (spec → body → fidelity →
contract → test → auto-run → re-dispatch); tiered config + first-fire
collection; runtime repair loop; the closed response canned tree; real
integrations with INTEGRATION declarations; the SimpleX command gateway and the
standalone SimpleX bridge + seeds (contact-list refresh, daemon-backed message
history / true unread); the LXMF gateway; and the voice gateway (wake word +
speech-to-text + text-to-speech).
Next. Real fine-tuning from grounded decision rows ("dreaming") with
validation + pinned-revision swap; queue persistence; more intake sources
(events/timers); dashboard run-requeue cross-linking; per-decision thresholds and
calibration; more bridges; a simplex.send_message seed. See AGENTS.md for the
detailed backlog and known gotchas.