A small agent engine for local models, written in Rust. One binary, one SQLite file, any OpenAI-compatible model server (Ollama, LM Studio, llama.cpp, OpenVINO).
The goal is simple: keep the engine efficient, so the model gets the machine's memory and time.
- Model time is scarce. A local model writes tens of tokens a second, shared by every bot.
- Memory is shared with the GPU on integrated-graphics and unified-memory machines.
- Local model servers differ in how they format tool calls, and each has bugs.
- Keys and private data live on the owner's machine, and any web page can try to steer a bot.
- Do one job. No chat channels or cloud providers; one connection to a local model server.
- Bots are data. A waiting bot is a small record and a timer, not a running process.
- Keep the prompt opening identical so the model server can reuse its cache.
- The engine owns tool calling. Probe the server, pick native tools, forced JSON or a text protocol, check every call, retry once with the error, then stop and say why.
- Set everything explicitly. Thinking and sampling settings are sent on every request. On
Ollama the engine uses its native chat API so it can also set
thinkand the context length: the model's own limit, capped at 32k tokens and by what the machine's memory can hold. Reasoning is never shown as a reply; a model that cannot stop thinking keeps it in its own field. - Lock down each command.
runuses a fresh confined process (Landlock on Linux, a deny-by-defaultsandbox-execprofile on macOS): writes only to the workspace and its temp folder, no network, CPU, memory and process limits, never as root. If it can't be confined, it doesn't run; Windows has no sandbox yet, sorunis refused there. - Nothing a command starts outlives it. A supervisor ends every process the command started
when it finishes or times out, including ones that called
setsidor forked twice: on Linux it is a subreaper outside the sandbox; on macOS it runs inside the command's sandbox, which lets it signal only that sandbox's processes. At most 4 commands run at once, and each may add at most 256 processes (threads on Linux) to what its user already runs. The system counts that limit per user, not per command, so one command that hits it can make another running command fail to start processes until it ends.
Nexy Engine is a single binary of a few megabytes with no UI, built to leave the machine's memory and time to the model.
cargo build --release
NEXY_ENGINE_MODEL_URL=http://127.0.0.1:11434 NEXY_ENGINE_MODEL=qwen3.6:35b-a3b ./target/release/nexy-engine serveCommands: serve, probe, ask TEXT, idle-memory N. Bots are defined in packs/. The API listens on
loopback and needs NEXY_ENGINE_KEY to listen anywhere else. Without a key it answers only requests
whose Host is 127.0.0.1, localhost or [::1] on its own port, or a name listed in
NEXY_ENGINE_HOSTS (comma separated); anything else gets 421, which stops DNS rebinding.
At start the engine tests the model with a few short requests (how to turn thinking off, whether
tools work natively) and keeps the answer in caps.json. For a model that counts every request,
NEXY_ENGINE_PROBE=off skips that test: the abilities come from NEXY_ENGINE_CAPS_FILE, or from
NEXY_ENGINE_THINK_OFF (template_kwargs, reasoning_effort, both, think_false,
no_thinking, stays_on; default template_kwargs) and NEXY_ENGINE_TOOLS (native, json,
text; default text), and only the user's turns reach the model.
POST /v1/chat/completions: OpenAI-shaped. The engine keeps each session's history; only the last user message is read."research": truemakes the engine search and read the top pages before the model answers. Links in a message are always read first. With"stream": truethe reply streams as server-sent events as the model writes it; tool calls and reasoning are held back, tool use shows as: tool <name>comments, and the last event carriesusageandnexy.POST /v1/responsesandGET /v1/uhp: the Unified Harness Protocol (core class, version 2026-10-19). Each bot is a harness./api/sessions,/api/jobs: history and scheduled tasks (routines). A schedule isevery 30m,daily 08:00or standard 5-field cron such as0 9 * * 1-5; day names are also taken (monday 09:00,weekly on mondays at 9am,mon, thu 09:00) and stored as cron. New routines run at most every 5 minutes. Clock times are read in the owner's time zone: send an IANA name such as"tz": "Asia/Manila"withPOST /api/jobs, with chat completions (top level) or with responses (metadata.tz); routines the model creates take the chat's zone. Without one it is UTC, and jobs made before zones stay UTC. Clock changes keep the wall-clock time:daily 08:00inEurope/Londonruns at 08:00 in both GMT and BST; a time skipped in spring runs just after the jump, and a time repeated in autumn runs once. Unknown zones get400.GET /api/jobslists each job'stz. A user keeps at most 50 routines and a bot holds at most 200, waiting ones included (409when full). Bots with theroutinetool can also create, list and delete routines in chat.- Routine approval: once outside content is in a chat's context (a web page, search result,
command output, file or saved memory, in this turn or earlier ones, or a system message the
caller has not vouched for), a routine the model creates is saved as
"status": "pending"with no next run, and the model cannot delete routines. Only the owner can then act, throughPOST /api/jobs/{id}/confirm(schedules it; an optional{"tz": …}body sets the zone it runs in) orPOST /api/jobs/{id}/discard(deletes it); neither is a tool.GET /api/jobslistsstatusandorigin. A caller whose system message holds only its own text sends"context_clean": true(chat completions) ormetadata.context_clean(responses). - Pause and resume:
POST /api/jobs/{id}/pausestops a routine running on its schedule or on events;POST /api/jobs/{id}/resumestarts it again, with a schedule's next run counted from now, so runs missed while paused never fire. A pending routine is neither (409: confirm it first). Like confirm, neither is a tool;GET /api/jobsshowsenabled. - Writes after outside content: once a web page, search result or passed-in content is in a
chat's context,
write_file,edit_file,rememberandrunare refused for the rest of that chat, and the reply tells the owner, who can ask again in a new chat. Reading the workspace or saved facts does not block writes, since only the owner or a clean turn put things there. - Event triggers: a routine can run when an event arrives instead of on a schedule. Send
"trigger": "mail from=alice@example.com"(or'file folder="Invoices 2026"') in place ofschedulewithPOST /api/jobs: a source name, then conditions that must all hold, ignoring case:key=valueis equal,from=@acme.comis any address whose domain is exactlyacme.com(notevil-acme.comoracme.com.evil.io), andsubject~invoiceis contains. Patterns are checked when the routine is made: no empty or wildcard-only values,~values up to 100 bytes, and no~on address fields. The caller that watches the source (the connector hub) posts each event toPOST /api/eventsas{"source": "mail", "id": "<the source's own id>", "fields": {"from": "alice@example.com"}, "text": "…"}, with fields normalised (a bare address, a folder's name) and text capped at 8,000 bytes. The answer lists the routinesstarted, those this event already ran (duplicate, so a repeat runs nothing), and those over a limit (limited, each withretry_afterseconds; the event is not recorded, so send it again then). Limits: one event run per routine every 5 minutes and 20 per user an hour. Only active routines match: a trigger routine the model creates is always saved aspending, even in a clean chat, until the owner confirms it. Every event run holds the event as outside content, so its writes are refused and it cannot create or delete routines. Event ids are kept 30 days. x-nexy-user: the user a request acts for, set by the trusted caller. Sessions, memory, jobs and workspaces are kept per user./healthanswers{"ok":true}; details need the key.
./tests/run.shMIT