Hosting and binding an engine
inf3r is not trying to integrate other people's inference engines into
crates/. It exists to host any engine behind one contract so that an
agent or author pointed at a (model, target) bundle can write a better,
specialized engine for that pair.
Binding a premade runtime is still worth having: it is the cheap bootstrap path
that gets a pair working right away and establishes a real inf3r bench
baseline for a custom engine in that same directory to beat.
This page covers both: writing or directly FFI-binding an engine inside a bundle, and wrapping an external CLI or HTTP runtime through the compatibility binder. Every path produces one bundle and passes the same gate. The core does not know which path was taken, which is the property the whole design exists to protect.
inf3r ships the host tooling, the contract, and test fixtures. A real model bundle is operator content; this page describes how an operator authors it.
What a bundle is
A bundle is one directory for one model on one target. It holds five parts:
| part | what it answers |
|---|---|
bundle.toml | what is this bundle, what engine does it bind, and what is the digest? |
BUNDLE.md | the card: id, model, target, engine kind, how to run it |
target.toml | what hardware was this built for? |
models/<serve>.toml | what does it serve, what weights, what can it do? |
model/ | the weights, mounted by the operator, never committed |
engine/ | the runtime, when the engine is bound |
A bundle also has src/ and Cargo.toml: the entry point. The entry point is a
package because cargo and the gate need one process to start. The engine behind
it can be any language. That is the whole trick: the protocol is the boundary,
not the language.
The package is its own cargo workspace (D19). Its Cargo.toml declares
[workspace], keeps its own lock, and reaches the engine crates by path. Build
it with cargo build --release inside the bundle, or build the engine and every
bundle into the root target with ./ops/build.sh release. The root
cargo build --workspace does not build a bundle.
A bundle becomes one plugin process. The pair is the unit (decision D12), and the directory is the unit of work (D14). A runtime that can serve many models is bound as several bundles, one per pair. A binding is not a library that the core links and not code that the core loads into itself. It is a program on the other end of a Unix socket, which is why a crash takes one model down instead of the host.
The artefacts
| artefact | where | what it answers |
|---|---|---|
| manifests | bundle.toml, target.toml, models/*.toml | what engine, what hardware, what weights, what the model can do |
| catalogue | printed by --describe, sent on the wire | what this process serves, with the lifecycle facts |
| lifecycle | the same catalogue | how a cancel, a stop, and a queue behave on this engine |
| gate | inf3r verify | whether the binding meets the contract |
The manifests are read by the operator and by inf3r new. The catalogue is the
only document that the core reads (spec section 15). When the two disagree, the
catalogue wins and the manifest was wrong. The weights are not an artefact of
the repository: model/ is mounted and excluded from the digest.
A model file with no alias_of holds the weights and the capabilities. A second
file with alias_of = "<served-name>" adds a name to the catalogue and inherits
those capabilities. The binder refuses two weight files, or an alias of an
alias. A capability section is in the catalogue only when the binder can map it:
all twelve names in the capability table are mapped by a binary bridge, and the
HTTP bridge maps the seven OpenAI-shaped ones plus the five neutral ones. A file
with no capability section keeps the historical implicit chat; a file that
names any capability carries only those names, so a decision-only model does not
claim chat.
The catalogue shape is the bridge's own coverage, not a wish list. A binary
chat bridge is a text prompt, so it advertises text and text output. An HTTP
chat bridge carries the OpenAI text, image, audio, and JSON content parts and
the reasoning progress channel. The OpenAI STT bridge emits text only, and
the HTTP image bridges take and return the parts those routes actually use;
the binary generic bridge keeps the richer shape because it can carry every
part. A model file's parts override is preserved.
target.toml carries two limits that the binder reads: max_inflight is the
welcome limit, and start_ms is the longest wait for an HTTP engine to answer
/health or for a JSON-lines worker to print {"ready":true}. Without
start_ms, the wait is the web's 120 s load deadline. The binder starts the
engine in its own process group, forwards its stderr, and ends the whole group
when the process stops. A resident worker declares one inflight, because one
process owns one model and one request line. A deploy file's max_inflight is
an upper bound, never a raise: the core clamps it to the welcome, so a deploy
value of eight still gives a worker one slot.
The catalogue carries facts, not claims
Each capability declares:
| field | values | meaning |
|---|---|---|
vocab | chat.v1, embed.v1, … | the request and reply shape |
parts | text, image, audio, json | what the capability accepts |
channels | text, progress, embedding, … | what it emits |
limits | named numbers | what the engine cannot exceed |
cancel | token, frame, request | where a cancel takes effect |
stops | plugin, native, none | who strips stop strings |
queue | none, internal | whether the engine queues inside itself |
A binding that cannot stop at a token says request. A binding that forwards to
another server says queue: internal and is labelled degraded. The label is
checked; see below.
The four engine paths
The primary paths implement inf3r_plugin_sdk::Plugin directly inside the
bundle's own src/ (or speak Wire 2 directly in any language), with no sidecar
server and no HTTP hop:
authored(engine = "authored",inf3r new <model> <target> <cap> --engine):src/is the inference engine. This is the destination for peak per-pair performance: custom kernels, exact memory layout, native KV/SSM state, truecancel: token, and real credit backpressure. The bundle may opt intounsafein its ownCargo.toml[lints]with a stated reason (D19).library(engine = "library",inf3r new <model> <target> <cap> --bind library):engine/holds a local shared library (libllama,libstable-diffusion,libaudio,libonnxruntime, etc.) andsrc/is a small, self-contained FFI shim implementinginf3r_plugin_sdk::Plugin(andCacheCodecdirectly over core-granted descriptors). No HTTP, no port, no second server process, and easy to copy per pair or replace piece by piece with custom kernels.inf3r new --bind librarywrites that shim, abuild.rs, and a placeholderengine/engine.cwith the four exports the shim expects. The placeholder echoes the prompt so the bundle builds and passes the gate before the real C API is wired; replaceengine.c, not the shim. The generated manifest allowsunsafe_codeonly in this bundle and says why: every raw-pointer call is insrc/ffi.rs(D19).- Raw protocol in any language, with no Rust at all (spec section 15.1,
method 3). The gate still judges it;
inf3r verify --programstarts it.
For external programs or third-party servers where linking a library is not
worth the effort, inf3r-bind provides a thin, engine-neutral compatibility
adapter. Its entry point is one line:
fn main() -> std::process::ExitCode { inf3r_bind::main() }
-
binary(engine = "binary",--bind binary):engine/entryis a program. The binder starts it, writes the request to stdin on a thread while it reads stdout, and ends the process group on cancel. Chat is a prompt of text lines. Another capability is one JSON request line:{"model", "capability", "params", "parts"}, where a part haskind,mime, an optionalrole, and eithertextor base64b64. Each reply line is text, or a JSON object withchannel,mime, and base64b64; addevent: trueto emit an event instead of an artifact.Add
worker = "jsonl"tobundle.tomlwhen the runtime should load once and stay resident. The binder starts it atload, waits for the first line{"ready":true}, and then writes one request object per line withid,model,capability,params, andparts. The worker answers with lines that carry the sameid: achannelplusb64(and optionalevent), a terminal{"done":true,"usage":{...},"meta":{...}}, or{"error":{"code":"dependency","message":"..."}}. The binder fixes one deadline when the job starts; it polls cancellation and that deadline while it waits, so a chatty line cannot extend the job and a cancel does not wait for a silent engine. The request is written on its own thread so a full pipe cannot block the job; a request or reply line is refused above 32 MiB. A missing or mismatchedid, a malformed line, a duplicate terminal, or a process exit stops the worker; the next job starts a new one.max_inflightis one because one process owns one model and one request line at a time. The weight and asset contract is unchanged:{model},{weights}, and{weightN}name the granted descriptors, and a descriptor-only grant is inherited as/proc/self/fd/<n>. -
http(engine = "http",--bind http):engine/entryis a URL or a local program the binder starts. The binder waits for/healthto answer below 500, maps the OpenAI-shaped subset (chat,embed,rerank,stt,tts,image-gen,image-edit) to routes below/v1, closes the connection to cancel, and declarescancel: requestandstops: native.music,t2v-gen,i2v-gen,decide, andextractuse the neutralPOST /<capability>bridge: the same request object as a binary engine crosses as JSON, and the reply is one object, an array, line-delimited JSON, or SSE with the samechannel,done, anderrorwords. NDJSON and SSE are consumed line by line with a short socket poll: each event is emitted as it arrives, and cancellation and the job deadline are checked between reads. A request or reply body is capped at 32 MiB and refused withsizebeyond it. Anhttpsentry is refused; a bound runtime is local.
inf3r-bind is strictly a fallback adapter, never the primary architecture for
first-class engines, and crates/ never hardcodes vendor CLI flags or vendor
HTTP routes. It carries every capability in the table without adding a vendor
name: the seven OpenAI-shaped HTTP bridges are a compatibility convenience, not
the definition of what a bound engine can do. A runtime that cannot cancel
inside a token and cannot honour the credit watermark makes inf3r verify skip
those two checks by name. Do not mistake a passing compatibility adapter for a
directly bound or authored engine.
Container mode
A bundle is the same citizen in a sibling engine container as in host mode. The
binder runs inside the engine image; the control never receives the plugin
binary or the engine library. The deploy file names runtime = "container" and
a pinned image, and the control starts one container per instance with no
network, a read-only root, and only its private socket directory. The engine
still speaks Wire 2 over that socket.
The weight contract does not change: the control grants read-only descriptors
and the binder passes {model}, {weights}, and {weightN} to the engine.
Because a container grant has no host path, the engine sees
/proc/self/fd/<n>. A read-only asset mount is for multi-file configuration that
is not a weight. Its source must resolve below an asset_dirs entry, contain no
symlink or .., and stay clear of the token, /etc, /var/run, /run, the
control home, and the Docker socket; it may not overlap the blob store, a cache
tier, or either socket root.
The cache stays in the control. An engine container receives no cache directory
and no cache quota; its cache objects travel over the private socket as
descriptors. A resident worker = "jsonl" engine is unaffected: it loads once
inside its container, and the binder in that container keeps the process line
open.
A container bind may lower its host resources with pids_limit, memory,
shm, log_max_size, and log_max_files. The engine always gets a process
limit, a host memory limit, a usable /dev/shm, and json-file log rotation;
the GPU ledger still governs device memory.
inf3r verify --container <bundle-id> --deploy <file> runs the same gate over
the container's private socket. The gate asks the control's Docker daemon to
start the image as a sibling; it never starts the engine on the host. It checks
the deploy conflicts and image pin first. On a host, socket_host_dir is the
gate's own root; inside a control, pass --socket-dir and the host mount path
is taken from socket_host_dir; the gate uses a private child of that root.
The gate
inf3r verify <plugin-id> # the binary under bin_dir
inf3r verify --program <path> [args] # a binary that is not installed yet
inf3r verify --program <path> --weights <file> # grant one weight file
inf3r verify --program <path> --budget 10m --load-budget 2m --job-budget 1m
The whole run defaults to five minutes. A load, including the handshake and
--describe, gets two minutes; one job gets one minute. The two smaller
deadlines are capped by the whole one, so --budget alone is always an upper
bound. --suite reads a different step list, which a bundle golden uses.
A binding that needs weights is granted one only when --weights names it. The
file crosses the socket as a descriptor, exactly as the core grants it, so the
gate tests the path that the engine will use. Every grant reaches the engine:
{model} is the first, {weights} is all of them in order, and {weightN} is
one. A grant with no path is inherited across the process start (and every
worker restart) and appears as
/proc/self/fd/<n>, so a descriptor-only sandbox works.
The gate starts the binding and checks, in order:
handshake— the connection, the welcome, the catalogue.catalogue— the target is named, every capability has a vocabulary and a part, and every lifecycle word is known.describe—--describeprints exactly the catalogue that the wire carried.- one
jobper step of the suite — a job completes, or the step is skipped with the reason that the binding does not declare it. extension— an extension frame crosses a live job and the job completes (R30).cancel— a job with no initial credit ends cancelled, or the binding refuses the job as cancelled before it starts.credit— a one-byte window is not overrun; one absolute window then lets the job finish. Refusing the job is a pass.descriptor— a real input part travels as a descriptor, not as a copy.artifact— a terminal artifact that carries a descriptor has the declared length. An inline artifact is a skip, not a pass.crash— the child is killed and the caller is not left waiting.restart— the same binding accepts a second handshake.
A fail is a defect in the binding. A skip is a truthful statement that the
capability is not declared or that the binding honestly refused a check it
cannot keep. The job steps come from data, so a new binding is judged by editing
goldens/conformance.json, not the runner.
The report is one line per check and an exit code: 0 when nothing failed.
The numbers
The ledger reserves weights_bytes + context × kv_bytes_per_token per load, on
every device the bind names. The catalogue declares weights_bytes; a binding
that declares zero has no weights, and the ledger reserves nothing for it. After
a load the core measures the process tree: device memory on a GPU target, and
resident bytes on a CPU target, because a bound bundle keeps its weights in the
engine child. It refuses a process that holds less than half of what it
declared.
Load time is measured, not guessed. The catalogue carries load_ms from the last
load. A job reports tokens_out, first_token_ms, and tokens_per_s in its
usage map. tokens_per_s is in hundredths of a token per second, so 1234 is
12.34. inf3r bench and inf3r stats print two decimal places.
The rules
- No weights in an image, and no download by any process. Weights are a mount.
- One bundle is one pair, and one process. Unload is process death (decision D13); there is no unload frame.
- No second wire. A binding uses the frames in
protocol.md; a private format is not a binding. - The deploy file is the only authority on devices and listeners. A binding
that tries to name its own device port fails startup.
inf3r-webgives the childINF3R_BUNDLE_DIR, so an installed binary finds its bundle. - A published capability name and a published vocabulary are permanent (decision D10).
- The bundle is the unit of replacement. A new engine in the same directory keeps the id, the bind, and the client. The gate and the bench decide.
Worked example
inf3r new example toy chat --engine
cd plugins/example/toy
cargo build --release
inf3r bundle verify .
inf3r verify --program ./target/release/inf3r-example-toy
bundle verify checks the five parts and the digest. verify is the same gate
that the conformance plugin meets in CI. Until both pass, the binding is a
draft.
A bound bundle is the same two commands:
inf3r new echo cpu chat --bind binary
# put the runtime in engine/ and edit entry in bundle.toml
./ops/build.sh debug
inf3r bundle verify plugins/echo/x64-cpu
inf3r verify --program ./target/debug/inf3r-echo-x64-cpu
plugins/echo/x64-cpu is the worked example in this tree. Its runtime is Python.
KV cache for a bound engine
A bound HTTP engine can persist its slot state without owning a cache. The
binder declares catalogue.cache and a codec fingerprint. The core owns the
store, the TTL, the tiers, and the eviction.
The binder understands one engine API: the optional cache bridge. It never mutates an engine's command line, never calls a vendor slot route, and never falls back to one. A runtime that does not advertise the bridge runs uncached; the job is still correct, it only pays a cold prefill.
A bundle that declares a context and a KV cost gives the binder a private 0700
exchange directory, named in INF3R_CACHE_DIR. When the runtime advertises the
bridge, a turn does:
- derive a longest-first prefix chain from the canonical prompt;
- ask the core for a read descriptor, verify its length and CRC32C, and restore slot 0 through the bridge;
- on a miss or a failed check, erase slot 0 through the bridge before prefill;
- after
done, reserve a writable descriptor, save slot 0 through the bridge, and commit the actual bytes and CRC32C.
The canonical prompt order is leading system parts, then every tools JSON
part, then the rest. Tools are a separate field in the chat body, so moving them
before the conversation matches the engine's rendering. response_format is not
moved: the binder sends it as a message at its original position.
Two keys come out of the chain. The tip key is scoped by the client
cache_key; the anchor key is prompt-only and is the last key of the stable
[system + tools] prefix. A conversation's lineage is H(cache_key) when the
client sends one, otherwise H(first conversation part). The binder keeps one
non-anchor tip per lineage (64, FIFO) and supersedes only that lineage's previous
tip. The shared anchor is never superseded.
Bytes cross the process boundary through the exchange directory, never as a
path from the core: the binder copies a restored entry into it and copies a
saved slot back into the granted descriptor. The cache conformance runner reads
the INF3R_CACHE_TRACE file to observe the unconditional erase.
The slot table is one slot. A hybrid or SSM model declares
checkpoint_exact and never rolls back. A cancel or a failed turn marks the
slot tainted; the next reuse erases it. The cache is a latency feature: a miss
or a corrupt restore is a cold prefill, not a failed job.
Engine cache bridge
An engine may advertise an optional HTTP bridge on the same base URL:
GET {base}/inf3r/cache
200 {"version":1,"prefix_checkpoint":true}
A 404, 405, 501, or malformed 200 runs uncached. A network error is
retried on the next turn and never selects a vendor route by accident.
The bridge implements one-slot save, restore, and erase under
/inf3r/cache/save|restore|erase, plus the optional prefix operation. Its
bodies are JSON. filename is a basename under INF3R_CACHE_DIR; the engine
may not follow a symlink or leave a partially written file.
POST /inf3r/cache/prefix carries slot, the same chat params, and two
prompts: prefix (the leading system messages and tools) and full (every
message). The engine renders both without the assistant-generation suffix,
requires the prefix tokens to be a prefix of the full tokens, erases the slot,
prefills only the prefix, and replies with {"tokens":N,"prefill_ms":M}. It does
not save a file and does not generate. 409 means "not a token prefix" and has
no side effects.
The binder then reserves an Anchor, calls /inf3r/cache/save for the current
slot, copies the bytes through the granted descriptor, and commits. A clean
reservation refusal leaves the prefilled prefix in the slot; any other failure
erases it before prefill. The anchor is shared across conversations with the
same [system + tools], so a second conversation hits it on its first turn.
The bridge never changes Wire 2 and never receives a path from the core. If the engine does not implement it, the binder runs uncached.